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>
#include <bits/stdc++.h>
using namespace std;
const long long 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 long long rd() {
  char ch = nc();
  long long 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 long long N = 1e5 + 50;
const long long INF = 0x3f3f3f3f3f3f3f3f;
long long n, q;
long long det[N];
vector<pair<long long, long long> > edge[N];
vector<pair<long long, long long> > ask[N];
struct Myset {
  long long id;
  struct data {
    long long first, second;
    long long id;
    data(long long first, long long second, long long id)
        : first(first), second(second), id(id) {}
    friend inline bool operator<(const data &a, const data &b) {
      long long 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<long long, long long> > *dis;
  inline long long sgn(long long x) { return (x > 0) ? 1 : 0; }
  Myset() {
    s = new set<data>;
    dis = new set<pair<long long, long long> >;
  }
  inline long long 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<long long, long long>(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<long long, long long>(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(long long pos, long long 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(long long pos, long long d) {
    add(pos, d);
    add(pos + 1, -d);
  }
  inline void mv(long long 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) {
        long long val = prev(nxt)->second;
        _erase(prev(nxt));
        add(nxt->first - det[id], val);
      } else {
        long long 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 long long getval(long long 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(long long x, long long f) {
  for (auto v : edge[x]) {
    if (v.first == f) continue;
    dfs(v.first, x);
    for (auto &d : ask[v.first]) {
      long long delta = max(0ll, max(-s[v.first].getval(d.first),
                                     s[v.first].getval(d.first + 1)));
      d.second = max(0ll, 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]);
  }
}
signed main() {
  n = rd();
  for (long long i = 1; i <= n; i++) s[i].id = i;
  for (long long i = 1; i < n; i++) {
    long long x = rd(), y = rd(), w = rd() * 2;
    edge[x].push_back(pair<long long, long long>(y, w));
    edge[y].push_back(pair<long long, long long>(x, w));
  }
  edge[0].push_back(pair<long long, long long>(1, 2));
  q = rd();
  for (long long i = 1; i <= q; i++) {
    long long d = 2 * rd(), f = rd(), p = rd();
    ask[p].push_back(pair<long long, long long>(d, f));
  }
  dfs(0, 0);
  if (!s[0].s) {
    puts("0");
    return 0;
  }
  long long 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';
}
