#include <iostream>
#include <vector>
#include <cstring>

#define int long long
using namespace std;
const int maxn = 2e5 + 1;
const int mod = 1e9 + 7;
int N;
struct edge{
    int to, w;
};
vector<edge > G[maxn];
int dis[maxn];

void dfs(int u, int f) {
    for(auto& e :G[u]) {
        if(e.to == f) continue;
        dis[e.to] = dis[u] ^ e.w;
        dfs(e.to, u);
    }
}

void init() {
    cin >> N;
    for(int i = 1; i < N; ++i) {
        int u, v, w;
        cin >> u >> v >> w;
        G[u].push_back(edge{v, w});
        G[v].push_back(edge{u, w});
    }
}

signed main() {
    init();
    dfs(1, 0);
    int ans = 0;
    for(int c = 0; c < 60; ++c) {
        int cnt[2] = {0, 0}; 
        for(int i = 1; i <= N; ++i) {
            cnt[(dis[i] >> c) & 1] ++;
        }
        ans += ((1ll << c) % mod) * (cnt[0] * cnt[1] % mod);
        ans %= mod;
    }
    cout << ans;
    return 0;
}
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
ll n,q;
vector<int> g[200010];
int a[200010],b[200010];
vector <int> depth;
void dfs(int a,int d){
    depth[a]=d;
    for(int i :g[a]){
        if(depth[i]==-1)dfs(i,d+1);
    }
}

ll ans[200010];
int main(){
    cin >> n;
    depth.resize(n,-1);
    rep(i,n-1){
        cin >> a[i] >> b[i];
        a[i]--;b[i]--;
        g[a[i]].emplace_back(b[i]);
        g[b[i]].emplace_back(a[i]);
    }
    dfs(0,0);
    cin >> q;
    rep(i,q){
        ll t,e,x;
        cin >> t >> e >> x;
        e--;
        int k=a[e],l=b[e];
        if(t==2)swap(k,l);
        if(depth[k]>depth[l]){
            ans[k]+=x;
        }
        else{
            ans[0]+=x;
            ans[l]-=x;
        }
    }
    vector <ll> q;
    q.push_back(0);
    while(!q.empty()){
        ll cnt=q.back();
        q.pop_back();
        for(int i:g[cnt]){
            if(depth[i]>depth[cnt]){
                ans[i]+=ans[cnt];
                q.push_back(i);
            }
        }
    }
    rep(i,n)cout << ans[i] << endl;
    return 0;
}
