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 = 100000;
int n, m;
struct side {
  int y, next, v;
} e[N * 2 + 9];
int lin[N + 9], cs;
void Ins(int x, int y, int v) {
  e[++cs].y = y;
  e[cs].v = v;
  e[cs].next = lin[x];
  lin[x] = cs;
}
void Ins2(int x, int y, int v) {
  Ins(x, y, v);
  Ins(y, x, v);
}
struct fish {
  int t, c;
  fish(int T = 0, int C = 0) {
    t = T;
    c = C;
  }
};
vector<fish> a[N + 9];
void into() {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int x, y, v;
    scanf("%d%d%d", &x, &y, &v);
    v <<= 1;
    Ins2(x, y, v);
  }
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) {
    int t, x, c;
    scanf("%d%d%d", &t, &c, &x);
    t <<= 1;
    a[x].push_back(fish(t, c));
  }
}
struct data_structure {
  struct state {
    int d, y;
    state(int D = 0, int Y = 0) {
      d = D;
      y = Y;
    }
    bool operator>(const state &p) const {
      return d > p.d || d == p.d && y > p.y;
    }
  };
  priority_queue<state, vector<state>, greater<state> > q;
  map<int, int> mp[2];
  int d;
  int size() { return mp[0].size() + mp[1].size(); }
  void Clear() {
    mp[0].clear();
    mp[1].clear();
    for (; !q.empty(); q.pop())
      ;
    d = 0;
  }
  void Adjust(int p, int opt) {
    if (opt) {
      map<int, int>::iterator it = mp[0].lower_bound(p + 2 * d);
      if (it == mp[0].end()) return;
      q.push(state(it->first - p, it->first));
    } else {
      map<int, int>::iterator it = mp[1].upper_bound(p - 2 * d);
      if (it == mp[1].begin()) return;
      --it;
      q.push(state(p - it->first, p));
    }
  }
  void Insert(int p, int v) {
    if (v > 0) {
      p += d;
      mp[0][p] += v;
      Adjust(p, 0);
    } else {
      p -= d;
      mp[1][p] += v;
      Adjust(p, 1);
    }
  }
  void Move(int v) {
    if (!v) return;
    for (; !q.empty() && q.top().d <= 2 * (d + v);) {
      state t = q.top();
      q.pop();
      int x = t.y - t.d, y = t.y;
      map<int, int>::iterator itx = mp[1].find(x);
      map<int, int>::iterator ity = mp[0].find(y);
      if (itx == mp[1].end() || ity == mp[0].end()) continue;
      if (-itx->second < ity->second) {
        ity->second += itx->second;
        mp[1].erase(itx);
        Adjust(ity->first, 0);
      } else {
        itx->second += ity->second;
        mp[0].erase(ity);
        Adjust(itx->first, 1);
      }
    }
    d += v;
  }
  int Query(int p) {
    int res = 0;
    if (mp[0].find(p + d) != mp[0].end()) res += mp[0][p + d];
    if (mp[1].find(p - d) != mp[1].end()) res += mp[1][p - d];
    return res;
  }
} s[N + 9];
int id[N + 9];
int Merge(int x, int y) {
  if (s[x].size() < s[y].size()) swap(x, y);
  for (map<int, int>::iterator it = s[y].mp[0].begin(); it != s[y].mp[0].end();
       ++it)
    s[x].Insert(it->first - s[y].d, it->second);
  for (map<int, int>::iterator it = s[y].mp[1].begin(); it != s[y].mp[1].end();
       ++it)
    s[x].Insert(it->first + s[y].d, it->second);
  s[y].mp[0].clear();
  s[y].mp[1].clear();
  for (; !s[y].q.empty(); s[y].q.pop())
    ;
  return x;
}
void Dfs_ans(int k, int fa, int v) {
  for (int i = lin[k]; i; i = e[i].next) {
    int y = e[i].y, v = e[i].v;
    if (y == fa) continue;
    Dfs_ans(y, k, e[i].v);
    id[k] = Merge(id[k], id[y]);
  }
  for (int vs = a[k].size(), i = 0; i < vs; ++i) {
    int x = s[id[k]].Query(a[k][i].t), y = s[id[k]].Query(a[k][i].t + 1);
    a[k][i].c -= max(0, max(-x, y));
  }
  s[id[k]].Move(1);
  for (int vs = a[k].size(), i = 0; i < vs; ++i) {
    if (a[k][i].c <= 0) continue;
    s[id[k]].Insert(a[k][i].t, a[k][i].c);
    s[id[k]].Insert(a[k][i].t + 1, -a[k][i].c);
  }
  s[id[k]].Move(v - 1);
}
int ans;
void Get_ans() {
  for (int i = 1; i <= n; ++i) id[i] = i;
  Dfs_ans(1, 0, 2);
  int k = id[1], now = 0;
  map<int, int> mp;
  for (map<int, int>::iterator it = s[k].mp[0].begin(); it != s[k].mp[0].end();
       ++it)
    mp[it->first - s[k].d] += it->second;
  for (map<int, int>::iterator it = s[k].mp[1].begin(); it != s[k].mp[1].end();
       ++it)
    mp[it->first + s[k].d] += it->second;
  for (map<int, int>::iterator it = mp.begin(); it != mp.end(); ++it) {
    now += it->second;
    ans = max(ans, now);
  }
}
void work() { Get_ans(); }
void outo() { printf("%d\n", ans); }
int main() {
  into();
  work();
  outo();
  return 0;
}