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 = 2e5 + 7, M = 4e6 + 7;
int n, m, q, k, p[N], t[N], vs[M], siz[N], va[M], vb[M];
vector<int> v[N], w[N];
struct node {
  int t, f;
};
vector<node> e[N];
struct note {
  int a, b;
} gt[N];
struct nope {
  int a, b, t;
};
priority_queue<nope> g[N];
inline int find(int u) {
  if (vs[u] == u) return u;
  return vs[u] = find(vs[u]);
}
inline bool operator<(note a, note b) {
  if (a.a == b.a) return a.b > b.b;
  return a.a < b.a;
}
inline bool operator<(nope a, nope b) {
  if (a.t == b.t) return max(a.a, a.b) < max(b.a, b.b);
  return a.t > b.t;
}
set<note> f1[N], f2[N];
inline void updatea(int u, int c) {
  note w;
  w.a = va[c] + t[u] * 2 + 1, w.b = 998244353;
  f2[u].insert(w);
  if ((*f2[u].rbegin()).b == 998244353) {
    f2[u].erase(w);
    return;
  };
  note e = (*(++f2[u].find(w)));
  f2[u].erase(w);
  if (find(e.b) == find(c) && (*f2[u].rbegin()).b == e.b) return;
  if (find(e.b) == find(c)) e = (*(++f2[u].find(e)));
  nope v;
  v.a = c, v.b = e.b, v.t = (va[v.b] - va[v.a] + 1) / 2;
  g[u].push(v);
}
inline void updateb(int u, int c) {
  note w;
  w.a = va[c] - t[u] * 2 - 1, w.b = -998244353;
  f1[u].insert(w);
  if ((*f1[u].begin()).b == -998244353) {
    f1[u].erase(w);
    return;
  };
  note e = (*(--f1[u].find(w)));
  f1[u].erase(w);
  if (find(e.b) == find(c) && (*f1[u].begin()).b == e.b) return;
  if (find(e.b) == find(c)) e = (*(--f1[u].find(e)));
  nope v;
  v.a = e.b, v.b = c, v.t = (va[v.b] - va[v.a] + 1) / 2;
  g[u].push(v);
}
inline void update(int u, int k) {
  while (g[u].size()) {
    nope z = g[u].top();
    if (va[z.a] == -1 || va[z.b] == -1) {
      g[u].pop();
      continue;
    }
    if (z.t <= t[u]) {
      g[u].pop();
      continue;
    }
    if (z.t <= t[u] + k) {
      g[u].pop();
      note r;
      r.a = va[z.a], r.b = z.a;
      note w1, w2, h1, h2;
      w1.a = -1, w1.b = -1, w2.a = -1, w2.b = -1, h1.a = -1, h1.b = -1,
      h2.a = -1, h2.b = -1;
      if ((*f1[u].begin()).b != r.b) w1 = (*(--f1[u].find(r)));
      if ((*f1[u].rbegin()).b != r.b) w2 = (*(++f1[u].find(r)));
      f1[u].erase(r);
      note c;
      c.a = va[z.b], c.b = z.b;
      if ((*f2[u].begin()).b != c.b) h1 = (*(--f2[u].find(c)));
      if ((*f2[u].rbegin()).b != c.b) h2 = (*(++f2[u].find(c)));
      f2[u].erase(c);
      if (vb[z.a] + vb[z.b] < 0) {
        m++, va[m] = va[z.a], vb[m] = vb[z.a] + vb[z.b], vs[m] = vs[z.a];
        c.a = va[m], c.b = m;
        f1[u].insert(c);
        updatea(u, m);
      }
      if (vb[z.a] + vb[z.b] > 0) {
        m++, va[m] = va[z.b], vb[m] = vb[z.a] + vb[z.b], vs[m] = vs[z.b],
             c.a = va[m], c.b = m;
        f2[u].insert(c);
        updateb(u, m);
      }
      if (w1.b != -1) updatea(u, w1.b);
      if (w2.b != -1) updatea(u, w2.b);
      if (h1.b != -1) updateb(u, h1.b);
      if (h2.b != -1) updateb(u, h2.b);
      va[z.a] = -1, va[z.b] = -1;
    } else
      break;
  }
  t[u] += k;
}
inline int merge(int a, int b) {
  if (siz[a] < siz[b]) swap(a, b);
  siz[a] += siz[b];
  set<note>::iterator iter = f1[b].begin();
  while (iter != f1[b].end()) {
    note w = (*iter);
    m++, va[m] = w.a + t[b] - t[a], vb[m] = vb[w.b], va[w.b] = -1, w.a = va[m],
         w.b = m, vs[m] = m;
    f1[a].insert(w), iter++, updatea(a, m);
  }
  iter = f2[b].begin();
  while (iter != f2[b].end()) {
    note w = (*iter);
    m++, va[m] = w.a - t[b] + t[a], vb[m] = vb[w.b], va[w.b] = -1, w.a = va[m],
         w.b = m, vs[m] = m;
    f2[a].insert(w), iter++, updateb(a, m);
  }
  return a;
}
inline void dfs(int u, int fa) {
  p[u] = u;
  for (int i = 0; i < v[u].size(); i++) {
    int x = v[u][i];
    if (x == fa) continue;
    dfs(x, u);
    for (int c = 0; c < e[x].size(); c++) {
      node s = e[x][c];
      vs[m + 1] = vs[m + 2] = m + 2;
      note v;
      m++, va[m] = s.t * 2 - t[p[x]], vb[m] = -s.f, v.a = va[m], v.b = m;
      f1[p[x]].insert(v), updatea(p[x], m);
      note q;
      m++, va[m] = s.t * 2 + t[p[x]] + 1, vb[m] = s.f, q.a = va[m], q.b = m;
      f2[p[x]].insert(q), updateb(p[x], m);
      siz[p[x]]++;
    }
    update(p[x], w[u][i] * 2);
    p[u] = merge(p[u], p[x]);
  }
}
inline bool tmp(note a, note b) { return a.a < b.a; }
int main() {
  cin >> n;
  int a, b, c;
  for (int i = 1; i < n; i++) {
    scanf("%d%d%d", &a, &b, &c);
    v[a].push_back(b), v[b].push_back(a);
    w[a].push_back(c), w[b].push_back(c);
  }
  v[1].push_back(n + 1), v[n + 1].push_back(1);
  w[1].push_back(1), w[n + 1].push_back(1);
  cin >> q;
  while (q--) {
    scanf("%d%d%d", &a, &b, &c);
    node d;
    d.t = a, d.f = b;
    e[c].push_back(d);
  }
  dfs(n + 1, 0);
  set<note>::iterator iter = f1[p[n + 1]].begin();
  while (iter != f1[p[n + 1]].end()) {
    note w = (*iter);
    gt[++k] = w;
    gt[k].a += t[p[n + 1]];
    iter++;
  }
  iter = f2[p[n + 1]].begin();
  while (iter != f2[p[n + 1]].end()) {
    note w = (*iter);
    gt[++k] = w;
    gt[k].a -= t[p[n + 1]];
    iter++;
  }
  sort(gt + 1, gt + k + 1, tmp);
  int sum = 0, ans = 0;
  for (int i = 1; i <= k; i++) {
    int j = i;
    sum += vb[gt[i].b];
    while (gt[j + 1].a == gt[i].a && j + 1 <= k) sum += vb[gt[j + 1].b], j++;
    i = j;
    ans = max(ans, sum);
  }
  cout << ans << endl;
}