//order_of_key(k): Number of items strictly smaller than k .
//find_by_order(k): K-th element in a set (counting from zero).
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define full(x,n) x,x+n+1
#define full(x) x.begin(),x.end()
#define finish return 0

#define putb push_back
#define f first
#define s second

//logx(a^n)=loga(a^n)/logx(a)
//logx(a*b)=logx(a)+logx(b)
//logx(y)=log(y)/log(x)
//logb(n)=loga(n)/loga(b)

#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define putf push_front
#define gainb pop_back

//(a+b)^n=sum of C(n,i)*a^i*b^(n-i) 0<=i<=n
//(a-b)^n=sum of C(n,i)*a^i*b^(n-i) for even i-for odd i

#define gainf pop_front
#define len(x) (int)x.size()

// 1/b%mod=b^(m-2)%mod
// (a>>x)&1==0
// a^b=(a+b)-2(a&b)

typedef double db;
typedef long long ll;

//sum of squares n*(n+1)*(2n+1)/6
//sum of cubes [n*(n+1)/2]^2
//sum of squares for odds n*(4*n*n-1)/3
//sum of cubes for odds n*n*(2*n*n-1)

const int ary=2e5+5;
const int mod=1e9+7;
const ll inf=1e18;

using namespace std;
using namespace __gnu_pbds;
int n,q,a[ary],b[ary],to[ary],ti[ary],tu,d[ary];
vector<int> g[ary]; 
ll w[ary],p[ary];
void dfs(int v=1,int p=0){
	d[v]=d[p]+1;
	tu++;
	ti[v]=tu;
	for(int i=0;i<len(g[v]);i++){
		int to=g[v][i];
		if(to==p){
			continue;
		}
		dfs(to,v);
	}
	to[v]=tu;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<n;i++){
		cin>>a[i]>>b[i];
		g[a[i]].putb(b[i]);
		g[b[i]].putb(a[i]);
	}
	dfs();
	cin>>q;
	while(q--){
		int t,e,x;
		cin>>t>>e>>x;
		if(t==1){
			if(d[a[e]]<d[b[e]]){
				p[1]+=x;
				p[ti[b[e]]]-=x;
				p[to[b[e]]+1]+=x;
			}
			else{
				p[ti[a[e]]]+=x;
				p[to[a[e]]+1]-=x;
			}
		}
		else{
			if(d[b[e]]<d[a[e]]){
				p[1]+=x;
				p[ti[a[e]]]-=x;
				p[to[a[e]]+1]+=x;
			}
			else{
				p[ti[b[e]]]+=x;
				p[to[b[e]]+1]-=x;
			}
		}
	}
	for(int i=1;i<=n;i++){
		p[i]+=p[i-1];
	}
	for(int i=1;i<=n;i++){
		w[i]=p[ti[i]];
		cout<<w[i]<<"\n";
	}
}
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define reps(i,s,n) for(int i=s; i<n; i++)
#define per(i,n) for(int i=n-1; i>=0; i--)
#define pers(i,n,s) for(int i=n-1; i>=s; i--)
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define lb(v,n) lower_bound(all(v),n)
#define lbi(v,n) lower_bound(all(v),n) - v.begin()
#define ub(v,n) upper_bound(all(v),n)
#define ubi(v,n) upper_bound(all(v),n) - v.begin()
 
#define mod 1000000007
#define infi 1010000000
#define infl 1100000000000000000
 
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define IN(n,m,v) rep(i,n) rep(j,m){cin >> v[i][j];}
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define cYES cout << "YES" << endl
#define cNO cout << "NO" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
 
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vs = vector<string>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}

int N;
ve<ve<pair<int,ll>>> G;
vl A;

void dfs(int u, int v){
    
    for (auto p : G[u]) {
        if(p.fi == v) continue;
        A[p.fi] = A[u] ^ p.se;
        dfs(p.fi,u);
    }
    
    
}


template <typename T> T extgcd(T a, T b, T& x, T& y){
    T d = a;
    if(b != 0){
        d = extgcd(b,a%b,y,x);
        y-=(a/b)*x;
    }
    else x=1,y=0;
    return d;
}

template <typename T> T mod_pow(T m, T n) {
    if(n == 0) return 1;
    T res = mod_pow(m*m%mod, n/2);
    if(n & 1) res *= m;
    return res%mod;
}

template <typename T> T mod_inv(T n) {
    T m = mod;
    T x,y;
    extgcd(n,m,x,y);
    return (m+x%m)%m;
}



void solve(){
    
    
    
    cin >> N;
    G.resize(N);
    A.assign(N,0);
    
    rep(i,N-1){
        int u,v;
        ll w;
        cin >> u >> v >> w;
        u--,v--;
        G[u].pb({v,w});
        G[v].pb({u,w});
    }
    
    dfs(0,-1);
    
    //outve(A);
    
    vl B(61,0);
    vl C(61,0);
    rep(i,N) {
        rep(j,61) {
            if(A[i] & 1LL << (ll)j) B[j]++;
            else C[j]++;
        }
    }
    
    //outve(B);
    
    ll ans = 0;
    rep(i,N) {
        rep(j,61){
            if(!(A[i] & 1LL << j)) ans += (B[j])*(ll(1LL<<(ll)j)%mod)%mod;
            else ans += (C[j])*((ll)(1LL<<(ll)j)%mod)%mod;
            ans %= mod;
        }
    }
    
    cout << (ans*(mod_inv(2LL)%mod))%mod << endl;
    
    
}



int main(){
    
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    solve();

    return 0;
}
