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;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
struct State {
  int delta;
  map<int, int> pos;
  map<int, int> neg;
  set<pair<int, pair<int, int>>> matches;
  void init() {
    delta = 0;
    pos.clear();
    neg.clear();
    matches.clear();
  }
  int findmatchforpos(int x) {
    auto it = neg.lower_bound(x + delta);
    return it == neg.end() ? INT_MAX : it->first - delta;
  }
  int findmatchforneg(int y) {
    auto it = pos.upper_bound(y - delta);
    return it == pos.begin() ? INT_MIN : prev(it)->first + delta;
  }
  void erasepos(int x) {
    assert(pos.erase(x - delta));
    int y = findmatchforpos(x);
    if (y != INT_MAX) {
      int xx = findmatchforneg(y);
      if (xx == INT_MIN || xx <= x)
        assert(matches.erase(
            make_pair(y - x + 2 * delta, make_pair(x - delta, y + delta))));
      if (xx != INT_MIN && xx <= x && findmatchforpos(xx) == y)
        matches.insert(
            make_pair(y - xx + 2 * delta, make_pair(xx - delta, y + delta)));
    }
  }
  void eraseneg(int y) {
    assert(neg.erase(y + delta));
    int x = findmatchforneg(y);
    if (x != INT_MIN) {
      int yy = findmatchforpos(x);
      if (yy == INT_MAX || yy >= y)
        assert(matches.erase(
            make_pair(y - x + 2 * delta, make_pair(x - delta, y + delta))));
      if (yy != INT_MAX && yy >= y && findmatchforneg(yy) == x)
        matches.insert(
            make_pair(yy - x + 2 * delta, make_pair(x - delta, yy + delta)));
    }
  }
  void insertpos(int x, int val) {
    if (pos.count(x - delta)) {
      pos[x - delta] += val;
      return;
    }
    int y = findmatchforpos(x);
    if (y != INT_MAX) {
      int xx = findmatchforneg(y);
      if (xx != INT_MIN && xx < x && findmatchforpos(xx) == y)
        assert(matches.erase(
            make_pair(y - xx + 2 * delta, make_pair(xx - delta, y + delta))));
      if (xx == INT_MIN || xx < x)
        matches.insert(
            make_pair(y - x + 2 * delta, make_pair(x - delta, y + delta)));
    }
    pos[x - delta] = val;
  }
  void insertneg(int y, int val) {
    if (neg.count(y + delta)) {
      neg[y + delta] += val;
      return;
    }
    int x = findmatchforneg(y);
    if (x != INT_MIN) {
      int yy = findmatchforpos(x);
      if (yy != INT_MAX && yy > y && findmatchforneg(yy) == x)
        assert(matches.erase(
            make_pair(yy - x + 2 * delta, make_pair(x - delta, yy + delta))));
      if (yy == INT_MAX || yy > y)
        matches.insert(
            make_pair(y - x + 2 * delta, make_pair(x - delta, y + delta)));
    }
    neg[y + delta] = val;
  }
  void grow(int by) {
    while (((int)(matches).size()) != 0 &&
           matches.begin()->first - 2 * delta < 2 * by) {
      int x = matches.begin()->second.first + delta,
          y = matches.begin()->second.second - delta;
      assert(pos.count(x - delta));
      int xval = pos[x - delta];
      assert(neg.count(y + delta));
      int yval = neg[y + delta];
      if (xval < yval) {
        neg[y + delta] -= xval;
        erasepos(x);
      } else if (xval > yval) {
        pos[x - delta] -= yval;
        eraseneg(y);
      } else {
        erasepos(x);
        eraseneg(y);
      }
    }
    delta += by;
  }
  void print() {
    printf("\tneg:");
    for (auto it = neg.begin(); it != neg.end(); ++it)
      printf(" %d=%d", it->first - delta, it->second);
    puts("");
    printf("\tpos:");
    for (auto it = pos.begin(); it != pos.end(); ++it)
      printf(" %d=%d", it->first + delta, it->second);
    puts("");
    printf("\tmatches:");
    for (auto it = matches.begin(); it != matches.end(); ++it)
      printf(" %d:%d-%d", it->first - 2 * delta, it->second.first + delta,
             it->second.second - delta);
    puts("");
  }
};
const int MAXN = 100000;
int n;
vector<pair<int, int>> e[MAXN];
int nq;
vector<pair<int, int>> obs[MAXN];
State state[MAXN];
int merge(int a, int b) {
  int asz = ((int)(state[a].pos).size()) + ((int)(state[a].neg).size()),
      bsz = ((int)(state[b].pos).size()) + ((int)(state[b].neg).size());
  if (asz < bsz) swap(a, b), swap(asz, bsz);
  for (auto it = state[b].pos.begin(); it != state[b].pos.end(); ++it)
    state[a].insertpos(it->first + state[b].delta, it->second);
  for (auto it = state[b].neg.begin(); it != state[b].neg.end(); ++it)
    state[a].insertneg(it->first - state[b].delta, it->second);
  return a;
}
int dfs(int at, int par, int parlen) {
  int ret = at;
  state[ret].init();
  for (int i = (0); i < (((int)(e[at]).size())); ++i) {
    int to = e[at][i].first;
    if (to == par) continue;
    int cur = dfs(to, at, e[at][i].second);
    ret = merge(ret, cur);
  }
  vector<pair<int, int>> extra;
  for (int i = (0); i < (((int)(obs[at]).size())); ++i) {
    int t = obs[at][i].first, cnt = obs[at][i].second, rem = cnt;
    {
      int cur = (state[ret].pos.count(t - state[ret].delta)
                     ? state[ret].pos[t - state[ret].delta]
                     : 0) +
                (state[ret].pos.count(t - state[ret].delta - 1)
                     ? state[ret].pos[t - state[ret].delta - 1]
                     : 0);
      rem = min(rem, max(0, cnt - cur));
    }
    {
      int cur = (state[ret].neg.count(t + state[ret].delta)
                     ? state[ret].neg[t + state[ret].delta]
                     : 0) +
                (state[ret].neg.count(t + state[ret].delta + 1)
                     ? state[ret].neg[t + state[ret].delta + 1]
                     : 0);
      rem = min(rem, max(0, cnt - cur));
    }
    if (rem > 0) extra.push_back(make_pair(t, rem));
  }
  state[ret].grow(1);
  for (int i = (0); i < (((int)(extra).size())); ++i) {
    int t = extra[i].first, cnt = extra[i].second;
    state[ret].insertneg(t - 1, cnt);
    state[ret].insertpos(t + 1, cnt);
  }
  state[ret].grow(parlen - 1);
  return ret;
}
int solve() {
  for (int i = (0); i < (n); ++i) sort(obs[i].begin(), obs[i].end());
  int res = dfs(0, -1, 1);
  map<int, int> all;
  for (auto it = state[res].pos.begin(); it != state[res].pos.end(); ++it)
    all[2 * (it->first + state[res].delta) + 0] -= it->second;
  for (auto it = state[res].neg.begin(); it != state[res].neg.end(); ++it)
    all[2 * (it->first - state[res].delta) + 1] += it->second;
  int ret = 0, cur = 0;
  for (auto it = all.begin(); it != all.end(); ++it) {
    cur += it->second;
    ret = max(ret, cur);
  }
  return ret;
}
void run() {
  scanf("%d", &n);
  for (int i = (0); i < (n - 1); ++i) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    --a, --b, c *= 2;
    e[a].push_back(make_pair(b, c));
    e[b].push_back(make_pair(a, c));
  }
  scanf("%d", &nq);
  for (int i = (0); i < (nq); ++i) {
    int t, cnt, idx;
    scanf("%d%d%d", &t, &cnt, &idx);
    t *= 2;
    --idx;
    obs[idx].push_back(make_pair(t, cnt));
  }
  printf("%d\n", solve());
}
int main() {
  run();
  return 0;
}