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 RLEN = 1 << 18 | 1;
inline char nc() {
  static char ibuf[RLEN], *ib, *ob;
  (ib == ob) && (ob = (ib = ibuf) + fread(ibuf, 1, RLEN, stdin));
  return (ib == ob) ? -1 : *ib++;
}
inline int rd() {
  char ch = nc();
  int i = 0, f = 1;
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = nc();
  }
  while (isdigit(ch)) {
    i = (i << 1) + (i << 3) + ch - '0';
    ch = nc();
  }
  return i * f;
}
const int N = 1e5 + 50;
const int INF = 0x3f3f3f3f;
int n, q;
int det[N];
vector<pair<int, int> > edge[N];
vector<pair<int, int> > ask[N];
struct Myset {
  int id;
  struct data {
    int first, second;
    int id;
    data(int first, int second, int id)
        : first(first), second(second), id(id) {}
    friend inline bool operator<(const data &a, const data &b) {
      int posa = a.first + ((a.second > 0) ? -det[a.id] : det[a.id]),
          posb = b.first + ((b.second > 0) ? -det[b.id] : det[b.id]);
      if (posa != posb) return posa < posb;
      return a.second < b.second;
    }
  };
  inline set<data>::iterator prev(set<data>::iterator t) { return --t; }
  inline set<data>::iterator suff(set<data>::iterator t) { return ++t; }
  set<data> *s;
  set<pair<int, int> > *dis;
  inline int sgn(int x) { return (x > 0) ? 1 : 0; }
  Myset() {
    s = new set<data>;
    dis = new set<pair<int, int> >;
  }
  inline int getpos(set<data>::iterator t) {
    return t->first + ((t->second < 0) ? det[t->id] : -det[t->id]);
  }
  inline void del_dis(set<data>::iterator x, set<data>::iterator y) {
    if (sgn(x->second) || !sgn(y->second)) return;
    dis->erase(dis->find(pair<int, int>(y->first - x->first, y->first)));
  }
  inline void inc_dis(set<data>::iterator x, set<data>::iterator y) {
    if (sgn(x->second) || !sgn(y->second)) return;
    dis->insert(pair<int, int>(y->first - x->first, y->first));
  }
  inline void _erase(set<data>::iterator x) {
    if (x != s->begin()) del_dis(prev(x), x);
    if (x != --s->end()) del_dis(x, suff(x));
    if (x != s->begin() && x != --s->end()) inc_dis(prev(x), suff(x));
    s->erase(x);
  }
  inline void add(int pos, int d) {
    if (!d) return;
    set<data>::iterator nxt = s->lower_bound(data(pos - det[id], -INF, id));
    if (nxt == s->end() || getpos(nxt) != pos) {
      if (s->size() >= 2 && getpos(s->begin()) < pos &&
          getpos(--s->end()) > pos)
        del_dis(prev(nxt), nxt);
      data temp = data(pos + ((d < 0) ? -det[id] : det[id]), d, id);
      set<data>::iterator now = s->insert(temp).first;
      if (nxt != s->end()) inc_dis(now, nxt);
      if (now != s->begin()) inc_dis(prev(now), now);
    } else {
      data temp = *nxt;
      _erase(nxt);
      if (!(temp.second + d)) return;
      if (temp.second < 0 && temp.second + d > 0) temp.first += 2 * det[id];
      if (temp.second > 0 && temp.second + d < 0) temp.first -= 2 * det[id];
      temp.second += d;
      set<data>::iterator nxt = s->insert(temp).first;
      if (nxt != --s->end()) inc_dis(nxt, suff(nxt));
      if (nxt != s->begin()) inc_dis(prev(nxt), nxt);
      if (nxt != --s->end() && nxt != s->begin()) del_dis(prev(nxt), suff(nxt));
    }
  }
  inline void md(int pos, int d) {
    add(pos, d);
    add(pos + 1, -d);
  }
  inline void mv(int d) {
    if (!d) return;
    while (dis->size() && dis->begin()->first <= (d + det[id]) * 2) {
      set<data>::iterator nxt =
          s->lower_bound(data(dis->begin()->second - 2 * det[id], -INF, id));
      if (nxt->second == -prev(nxt)->second)
        _erase(prev(nxt)), _erase(nxt);
      else if (nxt->second > -prev(nxt)->second) {
        int val = prev(nxt)->second;
        _erase(prev(nxt));
        add(nxt->first - det[id], val);
      } else {
        int val = nxt->second;
        nxt = prev(nxt);
        _erase(suff(nxt));
        add(nxt->first + det[id], val);
      }
    }
    det[id] += d;
  }
  inline void merge(Myset &b) {
    if (s->size() < b.s->size()) swap(s, b.s), swap(id, b.id), swap(dis, b.dis);
    for (set<data>::iterator v = b.s->begin(); v != b.s->end(); ++v) {
      data temp = *v;
      temp.first += (v->second < 0) ? det[b.id] : -det[b.id];
      add(temp.first, temp.second);
    }
    delete b.s;
    delete b.dis;
  }
  inline int getval(int pos) {
    set<data>::iterator nxt = s->lower_bound(data(pos - det[id], -INF, id));
    if (nxt != s->end() && getpos(nxt) == pos) return nxt->second;
    return 0;
  }
} s[N];
inline void dfs(int x, int f) {
  for (auto v : edge[x]) {
    if (v.first == f) continue;
    dfs(v.first, x);
    for (auto &d : ask[v.first]) {
      int delta = max(
          0, max(-s[v.first].getval(d.first), s[v.first].getval(d.first + 1)));
      d.second = max(0, d.second - delta);
    }
    s[v.first].mv(1);
    for (auto d : ask[v.first]) s[v.first].md(d.first, d.second);
    s[v.first].mv(v.second - 1);
    s[x].merge(s[v.first]);
  }
}
int main() {
  n = rd();
  for (int i = 1; i <= n; i++) s[i].id = i;
  for (int i = 1; i < n; i++) {
    int x = rd(), y = rd(), w = rd() * 2;
    edge[x].push_back(pair<int, int>(y, w));
    edge[y].push_back(pair<int, int>(x, w));
  }
  edge[0].push_back(pair<int, int>(1, 2));
  q = rd();
  for (int i = 1; i <= q; i++) {
    int d = 2 * rd(), f = rd(), p = rd();
    ask[p].push_back(pair<int, int>(d, f));
  }
  dfs(0, 0);
  if (!s[0].s) {
    puts("0");
    return 0;
  }
  int sum = 0, mx = 0;
  for (auto v = s[0].s->begin(); v != s[0].s->end(); ++v) {
    sum += v->second;
    mx = max(mx, sum);
  }
  cout << mx << '\n';
}