Problem: A group of researchers are studying fish population in a natural system of lakes and rivers. The system contains n lakes connected by n - 1 rivers. Each river has integer length (in kilometers) and can be traversed in both directions. It is possible to travel between any pair of lakes by traversing the rivers (that is, the network of lakes and rivers form a tree).

There is an unknown number of indistinguishable fish living in the lakes. On day 1, fish can be at arbitrary lakes. Fish can travel between lakes by swimming the rivers. Each fish can swim a river l kilometers long in any direction in l days. Further, each fish can stay any number of days in any particular lake it visits. No fish ever appear or disappear from the lake system. Each lake can accomodate any number of fish at any time.

The researchers made several observations. The j-th of these observations is "on day d_j there were at least f_j distinct fish in the lake p_j". Help the researchers in determining the smallest possible total number of fish living in the lake system that doesn't contradict the observations.

Input

The first line contains a single integer n (1 ≤ n ≤ 10^5) — the number of lakes in the system.

The next n - 1 lines describe the rivers. The i-th of these lines contains three integers u_i, v_i, l_i (1 ≤ u_i, v_i ≤ n, u_i ≠ v_i, 1 ≤ l_i ≤ 10^3) — 1-based indices of lakes connected by the i-th river, and the length of this river.

The next line contains a single integer k (1 ≤ k ≤ 10^5) — the number of observations.

The next k lines describe the observations. The j-th of these lines contains three integers d_j, f_j, p_j (1 ≤ d_j ≤ 10^8, 1 ≤ f_j ≤ 10^4, 1 ≤ p_j ≤ n) — the day, the number of fish, and the lake index of the j-th observation. No two observations happen on the same day at the same lake simultaneously.

Output

Print one integer — the smallest total number of fish not contradicting the observations.

Examples

Input

4
1 2 1
1 3 1
1 4 1
5
1 1 2
1 1 3
2 2 1
3 1 4
3 1 2


Output

2


Input

5
1 2 1
1 3 1
1 4 1
1 5 1
4
1 1 2
2 1 3
3 1 4
4 1 5


Output

2


Input

5
2 5 1
5 1 1
2 4 1
5 3 3
6
5 2 4
2 1 1
2 1 3
2 2 4
4 7 5
4 1 2


Output

10

Note

In the first example, there could be one fish swimming through lakes 2, 1, and 4, and the second fish swimming through lakes 3, 1, and 2.

In the second example a single fish can not possibly be part of all observations simultaneously, but two fish swimming 2 → 1 → 4 and 3 → 1 → 5 can.

In the third example one fish can move from lake 1 to lake 5, others staying in their lakes during all time: two fish in lake 4, six fish in lake 5, one fish in lake 3. The system of lakes is shown on the picture.

