#include<bits/stdc++.h>
using namespace std;
long long n,u_i[200005],sub,v_i[200005],d[200005],m,t,node,e,x,u,p[200005],val[200005],dp[200005];
vector<long long> v[200005];
queue<long long> q;
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%lld%lld",&u_i[i],&v_i[i]);
		v[u_i[i]].push_back(v_i[i]);
		v[v_i[i]].push_back(u_i[i]);
	}
	memset(d,-1,sizeof d);
	q.push(1);
	d[1]=0;
	while(!q.empty())
	{
		u=q.front();
		q.pop();
		for(int i=0;i<v[u].size();i++)
		{
			if(d[v[u][i]]==-1)
			{
				d[v[u][i]]=0;
				p[v[u][i]]=u;
				q.push(v[u][i]);
			}
		}
	}
	scanf("%lld",&m);
	while(m--)
	{
		scanf("%lld%lld%lld",&t,&e,&x);
		if(u_i[e]==p[v_i[e]])
		{
			node=u_i[e];
			sub=v_i[e];
		}else
		{
			node=v_i[e];
			sub=u_i[e];
		}
		if(t==1&&u_i[e]==p[v_i[e]]||t==2&&v_i[e]==p[u_i[e]])
		{
			dp[1]+=x;
			dp[sub]-=x;
			//printf("up\n");
		}else
		{
			//printf("down\n");
			dp[sub]+=x;
		}
	}
	memset(d,-1,sizeof d);
	d[1]=0;
	q.push(1);
	while(!q.empty())
	{
		u=q.front();
		q.pop();
		for(int i=0;i<v[u].size();i++)
		{
			if(d[v[u][i]]==-1)
			{
				d[v[u][i]]=0;
				dp[v[u][i]]+=dp[u];
				q.push(v[u][i]);
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		printf("%lld\n",dp[i]);
	}
}

#include <bits/stdc++.h>
#define ll long long int
using namespace std;
vector<int> graph[400001];

void dfs(int k, bool visited[], int par, bool &cond, int &si)
{
    if (visited[k])
    {
        return;
    }
    si++;
    visited[k] = true;
    for (auto i : graph[k])
    {
        if (i != par && visited[i] == true)
        {
            cond = true;
        }

        else
        {
            dfs(i, visited, k, cond, si);
        }
    }
}

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

    int t;
    cin >> t;
    pair<int, int> a[t];
    for (int i = 0; i < t; i++)
    {
        int a1, b;
        cin >> a1 >> b;
        graph[a1].push_back(b);
        graph[b].push_back(a1);
        a[i] = {a1, b};
    }
    bool visited[400001];
    memset(visited, false, sizeof(visited));
    int ans = 0;
    for (auto i : a)
    {
        if (!visited[i.first])
        {
            int si = 0;
            bool cond = false;
            dfs(i.first, visited, -1, cond, si);
            // cout << cond << " " << i.first << " " << si << endl;
            if (cond)
            {
                ans += si;
            }
            else
            {
                ans += si - 1;
            }
        }
        if (!visited[i.second])
        {
            int si = 0;
            bool cond = false;
            dfs(i.second, visited, -1, cond, si);
            // cout << cond << " " << i.second << " " << si << endl;
            if (cond)
            {
                ans += si;
            }
            else
            {
                ans += si - 1;
            }
        }
    }
    cout << ans << endl;
}
