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;
inline int read() {
  char c = getchar();
  int x = 0;
  bool f = 0;
  for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  if (f) x = -x;
  return x;
}
int n, m;
vector<pair<int, int> > e[200005];
vector<pair<int, int> > add[200005];
struct data {
  map<int, int> pos, neg;
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      q;
  int tag;
  int size() { return pos.size() + neg.size(); }
  int calc_ans() {
    map<int, int> mp;
    for (auto it : pos) mp[it.first - tag] += it.second;
    for (auto it : neg) mp[it.first + tag] += it.second;
    int res = 0, now = 0;
    for (auto it : mp) now += it.second, res = max(res, now);
    return res;
  }
  inline int get(int x) {
    auto t1 = pos.find(x + tag), t2 = neg.find(x - tag);
    return (t1 == pos.end() ? 0 : t1->second) +
           (t2 == neg.end() ? 0 : t2->second);
  }
  void adjust(int x, bool o) {
    if (o) {
      auto it = neg.upper_bound(x - tag * 2);
      if (it == neg.begin()) return;
      --it;
      q.push(make_pair(x - (it->first), x));
    } else {
      auto it = pos.lower_bound(x + tag * 2);
      if (it == pos.end()) return;
      q.push(make_pair((it->first) - x, it->first));
    }
  }
  void ins(int x, int w) {
    if (w > 0)
      pos[x + tag] += w, adjust(x + tag, 1);
    else
      neg[x - tag] += w, adjust(x - tag, 0);
  }
  void up(int l) {
    while (!q.empty()) {
      pair<int, int> _ = q.top();
      if (_.first > (tag + l << 1)) break;
      q.pop();
      int x = _.second, y = x - _.first;
      auto i = pos.find(x), j = neg.find(y);
      if (i == pos.end() || j == neg.end()) continue;
      if (i->second + j->second < 0) {
        j->second += i->second;
        pos.erase(i);
        adjust(j->first, false);
      } else {
        i->second += j->second;
        neg.erase(j);
        adjust(i->first, true);
      }
    }
    tag += l;
  }
  void operator+=(const data &b) {
    for (auto t : b.pos) ins(t.first - b.tag, t.second);
    for (auto t : b.neg) ins(t.first + b.tag, t.second);
  }
};
data dp[200005];
void merge(data &a, data &b) {
  for (auto it : b.pos) a.ins(it.first - b.tag, it.second);
  for (auto it : b.neg) a.ins(it.first + b.tag, it.second);
}
void dfs(int u, int pa) {
  for (auto it : e[u]) {
    int v = it.first, w = it.second;
    if (v == pa) continue;
    dfs(v, u);
    for (auto &t : add[v])
      t.second -= max(0, max(-dp[v].get(t.first), dp[v].get(t.first + 1)));
    dp[v].up(1);
    for (auto t : add[v])
      if (t.second > 0) {
        dp[v].ins(t.first, t.second);
        dp[v].ins(t.first + 1, -t.second);
      }
    dp[v].up(w - 1);
    if (dp[u].size() < dp[v].size()) swap(dp[u], dp[v]);
    dp[u] += dp[v];
  }
}
signed main() {
  n = read();
  for (register int i = (2); i <= (n); ++i) {
    int u = read(), v = read(), w = read() << 1;
    e[u].push_back(make_pair(v, w)), e[v].push_back(make_pair(u, w));
  }
  e[0].push_back(make_pair(1, 2));
  m = read();
  while (m--) {
    int d = read() << 1, x = read(), pos = read();
    add[pos].push_back(make_pair(d, x));
  }
  dfs(0, 0);
  cout << dp[0].calc_ans();
  return 0;
}