<image>

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, I = 1 << 30;
int n, m, u, v, w, i, rt[N];
vector<pair<int, int> > e[N], ev[N];
struct node {
  int ch[2], fa;
  int tg, v, mn, w, s, sz, lv, rv;
  bool tp, lt, rt;
  inline int dir(int x) { return ch[1] == x; }
  inline void addtag(int d) {
    tg += d;
    tp ? v += d : v -= d;
    lt ? lv += d : lv -= d;
    rt ? rv += d : rv -= d;
    mn -= d * 2;
  }
} t[N * 2];
int tcnt;
inline void upd(int x) {
  int l = t[x].ch[0], r = t[x].ch[1];
  if (l)
    t[x].lv = t[l].lv, t[x].lt = t[l].lt;
  else
    t[x].lv = t[x].v, t[x].lt = t[x].tp;
  if (r)
    t[x].rv = t[r].rv, t[x].rt = t[r].rt;
  else
    t[x].rv = t[x].v, t[x].rt = t[x].tp;
  t[x].s = t[l].s + t[r].s + t[x].w;
  t[x].sz = t[l].sz + t[r].sz + 1;
  t[x].mn =
      min(min(t[l].mn, t[r].mn), t[x].tp ? r && !t[r].lt ? t[r].lv - t[x].v : I
                                 : l && t[l].rt ? t[x].v - t[l].rv
                                                : I);
}
inline void pushdown(int x) {
  int& z = t[x].tg;
  if (z) {
    if (t[x].ch[0]) t[t[x].ch[0]].addtag(z);
    if (t[x].ch[1]) t[t[x].ch[1]].addtag(z);
    z = 0;
  }
}
inline void rotate(int x) {
  int y = t[x].fa, z = t[y].fa, o = t[y].dir(x);
  t[z].ch[t[z].dir(y)] = x;
  t[x].fa = z;
  t[t[x].ch[!o]].fa = y;
  t[y].ch[o] = t[x].ch[!o];
  t[x].ch[!o] = y;
  t[y].fa = x;
  upd(y);
}
inline void splay(int x, int xx = 0) {
  static int st[N * 2];
  int w = 0, y, z;
  for (y = x; y != xx; y = t[y].fa) st[++w] = y;
  for (; w;) pushdown(st[w--]);
  for (; t[x].fa != xx; rotate(x)) {
    y = t[x].fa;
    z = t[y].fa;
    if (z != xx) rotate(t[z].dir(y) == t[y].dir(x) ? y : x);
  }
  upd(x);
}
inline void go(int& x, int o) {
  for (; t[x].ch[o]; x = t[x].ch[o])
    ;
}
inline int merge(int x, int y) {
  t[x].fa = t[y].fa = 0;
  if (!x || !y) return x | y;
  go(x, 1);
  splay(x);
  t[x].ch[1] = y;
  t[y].fa = x;
  upd(x);
  return x;
}
inline void stre(int& x, int le) {
  if (!x) return;
  for (; t[x].mn <= le * 2;) {
    for (;;) {
      pushdown(x);
      int l = t[x].ch[0], r = t[x].ch[1], y = t[x].fa, o = t[y].dir(x);
      if (!t[x].tp && l && t[l].rt && t[x].v - t[l].rv <= le * 2) {
        go(l, 1);
        splay(l, x);
        t[l].w += t[x].w;
        if (t[l].w > 0) t[l].tp = 0, t[l].v = t[x].v;
        upd(l);
        x = merge(t[l].w ? l : t[l].ch[0], r);
        t[y].ch[o] = x;
        t[x].fa = y;
        if (!x) x = y;
        break;
      }
      if (t[x].tp && r && !t[r].lt && t[r].lv - t[x].v <= le * 2) {
        go(r, 0);
        splay(r, x);
        t[r].w += t[x].w;
        if (t[r].w < 0) t[r].tp = 1, t[r].v = t[x].v;
        upd(r);
        x = merge(l, t[r].w ? r : t[r].ch[1]);
        t[y].ch[o] = x;
        t[x].fa = y;
        if (!x) x = y;
        break;
      }
      x = t[l].mn <= le * 2 ? l : r;
    }
    splay(x);
  }
  t[x].addtag(le);
}
inline void ins(int& x, int v, int w, int u = 0) {
  auto getn = [&]() {
    if (!u) u = ++tcnt;
    t[u] = node{0, 0, x, 0, v, I, w, w, 1, w, w, 0, 0, 0};
    x = u;
  };
  if (!x)
    getn();
  else
    for (;;) {
      if (v == t[x].v) {
        t[x].w += w;
        break;
      }
      pushdown(x);
      int o = v > t[x].v;
      if (!t[x].ch[o]) {
        t[x].ch[o] = u ? u : tcnt + 1;
        getn();
        break;
      }
      x = t[x].ch[o];
    }
  splay(x);
  if (!t[x].w)
    x = merge(t[x].ch[0], t[x].ch[1]);
  else
    t[x].tp = t[x].w < 0;
  upd(x);
}
int aa[N * 2], ww;
void dfss(int x) {
  pushdown(x);
  if (t[x].ch[0]) dfss(t[x].ch[0]);
  aa[++ww] = x;
  if (t[x].ch[1]) dfss(t[x].ch[1]);
}
inline void join(int& x, int y) {
  ww = 0;
  dfss(y);
  for (i = 1; i <= ww; ++i) ins(x, t[aa[i]].v, t[aa[i]].w, aa[i]);
}
inline int getv(int& x, int k) {
  if (!x) return 0;
  int ans = 0;
  for (;;) {
    pushdown(x);
    int o = k >= t[x].v;
    if (o) ans += t[t[x].ch[0]].s + t[x].w;
    if (t[x].ch[o])
      x = t[x].ch[o];
    else
      break;
  }
  splay(x);
  return ans;
}
void dfs(int x, int fa) {
  for (auto u : e[x]) {
    int y, l;
    tie(y, l) = u;
    if (y == fa) continue;
    dfs(y, x);
    stre(rt[y], 2 * l - 1);
    if (t[rt[x]].sz < t[rt[y]].sz) swap(rt[x], rt[y]);
    if (rt[y]) join(rt[x], rt[y]);
  }
  for (auto& u : ev[x]) u.second += getv(rt[x], u.first);
  stre(rt[x], 1);
  for (auto u : ev[x]) {
    int xx, y, z;
    tie(xx, y) = u;
    z = getv(rt[x], xx);
    if (y > z) ins(rt[x], xx, y - z), ins(rt[x], xx + 1, z - y);
  }
}
int main() {
  t[0].mn = I;
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (i = 1; i < n; ++i)
    cin >> u >> v >> w, e[u].push_back({v, w}), e[v].push_back({u, w});
  cin >> m;
  for (i = 1; i <= m; ++i) cin >> w >> v >> u, ev[u].push_back({w * 2, v});
  int ans = 0, zz = 0;
  dfs(1, 0);
  ww = 0;
  dfss(rt[1]);
  for (i = 1; i <= ww; ++i) ans = max(ans, zz += t[aa[i]].w);
  cout << ans << endl;
}