#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <stdio.h>

constexpr int buffer_size = 1 << 18;
int  offset = buffer_size;
char buffer[1 << 18];
inline void buffer_in(void){ fread(buffer, 1, offset, stdin); }
inline void buffer_out(void){ fwrite(buffer, 1, offset, stdout); }
inline void buffer_clear(void){ offset = 0; }

inline char readbyte(void){
    if(offset == buffer_size){ buffer_in(); offset = 0; }
    return buffer[offset++];
}
inline int readint(void){
    int res = 0; char c; while('0' <= (c = readbyte()) and c <= '9') res = 10 * res + c - '0';
    return res;
}

inline void writebyte(const char c){
    if(offset == buffer_size){ buffer_out(); offset = 0; }
    buffer[offset++] = c;
}
char buffer_for_longlong[20];
inline void writeint(long long int x){
    if(x == 0) writebyte('0');
    else{
        int pos = 0; 
        for(; x ; x /= 10) buffer_for_longlong[pos++] = (x % 10) + '0';
        while(pos) writebyte(buffer_for_longlong[--pos]);
    }
    writebyte('\n');
}


struct point{
    int a, b;
};

constexpr int MAX_N = 200010;
point P[MAX_N];
int depth[MAX_N];
int stack_len = 0;
int stack[MAX_N];
inline bool exists(void){ return stack_len; }
inline void push(int x){ stack[stack_len++] = x; }
inline int  pop(void){   return stack[--stack_len]; }

struct OPS {
    int val;
    int nxt;
};
OPS G[2 * MAX_N + 1];
int begin[MAX_N];
int now_position = 1;
inline void append(int idx, int val){
    G[now_position].val = val;
    G[now_position].nxt = begin[idx];
    begin[idx] = now_position++;
}

constexpr int root = 0;
long long int Value[MAX_N];

int main(void){
    const int n = readint();
    for(int i = 0; i + 1 < n; ++i){
        P[i].a = readint() - 1;
        P[i].b = readint() - 1;
        append(P[i].a, P[i].b);
        append(P[i].b, P[i].a);
    }
    depth[root] = 1; push(root);
    while(exists()){
        const int v = pop();
        for(int idx = begin[v]; idx ; idx = G[idx].nxt) if(depth[G[idx].val] == 0){
            depth[G[idx].val] = depth[v] + 1;
            push(G[idx].val);
        }
    }

    int q = readint();
    while(q--){
        char c = readbyte(); readbyte();
        int idx = readint() - 1, V = readint();

        int x, y; if(c == '1'){ x = P[idx].a, y = P[idx].b; } else{ x = P[idx].b, y = P[idx].a; }
        if(depth[x] < depth[y]){
            Value[0] += V;
            Value[y] -= V;
        }
        else Value[x] += V;
    }
    push(root);
    while(exists()){
        const int v = pop();
        for(int idx = begin[v]; idx ; idx = G[idx].nxt) if(depth[v] < depth[G[idx].val]){
            Value[G[idx].val] += Value[v];
            push(G[idx].val);
        }
    }
    buffer_clear();
    for(int i = 0; i < n; ++i) writeint(Value[i]);
    buffer_out();
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define int long long int
#define pb push_back
#define mp make_pair
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>
#define setbits(x) __builtin_popcountll(x)
#define md (ll)1e9 + 7
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define f(i, j, n) for (ll i = j; i < n; i++)
#define r(i, j, n) for (ll i = n - 1; i >= j; i--) 
vll v[1000000];
ll l[1000000]={0},c[1000000]={0};
bool vis[1000000],ans[1000000];//make it false
mll st;
void dfs(ll s)
{
    vis[s] = true;
    if(st[c[s]]!=0)
        ans[s]=false;
    st[c[s]]++;
    for(auto u : v[s])
    {
        if(!vis[u])
        {
           dfs(u);
        }
    }
    st[c[s]]--;
}
void solve()
{
    ll n;cin>>n; 
    memset(vis,false,sizeof(vis));
    memset(ans,true,sizeof(ans));
    f(i,1,n+1)cin>>c[i];
    for(int i=0;i<n-1;i++)
    {
        ll x,y; cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    dfs(1);
    f(i,1,n+1)
        if(ans[i])
            cout<<i<<"\n";
}
 main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("inpput.txt", "r", stdin); //freopen("op.txt", "w", stdout);
#endif
    ll test_cases = 1;
    //cin >> test_cases;
    for (ll t = 1; t <= test_cases; t++)
        solve(),cout<<"\n";;
    //cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";
}