#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <cmath>
#include <cassert>
#include <stack>
#include <numeric>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, ss) for (int i = (ss);i < (int)( n ); i++)
#define all(l) l.begin(), l.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &l, const T b) {
    if (l < b) {
        l = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T &l, const T b) {
    if (l > b) {
        l = b;
        return true;
    }
    return false;
}

# ifdef LOCAL_DEBUG
template<typename T>
void vdeb(const std::vector<T> &bb) {
    for (unsigned int i = 0;i < bb.size();i++) {
        if (i == bb.size() - 1) std::cout << bb[i];
        else std::cout << bb[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(const std::vector<std::vector<T>> &bb) {
    for (unsigned int i = 0;i < bb.size();i++) {
        std::cout << i << ' ';
        vdeb(bb[i]);
    }
    std::cout << '\n';
}
# endif

using namespace std;

void dfs1(vector<vector<int>> &da, vector<Pii> &ed, vector<ll> &score, int now, int depth) {
    if(score[now] != -1) return;
    score[now] = depth;
    rip(i,da[now].size(),0) {
        dfs1(da, ed, score, ed[da[now][i]].first^ed[da[now][i]].second^now, depth+1);
    }
}

void dfs2(vector<vector<int>> &da, vector<Pii> &ed, vector<ll> &ans, vector<ll> &weg, int now, ll depth) {
    if(ans[now] != -1) return;
    ans[now] = depth + weg[now];
    rip(i,da[now].size(),0) {
        dfs2(da, ed, ans, weg, ed[da[now][i]].first^ed[da[now][i]].second^now, ans[now]);
    }
}

int main() {
    int n; cin >> n;
    vector<Pii> ed(n-1);
    vector<vector<int>> da(n, vector<int>(0));
    vector<ll> score(n, -1);
    rip(i,n-1,0) {
        int a,b; cin >> a >> b;
        --a;--b;
        da[a].push_back(i);
        da[b].push_back(i);
        ed[i] = {a, b};
    }
    dfs1(da, ed, score, 0, 0);
    vector<ll> weg(n);
    vector<ll> ans(n, -1);
    // rip(i,n-1,0) {
    //     if(ed[i].first < ed[i].second) swap(ed[i].first, ed[i].second);
    // } 
    int q; cin >> q;
    rip(i,q,0) {
        ll t, e, x; cin >> t >> e >> x;
        --e;
        if(t == 1) {
            if(score[ed[e].first] > score[ed[e].second]) {
                weg[ed[e].first] += x;
            }
            else {
                weg[ed[e].second] -= x;
                weg[0] += x;
            }
        }
        else {
            if(score[ed[e].first] < score[ed[e].second]) {
                weg[ed[e].second] += x;
            }
            else {
                weg[ed[e].first] -= x;
                weg[0] += x;
            }
        }
    }
    dfs2(da, ed, ans, weg, 0, 0);
    rip(i,n,0) {
        cout << ans[i] << '\n';
    }
}
#include <bits/stdc++.h>
using namespace std;

#define R register
#define LL long long

inline int read() {
	int x = 0, f = 1; char a = getchar();
	for(; a > '9' || a < '0'; a = getchar()) if(a == '-') f = -1;
	for(; a <= '9' && a >= '0'; a = getchar()) x = x * 10 + a - '0';
	return x * f;
}

const int N = 4e5 + 10;

int n;
int a[N], b[N], uni[N], tot;
vector<int> e[N];
int vis[N];
int F = 0; int sz;
void dfs(int x, int las) {
	if(vis[x]) { F = 1; return ; }
	sz ++;
	vis[x] = 1;
	for(int y : e[x]) if(y != las) dfs(y, x);
}

signed main() {
	#ifdef IN
	freopen("a.in", "r", stdin);
	//freopen(".out", "w", stdout);
	#endif
	n = read();
	for(int i = 1; i <= n; i ++) a[i] = read(), b[i] = read(), uni[++ tot] = a[i], uni[++ tot] = b[i];
	sort(uni + 1, uni + 1 + tot);
	tot = unique(uni + 1, uni + 1 + tot) - uni - 1;
	for(int i = 1; i <= n; i ++) {
		a[i] = lower_bound(uni + 1, uni + 1 + tot, a[i]) - uni;
		b[i] = lower_bound(uni + 1, uni + 1 + tot, b[i]) - uni;
	}
	for(int i = 1; i <= n; i ++) {
		e[a[i]].push_back(b[i]);
		e[b[i]].push_back(a[i]);
	}
	int ans = 0;
	for(int i = 1; i <= tot; i ++)
		if(! vis[i]) {
			F = 0; sz = 0;dfs(i, 0);
			ans += sz - 1;
			if(F) ans ++;
		}	
	cout << ans << endl;
	return 0;	
}