#include<cstdio>
#include<cctype>
#include<queue>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define ren for(int i=first[x];i;i=next[i])
using namespace std;
typedef long long ll;
const int BufferSize=1<<16;
char buffer[BufferSize],*head,*tail;
inline char Getchar() {
if(head==tail) {
int l=fread(buffer,1,BufferSize,stdin);
tail=(head=buffer)+l;
}
return *head++;
}
inline ll read() {
ll x=0,f=1;char c=Getchar();
for(;!isdigit(c);c=Getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=Getchar()) x=x*10+c-'0';
return x*f;
}
const int maxn=200010;
const ll inf=1ll<<60;
int n,e,fa[maxn],first[maxn],next[maxn<<1],to[maxn<<1];
ll p[maxn],q[maxn],l[maxn],dep[maxn],f[maxn];
void AddEdge(int u,int v) {
to[++e]=v;next[e]=first[u];first[u]=e;
to[++e]=u;next[e]=first[v];first[v]=e;
}
int vis[maxn],g[maxn],s[maxn],size,root;
void getroot(int x,int f2) {
s[x]=1;int maxs=0;
ren if(!vis[to[i]]&&to[i]!=f2) {
getroot(to[i],x);
s[x]+=s[to[i]];
maxs=max(maxs,s[to[i]]);
}
g[x]=max(size-s[x],maxs);
if(g[root]>g[x]) root=x;
}
int cnt,A[maxn],Q[maxn];
void dfs(int x,int f2) {
A[++cnt]=x;
ren if(!vis[to[i]]&&to[i]!=f2) dfs(to[i],x);
}
void relax(int x,int y) {f[x]=min(f[x],f[y]+(dep[x]-dep[y])*p[x]+q[x]);}
double slop(int x,int y) {return !x?1e30:(double)(f[x]-f[y])/(dep[x]-dep[y]);}
int cmp(int x,int y) {return dep[x]-l[x]>dep[y]-l[y];}
void solve(int x) {
root=0;getroot(x,0);
int now=root,rt=root;vis[now]=1;
if(!vis[x]) size=s[x]-s[now],solve(x);cnt=0;
for(int i=first[now];i;i=next[i]) if(!vis[to[i]]) dfs(to[i],now);
sort(A+1,A+cnt+1,cmp);
for(int i=now;i!=fa[x]&&dep[i]>=dep[now]-l[now];i=fa[i]) relax(now,i);
for(int i=1,r=0;i<=cnt;i++) {
for(;now!=fa[x]&&dep[now]>=dep[A[i]]-l[A[i]];now=fa[now]) {
while(r>1&&slop(now,Q[r])>=slop(Q[r],Q[r-1])) r--;Q[++r]=now;
}
if(r) {
int L=1,R=r;
while(L<R) {
int mid=L+R+1>>1;
if(slop(Q[mid-1],Q[mid])>=(double)p[A[i]]) L=mid;
else R=mid-1;
}
relax(A[i],Q[L]);
}
}
for(int i=first[rt];i;i=next[i]) if(!vis[to[i]]) size=s[to[i]],solve(to[i]);
}
int main() {
n=size=g[0]=read();read();
rep(i,2,n) f[i]=inf,fa[i]=read(),dep[i]=dep[fa[i]]+read(),AddEdge(fa[i],i),p[i]=read(),q[i]=read(),l[i]=read();
solve(1);
rep(i,2,n) printf("%lld\n",f[i]);
return 0;
}