#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<map>
#include<vector>
#include<set>
#include<queue>
#include<time.h>
#include<math.h>
using namespace std;
#define ok cout<<"OK"<<endl;
#define dbg(x) cout<<#x<<" = "<<x<<endl;
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl;
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl;
#define print(a,n) for(int i=1;i<=n;i++) cout<<a[i]<<" ";cout<<endl;
#define pb push_back
#define Fi first
#define Se second
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
const double eps = 1e-8;
const double PI = acos(-1.0);
const int Mod = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 1e5+10;
vector<pii> G[maxn];
ll dp[maxn][32];
ll sum[maxn];
ll ans[maxn];
void dfs(int rt,int fa)
{
sum[rt]=1;
for(int i=0;i<G[rt].size();i++)
{
int to=G[rt][i].Fi;
int val=G[rt][i].Se;
if(to==fa) continue;
dfs(to,rt);
sum[rt]+=sum[to];
for(int j=0;j<30;j++)
{
if(val&(1<<j))
{
dp[rt][j]=dp[rt][j]+sum[to]-dp[to][j];
}
else
{
dp[rt][j]=dp[rt][j]+dp[to][j];
}
}
}
}
int main()
{
//freopen(".in","r",stdin);
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=1;i<=n;i++) for(int j=0;j<30;j++) dp[i][j]=0;
for(int i=1;i<=n;i++) ans[i]=0;
for(int i=1;i<=n;i++) G[i].clear();
for(int i=1;i<=n-1;i++)
{
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
G[u].push_back(pii(v,w));
G[v].push_back(pii(u,w));
}
for(int i=1;i<=n;i++) sum[i]=0;
dfs(1,-1);
for(int i=1;i<=n;i++)
{
ans[i]=0;
for(int j=0;j<30;j++)
{
ans[i]=(ans[i]+1LL*dp[i][j]*(sum[i]-dp[i][j])%Mod*(1LL<<j)%Mod)%Mod;
}
printf("%lld ",ans[i]);
}
puts("");
}
return 0;
}