#include <bits/stdc++.h>
using namespace std;

const int maxn = 200010;
int n, a[maxn], b[maxn], perm[maxn], c[maxn];
long long ans;
map<int, vector<int>> mp;
map<int, int> id;

void add(int p, int v) {
    for (; p <= n; p += p & -p) c[p] += v;
}

int query(int p) {
    int s = 0;
    for (; p; p -= p & -p) s += c[p];
    return s;
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]), a[i] += i;
        mp[a[i]].push_back(i);
    }
    for (int i = 1; i <= n; i++) {
        scanf("%d", &b[i]), b[i] += i;
    }
    for (int i = 1; i <= n; i++) {
        if (mp[b[i]].size() == id[b[i]]) puts("-1"), exit(0);
        perm[i] = mp[b[i]][id[b[i]]++];
        ans += i - 1 - query(perm[i]), add(perm[i], 1);
    }
    printf("%lld\n", ans);
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
using pii = pair<int, int>;

int main() {
  int N;
  cin >> N;
  vector<vector<int>> to(N);
  vector<int> a(N-1), b(N-1);
  rep(i,N-1) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    to[a[i]].push_back(b[i]); to[b[i]].push_back(a[i]);
  }
//  for(auto&x:to[0])cout<<x;cout<<endl;
  vector<ll> c(N,0);
  vector<pii> dag;
  vector<int> depth(N,-1);
  queue<int> q;
  q.push(0); depth[0]=0;
  while (!q.empty()) {
    int x=q.front(); q.pop();
    for (auto& y:to[x]) {
      if (depth[y] != -1) continue;
      depth[y] = depth[x] + 1;
      dag.push_back(pii(x,y));
      q.push(y);
    }
  }
//  for (auto&[x,y]:dag)cout<<"["<<x<<","<<y<<"],";
  int Q;
  cin >> Q;
  rep(i,Q) {
    int t,e,x;
    cin >> t >> e >> x;
    e--;
    int va=a[e], vb=b[e];
    if (t==2) swap(va, vb);
    if (depth[va]>depth[vb]) c[va] += x;
    else {c[0] += x; c[vb] -= x;}
  }
  for (auto& [x,y]:dag) {
    c[y] += c[x];
  }
  for (auto& x:c) printf("%ld\n",x);
}


