#include<iostream>
#include<cstdio>
using namespace std;
bool vis[10000]={false};
bool k[10000]={false};
bool cir[10000]={false};
bool ok=false;
long long no[10000];
int n;
int minx;
int nw;
int a,b,c,d;
int s[20000],tp=1;
long long sum=0;
int head[10000]={0},tar[10000]={0},cnt=1;
struct edge
{
int to,nex,w,p;
}e[20000];
void add(int from,int t,int weig,int beau)
{
e[cnt].to=t;
e[cnt].w=weig;
e[cnt].p=beau;
e[cnt].nex=head[from];
head[from]=cnt;
tar[from]=cnt;
cnt++;
return;
}
bool dfs()
{
int i,j;
while(tp>0)
{
i=tar[s[tp]];
j=e[i].to;
if(i==0)
{
--tp;
continue;
}
if(tp>1&&j==s[tp-1])
{
tar[s[tp]]=e[i].nex;
continue;
}
if(vis[j]==true)
{
cir[j]=true;
do
{
cir[s[tp]]=true;
--tp;
}while(s[tp]!=j);
break;
break;
}
else
{
tar[s[tp]]=e[i].nex;
vis[j]=true;
++tp;
s[tp]=j;
}
}
}
void ans(int rt)
{
for(int i=head[rt];i!=0;i=e[i].nex)
{
if(k[e[i].to]==false&&cir[e[i].to]==false)
{
k[e[i].to]==true;
no[e[i].to]=no[rt];
ans(e[i].to);
}
}
return;
}
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d%d%d%d",&a,&b,&c,&d);
sum+=c;
add(a,b,c,d);
add(b,a,c,d);
}
s[1]=1;
vis[1]=true;
int i,j;
while(tp>0)
{
i=tar[s[tp]];
j=e[i].to;
if(i==0)
{
--tp;
continue;
}
if(tp>1&&j==s[tp-1])
{
tar[s[tp]]=e[i].nex;
continue;
}
if(vis[j]==true)
{
cir[j]=true;
do
{
cir[s[tp]]=true;
--tp;
}while(s[tp]!=j);
break;
break;
}
else
{
tar[s[tp]]=e[i].nex;
vis[j]=true;
++tp;
s[tp]=j;
}
}
for(int i=1;i<=n;i++)
{
if(cir[i]==true)
{
minx=1e9+7;
for(int j=head[i];j!=0;j=e[j].nex)
{
if(cir[e[j].to]==true&&e[j].p<minx)
{
minx=e[j].p;
no[i]=e[j].w;
}
}
k[i]=true;
ans(i);
}
}
for(int i=1;i<=n;i++) printf("%lld\n",sum-no[i]);
return 0;
}