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 = 100005;
using ll = long long;
using pii = pair<int, int>;
vector<pii> v[N], f[N];
int n, m, cur, dep[N];
struct Node {
  int x, d, v;
  Node(int x, int d, int v, int t = 0) : x(x - d * t), d(d), v(v) {}
};
inline bool operator<(const Node &a, const Node &b) {
  int p = a.x + cur * a.d, q = b.x + cur * b.d;
  return p == q ? a.d < b.d : p < q;
}
struct Collision {
  Node x, y;
  int t;
  Collision(Node x, Node y) : x(x), y(y), t((y.x - x.x) >> 1) {}
};
inline bool operator<(const Collision &a, const Collision &b) {
  return a.t != b.t ? a.t < b.t
                    : make_tuple(a.x.x, a.x.v, a.y.x, a.y.v) <
                          make_tuple(b.x.x, b.x.v, b.y.x, b.y.v);
}
struct Info {
  set<Collision> c;
  set<Node> nd;
  inline void insc(Node x, Node y) {
    if (x.d > 0 && y.d < 0) c.insert(Collision(x, y));
  }
  inline void erasec(Node x, Node y) {
    if (x.d > 0 && y.d < 0) c.erase(Collision(x, y));
  }
  void ins(Node x) {
    if (!x.v) return;
    if (nd.count(x)) x.v += nd.find(x)->v, erase(*nd.find(x));
    auto it = nd.insert(x).first, nxt = it;
    ++nxt;
    if (it != nd.begin()) {
      auto pre = it;
      --pre;
      if (nxt != nd.end()) erasec(*pre, *nxt);
      insc(*pre, x);
    }
    if (nxt != nd.end()) insc(x, *nxt);
  }
  void erase(Node x) {
    auto it = nd.find(x), nxt = it;
    ++nxt;
    if (nxt != nd.end()) erasec(x, *nxt);
    if (it != nd.begin()) {
      auto pre = it;
      --pre;
      erasec(*pre, x);
      if (nxt != nd.end()) insc(*pre, *nxt);
    }
    nd.erase(it);
  }
  int reset(int x, int y) {
    Node l(x + 1, -1, y, cur), r(x - 1, 1, y, cur);
    return max(0, y - max(nd.find(l) == nd.end() ? 0 : nd.find(l)->v,
                          nd.find(r) == nd.end() ? 0 : nd.find(r)->v));
  }
  Node cancel(Node x, Node y) {
    if (x.v > y.v)
      return Node(x.x, x.d, x.v - y.v);
    else
      return Node(y.x, y.d, y.v - x.v);
  }
  inline void collide(Collision x) {
    erase(x.x);
    erase(x.y);
    ins(cancel(x.x, x.y));
  }
  void maintain(int x) {
    while (!c.empty() && c.begin()->t <= x) collide(*c.begin());
  }
  void merge(Info &b) {
    if (nd.size() < b.nd.size()) swap(nd, b.nd), swap(c, b.c);
    for (auto &i : b.nd) ins(i);
  }
  int query() {
    int ret = 0;
    for (auto &i : nd)
      if (i.d > 0) ret += i.v;
    return ret;
  }
} info[N];
void dfs(int pos, int fa) {
  for (auto &i : v[pos]) {
    int vv = i.first, ww = i.second;
    if (vv == fa) continue;
    dep[vv] = dep[pos] + ww;
    dfs(vv, pos);
  }
}
void solve(int pos, int fa) {
  for (auto &i : v[pos]) {
    int vv = i.first;
    if (vv == fa) continue;
    solve(vv, pos);
    cur = -dep[vv];
    info[vv].maintain(-(dep[pos] + 1));
    cur = -(dep[pos] + 1);
    info[pos].merge(info[vv]);
  }
  cur = -(dep[pos] + 1);
  for (auto &i : f[pos]) i.second = info[pos].reset(i.first, i.second);
  info[pos].maintain(-dep[pos]);
  cur = -dep[pos];
  for (auto &i : f[pos])
    info[pos].ins(Node(i.first, -1, i.second, cur)),
        info[pos].ins(Node(i.first, 1, i.second, cur));
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int t1, t2, t3;
    cin >> t1 >> t2 >> t3;
    t3 <<= 1;
    v[t1].push_back({t2, t3});
    v[t2].push_back({t1, t3});
  }
  cin >> m;
  for (int i = 1; i <= m; i++) {
    int d, v, w;
    cin >> d >> v >> w;
    d <<= 1;
    f[w].push_back({d, v});
  }
  dfs(1, 0);
  solve(1, 0);
  info[1].maintain(INT_MAX);
  cout << info[1].query() << endl;
  return 0;
}