// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>
// #include "atcoder/all"

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


void solve(long long n, std::vector<long long> a, std::vector<long long> b, long long q, std::vector<long long> t, std::vector<long long> e, std::vector<long long> x){
    vector<vector<int>> edges(n);
    for(int i = 0; i < n - 1; ++i){
        --a[i], --b[i];
        edges[a[i]].emplace_back(b[i]);
        edges[b[i]].emplace_back(a[i]);
    }

    int cnt = 0;
    vector<int> in(n, -1), out(n);
    vector<int> dep(n, 0);
    function<void(int)> f = [&](int x){
        in[x] = cnt++;
        for(auto y : edges[x]){
            if(in[y] != -1)
                continue;
            dep[y] = dep[x] + 1;
            f(y);
        }
        out[x] = cnt;
    };
    f(0);

    vector<i64> imo(n + 1, 0);
    for(int i = 0; i < q; ++i){
        int fr = (t[i] == 1 ? a[e[i] - 1] : b[e[i] - 1]);
        int ba = (t[i] == 2 ? a[e[i] - 1] : b[e[i] - 1]);
        if(dep[fr] > dep[ba]){
            imo[in[fr]] += x[i];
            imo[out[fr]] -= x[i];
        }
        else{
            imo[0] += x[i];
            imo[in[ba]] -= x[i];
            imo[out[ba]] += x[i];
        }
    }
    for(int i = 0; i < n; ++i){
        imo[i + 1] += imo[i];
    }
    for(int i = 0; i < n; ++i){
        cout << imo[in[i]] << endl;
    }

}


signed main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N-1);
    std::vector<long long> b(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
    }
    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> t(Q);
    std::vector<long long> e(Q);
    std::vector<long long> x(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&t[i]);
        scanf("%lld",&e[i]);
        scanf("%lld",&x[i]);
    }
    solve(N, std::move(a), std::move(b), Q, std::move(t), std::move(e), std::move(x));
    return 0;
}

#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int M = 1e9 + 7;
struct mint {
    int value;
    mint() : value(0) {}
    template <class T>
    mint(T x) : value(x % M) {
        if (value < 0) value += M;
    }
    mint &operator-=(mint oth) {
        value -= oth.value;
        if (value < 0) value += M;
        return *this;
    }
    mint &operator+=(mint oth) {
        value += oth.value;
        if (value >= M) value -= M;
        return *this;
    }
    mint &operator*=(mint oth) {
        value = (long long)value * oth.value % M;
        return *this;
    }
    mint &operator--() {
        if (--value == -1) value = M - 1;
        return *this;
    }
    mint &operator++() {
        if (++value == M) value = 0;
        return *this;
    }
    mint operator--(int) {
        mint temp = *this;
        --*this;
        return temp;
    }
    mint operator++(int) {
        mint temp = *this;
        ++*this;
        return temp;
    }
    mint operator-() const { return mint() - *this; }
    mint operator+() const { return *this; }
    mint pow(long long e = M - 2) const {
        mint res = 1, b = *this;
        while (e > 0) {
            if (e % 2 == 1) {
                res *= b;
            }
            b *= b;
            e /= 2;
        }
        return res;
    }
    friend mint operator-(mint a, mint b) { return a -= b; }
    friend mint operator+(mint a, mint b) { return a += b; }
    friend mint operator*(mint a, mint b) { return a *= b; }
    friend bool operator==(mint a, mint b) { return a.value == b.value; }
    friend bool operator!=(mint a, mint b) { return a.value != b.value; }
    friend ostream &operator<<(ostream &out, mint a) {
        out << a.value;
        return out;
    }
};
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    vector<vector<pair<int, ll>>> g(n);
    for (int i = 1; i < n; i++) {
        int u, v;
        ll w;
        cin >> u >> v >> w;
        --u;
        --v;
        g[u].push_back({v, w});
        g[v].push_back({u, w});
    }
    vector<ll> dis(n, -1);
    dis[0] = 0;
    queue<int> q;
    q.push(0);
    while (!q.empty()) {
        int f = q.front();
        q.pop();
        for (auto to: g[f]) {
            if (dis[to.first] == -1) {
                dis[to.first] = dis[f] ^ to.second;
                q.push(to.first);
            }
        } 
    }
    vector<int> cnt(61, 0);
    for (int i = 0; i < 60; i++) {
        ll t = 1ll << i;
        for (int j = 1; j < n; j++) {
            if (dis[j] & t) {
                cnt[i]++;
            }
        }
    }
    mint ans(0), pow(1);
    for (int j = 1; j < n; j++) {
        ans += mint(dis[j]);
    }
    for (int i = 0; i < 60; i++) {
        ans += mint(cnt[i]) * mint(n - 1 - cnt[i]) * pow;
        pow *= 2;
    }
    cout << ans << endl;

    return 0;
}