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 maxn = 100010;
int n, K, cur, tag;
vector<pair<int, int>> G[maxn], fish[maxn];
inline int get(pair<int, int> A) {
  return A.first + (A.second > 0 ? -tag : tag);
}
struct comp {
  bool operator()(pair<int, int> A, pair<int, int> B) {
    return get(A) < get(B);
  }
};
struct DS {
  int tag;
  set<pair<int, int>, comp> diff;
  set<pair<int, pair<int, int>>> S;
  void ins_collision(pair<int, int> A, pair<int, int> B) {
    if (A.second < 0 && B.second > 0) S.emplace((B.first - A.first + 1) / 2, A);
  }
  void del_collision(pair<int, int> A, pair<int, int> B) {
    if (A.second < 0 && B.second > 0) S.erase({(B.first - A.first + 1) / 2, A});
  }
  void ins(set<pair<int, int>, comp>::iterator it) {
    auto pre = it, nxt = next(it);
    if (pre != diff.begin()) {
      ins_collision(*--pre, *it);
      if (nxt != diff.end()) del_collision(*pre, *nxt);
    }
    if (nxt != diff.end()) ins_collision(*it, *nxt);
  }
  void del(set<pair<int, int>, comp>::iterator it) {
    auto pre = it, nxt = next(it);
    if (pre != diff.begin()) {
      del_collision(*--pre, *it);
      if (nxt != diff.end()) ins_collision(*pre, *nxt);
    }
    if (nxt != diff.end()) del_collision(*it, *nxt);
    diff.erase(it);
  }
  void ins(pair<int, int> v) {
    if (!v.second) return;
    int o = v.first;
    ::tag = tag, v.first += v.second > 0 ? tag : -tag;
    auto it = diff.find(v);
    if (it != diff.end()) v.second += it->second, del(it);
    if (!v.second) return;
    v.first = o + (v.second > 0 ? tag : -tag);
    ins(it = diff.insert(v).first);
  }
  int delta(int p) {
    ::tag = tag;
    auto it = diff.find({p + tag, 1});
    return it != diff.end() ? it->second : 0;
  }
  void advance(int l) {
    ::tag = tag;
    while (!S.empty() && S.begin()->first - tag <= l) {
      auto p = *S.begin();
      auto it = diff.find(p.second);
      auto L = *it;
      it++, del(prev(it));
      auto R = *it;
      del(it);
      if (L.second += R.second) ins({get(L.second > 0 ? R : L), L.second});
    }
    tag += l;
  }
  void merge(DS &o) {
    if (diff.size() < o.diff.size())
      swap(tag, o.tag), swap(diff, o.diff), swap(S, o.S);
    static vector<pair<int, int>> tmp;
    ::tag = o.tag, tmp.clear();
    for (auto p : o.diff) tmp.emplace_back(get(p), p.second);
    ::tag = tag;
    for (auto p : tmp) ins(p);
  }
  void upd(vector<pair<int, int>> &fish, int l) {
    ::tag = tag;
    vector<int> tmp;
    for (auto p : fish) {
      int a = delta(p.first - 1), b = delta(p.first), c = delta(p.first + 1);
      tmp.push_back(max(0, p.second + a + b - max({a, a + b, a + b + c})));
    }
    advance(1);
    for (int i = 0; i < fish.size(); i++)
      if (tmp[i]) {
        ins({fish[i].first, tmp[i]}), ins({fish[i].first + 1, -tmp[i]});
      }
    advance(l - 1);
  }
  void print() {
    ::tag = tag;
    int cur = 0, mx = 0;
    for (auto p : diff) mx = max(mx, cur += p.second);
    printf("%d\n", mx);
  }
} f[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 1, u, v, w; i < n; i++) {
    scanf("%d %d %d", &u, &v, &w), w <<= 1;
    G[u].emplace_back(v, w), G[v].emplace_back(u, w);
  }
  scanf("%d", &K);
  while (K--) {
    int d, f, p;
    scanf("%d %d %d", &d, &f, &p);
    fish[p].emplace_back(d << 1, f);
  }
  function<void(int, int, int)> dfs = [&](int v, int fa, int w) {
    for (auto e : G[v])
      if (e.first ^ fa) {
        dfs(e.first, v, e.second), f[v].merge(f[e.first]);
      }
    f[v].upd(fish[v], w);
  };
  dfs(1, 0, 1), f[1].print();
  return 0;
}