#include <bits/stdc++.h>
#include <variant>

#define rep2(i,k,n) for(i64 i=(i64)(k);i<(i64)(n);i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) begin(x),end(x)
#ifdef ENV_LOCAL
#define dump if (1) cerr
#else
#define dump if (0) cerr
#endif

using namespace std;
using namespace std::string_literals;

using i32 = int32_t;
using i64 = int64_t;
using f64 = double;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;

//using namespace harudake;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  i32 n;
  cin>>n;
  vi64 ha(n+1);
  vi64 b(n), c(n);
  rep(i,n) {
    i32 a;
    cin>>a;
    ++ha[a];
  }
  rep(i,n) cin>>b[i];
  rep(i,n) cin>>c[i];
  i64 ans = 0;
  rep(i,n) {
    ans += ha[b[c[i]-1]];
  }
  cout<<ans<<endl;
  return 0;
}

#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
const long long MOD = 1000000007;

ll N, c[200010], q[200010];
pll edge[200010];
vector<ll> adj[200010];
ll depth[200010];
bool visited[200010];

void dep(ll i, ll d){
    if(depth[i] != -1) return;
    depth[i] = d;
    for(ll j : adj[i]) dep(j, d + 1);
}

void dfs(ll i, ll s){
    if(c[i] != -1) return;
    c[i] = s + q[i];
    for(ll j : adj[i]) dfs(j, c[i]);
}


signed main(){
    cin >> N;
    ll a, b;
    REP(i, N - 1){
        cin >> a >> b;
        a--; b--;
        edge[i] = {a, b};
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    REP(i, N) depth[i] = -1;
    dep(0, 0);
    ll Q, t, e, x;
    cin >> Q;
    REP(i, Q){
        cin >> t >> e >> x;
        t--; e--;
        auto [a, b] = edge[e];
        if(depth[a] > depth[b]){
            swap(a, b);
            t = 1 - t;
        }
        if(t == 0){
            q[0] += x;
            q[b] -= x;
        }else{
            q[b] += x;
        }
    }
    REP(i, N) c[i]= -1;
    dfs(0, 0);
    REP(i, N) PRINT(c[i]);
    return 0;
}