// C - Exoswap
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	int n; cin>>n;
	vector<int> ans, P(n); for(auto& x:P) cin>>x, --x; // -1

	int l = 0;
	rep(r, n){
		if(r == n-1 and P[r] != l){ puts("-1"); return 0; }
		if(P[r] == l){
			for(int i=r-1; i>=l; --i){
				ans.push_back(i+1);
				P[i+1] = P[i];
			}
			P[l] = l;
			l = r;
		}
	}

	rep(i, n) if(P[i] != i){ puts("-1"); return 0; }
	for(auto x:ans) cout<< x <<endl;
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
#define rng(i,l,r) for (int i=l; i<r; i++)
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> using V = vector<T>;
template<class T> bool chmin(T& a, T b){ if (a > b){ a = b; return true; } return false; }
template<class T> bool chmax(T& a, T b){ if (a < b){ a = b; return true; } return false; }
struct in { template <class T> operator T() { T t; std::cin >> t; return t; } };
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
int dx[8] = {0,1,0,-1,1,1,-1,-1};
int dy[8] = {1,0,-1,0,1,-1,1,-1};

// ノードに方向と伝播する値の総数を記録する
struct Edge {
   int to;
   ll x;
   Edge (int to) : to(to), x(0) {}
};
using Graph = V<V<Edge>>;
auto solve() {
   int n = in();
   Graph G(n+1);
   vector<int> a(n), b(n);
   rng(i,1,n) {
      cin >> a[i] >> b[i];
      G[a[i]].push_back(Edge(b[i]));
      G[b[i]].push_back(Edge(a[i]));
   }

   vector<ll> res(n+1, 0);

   vector<int> depth(n+1, 0);
   auto getdepth = [&](auto && self, int v, int from, int d=0) -> void {
      depth[v] = d;
      for (auto e: G[v]) {
         if (e.to == from) continue;
         self(self, e.to, v, d+1);
      }
   };
   getdepth(getdepth, 1, 0);

   int q = in();
   rep(i,q) {
      int t = in();
      int e = in();
      ll x = in();
      if (t == 1) {
         if (depth[a[e]] < depth[b[e]]) {
            res[b[e]] -= x;
            res[1] += x;
         } else {
            res[a[e]] += x;
         }
      } else {
         if (depth[a[e]] < depth[b[e]]) {
            res[b[e]] += x;
         } else {
            res[a[e]] -= x;
            res[1] += x;
         }
      }
   }


   auto propagate = [&](auto && self, int v, int from) -> void {
      for (auto e : G[v]) {
         if (e.to == from) continue;
         res[e.to] += res[v];
         self(self, e.to, v);
      }
   };
   propagate(propagate, 1, 0);
   rng(i,1,n+1) cout << res[i] << endl;
}

int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);

   solve();
}
