/*
    __  ___        __
   /  |/  /____   / /_ ____   _____ ____ _ _____
  / /|_/ // __ \ / __// __ \ / ___// __ `// ___/
 / /  / // /_/ // /_ / /_/ // /   / /_/ /(__  )
/_/  /_/ \____/ \__/ \____//_/    \__,_//____/
*/

#ifndef __AHA__HEADER
#define __AHA__HEADER

#include <bits/stdc++.h>
using namespace std;
#define g0 get<0>
#define g1 get<1>
#define g2 get<2>
#define ft first
#define sd second
#define sz(x) (i6) x.size()
#define psb(x) push_back(x)
#define ppb() pop_back()
#define bg(x) x.begin()
#define ed(x) x.end()
#define col(x) x.begin(), x.end()
#define srt(x) sort(x.begin(), x.end())
#define vec vector
#define deq deque
#define hmap unordered_map
#define pq priority_queue
#define fn function
#ifdef LOCAL
#define git stauDBG_MACRO_NO_WARNING
#include <dbg.h>
#define dbgt dbg(dbg::time())
#else
#define dbg(...)
#define dbgt
#endif
typedef string str;
typedef int32_t i3;
typedef int64_t i6;
typedef int64_t i64;
typedef uint32_t u3;
typedef uint64_t u6;
typedef long double d6;
typedef pair<i6, i6> p6;
typedef vec<i6> vi6;
typedef vec<p6> vp6;
typedef vec<bool> vb;
typedef vec<vi6> vv;
typedef deq<p6> dp6;
typedef deq<i6> di6;
typedef map<i6, i6> mi6;
typedef map<p6, i6> mp6;
typedef set<i6> si6;
typedef hmap<i6, i6> hi6;
typedef vv graph;
typedef vv matrix;

const i6 INF = INT64_MAX / 4;
const i6 NINF = -INF;
const i6 ZERO = 0;
const i6 ONE = 1;

#endif

void build_prt(i6 p, i6 crt, vv& tree, vi6& prt) {
  for (auto& c : tree[crt]) {
    if (c != p) {
      prt[c] = crt;
      build_prt(crt, c, tree, prt);
    }
  }
}

void dfs(i6 p, i6 crt, i6 val, vv& tree, vi6& vals, vi6& ans) {
  ans[crt] = val + vals[crt];
  for (auto& c : tree[crt]) {
    if (c != p) {
      dfs(crt, c, ans[crt], tree, vals, ans);
    }
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifdef LOCAL
  ifstream cin{"input.txt"};
  ofstream cout{"output.txt"};
#endif
  i6 n;
  cin >> n;
  vp6 edges(n);
  vv tree(n + 1, vi6());
  for (i6 i = 0; i < n - 1; i++) {
    i6 x, y;
    cin >> x >> y;
    edges[i] = {x, y};
    tree[x].push_back(y);
    tree[y].push_back(x);
  }
  vi6 prt(n + 1, -1);
  build_prt(-1, 1, tree, prt);
  prt[1] = 1;
  i6 q;
  cin >> q;
  vi6 vals(n + 1, 0);
  for (int i = 1; i <= q; i++) {
    i6 t, e, x;
    cin >> t >> e >> x;
    auto crtp = edges[e - 1];
    if (t == 1) {
      if (prt[crtp.ft] != crtp.sd) {
        vals[1] += x;
        vals[crtp.sd] -= x;
      } else {
        vals[crtp.ft] += x;
      }
    } else {
      if (prt[crtp.sd] != crtp.ft) {
        vals[1] += x;
        vals[crtp.ft] -= x;
      } else {
        vals[crtp.sd] += x;
      }
    }
  }
  vi6 ans(n + 1, 0);
  dfs(-1, 1, 0, tree, vals, ans);
  for (i6 i = 1; i <= n; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;
const ll INF = 1e18;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n; cin >> n;
    vector<ll> x(n), c(n);
    vector<ll> l(n+2, INF), r(n+2, -INF);
    for(int i = 0; i < n; i++) {
        cin >> x[i] >> c[i];
        chmin(l[c[i]], x[i]);
        chmax(r[c[i]], x[i]);
    }
    l[0] = 0, r[0] = 0;
    l[n+1] = 0, r[n+1] = 0;
    vector<vector<ll>> dp(n+2, vector<ll>(2, INF));
    int pre = 0;
    dp[0][0] = 0;
    dp[0][1] = 0;
    for(int i = 1; i <= n+1; i++){
        if(l[i] == INF) continue;
        chmin(dp[i][0], dp[pre][0]+abs(r[i]-l[pre])+abs(l[i]-r[i]));
        chmin(dp[i][0], dp[pre][1]+abs(r[i]-r[pre])+abs(l[i]-r[i]));
        chmin(dp[i][1], dp[pre][0]+abs(l[i]-l[pre])+abs(l[i]-r[i]));
        chmin(dp[i][1], dp[pre][1]+abs(l[i]-r[pre])+abs(l[i]-r[i]));
        pre = i;
    }
    cout << dp[n+1][0] << endl;
}