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>
const int maxn = 100010, maxk = 100010, inf = 1e9;
int n;
struct edge {
  int to, l;
  edge* next;
} E[maxn * 2], *ne = E, *fir[maxn];
struct item {
  int d, f;
  item* next;
} I[maxk], *fi[maxn];
void link(int u, int v, int l) {
  *ne = (edge){v, l, fir[u]};
  fir[u] = ne++;
}
int fa[maxn], dep[maxn], siz[maxn], son[maxn];
void init(int i) {
  siz[i] = 1;
  for (edge* e = fir[i]; e; e = e->next)
    if (e->to != fa[i]) {
      fa[e->to] = i;
      dep[e->to] = dep[i] + e->l;
      init(e->to);
      if (siz[e->to] > siz[son[i]]) son[i] = e->to;
      siz[i] += siz[e->to];
    }
}
void cmax(int& a, int b) { b > a ? a = b : 1; }
struct node {
  int l, r, v, ty, md, add;
  node *fa, *ch[2];
  int L(int x) { return ty & 1 ? l - x : l + x; }
  int R(int x) { return ty & 2 ? r - x : r + x; }
  int Lv(int x) { return L(x) * 2 + (ty & 1); }
  int Rv(int x) { return R(x) * 2 + (ty >> 1); }
  void pu() {
    md = ty == 1 ? l - r : -inf;
    if (ch[0]) cmax(md, ch[0]->md);
    if (ch[1]) cmax(md, ch[1]->md);
  }
  void pd() {
    if (!add) return;
    if (ch[0]) ch[0]->v += add, ch[0]->add += add;
    if (ch[1]) ch[1]->v += add, ch[1]->add += add;
    add = 0;
  }
  void chd(int i, int d, int x) {
    if ((ty >> i & 1) == d) return;
    ty ^= 1 << i;
    x *= d ? 1 : -1;
    i ? r += x : l += x;
  }
  void rot(node*& r) {
    node* f = fa;
    int c = this == f->ch[1];
    if (f->ch[c] = ch[!c]) ch[!c]->fa = f;
    ch[!c] = f;
    if (fa = f->fa) fa->ch[f == fa->ch[1]] = this;
    f->fa = this;
    f->pu();
    if (f == r) r = this;
  }
  void spl(node*& r) {
    for (; this != r; rot(r))
      if (fa != r)
        (this == fa->ch[1]) == (fa == fa->fa->ch[1]) ? fa->rot(r) : rot(r);
    pu();
  }
  node* fir(int c) { return pd(), ch[c] ? ch[c]->fir(c) : this; }
  node* next() {
    if (pd(), ch[1]) return ch[1]->fir(0);
    for (node* x = this; x; x = x->fa)
      if (x->fa && x == x->fa->ch[0]) return x->fa;
    return 0;
  }
  node* ins(int c) {
    node* x = new node;
    *x = *this;
    x->ch[!c] = 0;
    x->fa = this;
    if (ch[c]) ch[c]->fa = x;
    return ch[c] = x;
  }
  node* ub(int d, int x, bool t = 0) {
    pd();
    if (x < Lv(d)) return ch[0] && !t ? ch[0]->ub(d, x) : this;
    if (x < Rv(d)) return this;
    return ch[1]->ub(d, x);
  }
  node* maxd() {
    if (pd(), ty == 1 && l - r == md) return this;
    return ch[ch[1] && ch[1]->md == md]->maxd();
  }
  int maxv() {
    int x = v;
    pd();
    if (ch[0]) cmax(x, ch[0]->maxv());
    if (ch[1]) cmax(x, ch[1]->maxv());
    return x;
  }
};
void del(node*& f) {
  int d = f->l - f->r;
  node *l = f->ch[0], *r = f->ch[1];
  l->fa = r->fa = 0;
  l->fir(1)->spl(l);
  r->fir(0)->spl(r);
  l->ch[1] = r;
  r->fa = l;
  r->chd(0, l->v > r->v, d);
  r->pu();
  l->chd(1, l->v > r->v, d);
  l->pu();
  f = l;
}
void des(node* x) {
  if (x->ch[0]) des(x->ch[0]);
  if (x->ch[1]) des(x->ch[1]);
  delete x;
}
node* dfs(int i) {
  node* f;
  if (son[i])
    f = dfs(son[i]);
  else
    f = new node, *f = (node){-inf, inf, 0, 2, -inf, 0, 0, {0, 0}};
  int d = dep[i];
  for (edge* e = fir[i]; e; e = e->next)
    if (e->to != fa[i] && e->to != son[i]) {
      node* rt = dfs(e->to);
      bool t = 0;
      for (node* g = rt->fir(0); g; g = g->next())
        if (g->v) {
          int l = g->L(d), r = g->R(d), lv = g->Lv(d), rv = g->Rv(d);
          f->ub(d, lv, t)->spl(f);
          node *fl, *fr;
          if (f->Lv(d) < lv) {
            fl = f->ins(0);
            fl->r = f->l = l - d;
            fl->ty &= ~2;
            f->ty &= ~1;
          } else
            fl = f->ch[0]->fir(1), fl->spl(f->ch[0]);
          if (fl->v < f->v + g->v) fl->chd(1, 0, d * 2), f->chd(0, 0, d * 2);
          fl->spl(f);
          fl = f->ch[1]->ub(d, rv - 1);
          fl->spl(f->ch[1]);
          if (fl->Rv(d) > rv) {
            fr = fl->ins(1);
            fl->r = fr->l = r + d;
            fl->ty |= 2;
            fr->ty |= 1;
          } else
            fr = fl->ch[1]->fir(0), fr->spl(fl->ch[1]);
          fl->v += g->v;
          if (fl->ch[0]) fl->ch[0]->v += g->v, fl->ch[0]->add += g->v;
          if (fr->v < fl->v) fr->chd(0, 1, d * 2), fl->chd(1, 1, d * 2);
          fr->spl(f);
          t = 1;
        }
      des(rt);
    }
  for (item* it = fi[i]; it; it = it->next) {
    f->ub(d, it->d * 2 + 1)->spl(f);
    node* f0 = f->ins(0);
    node* f1 = f->ins(0);
    f0->r = f1->l = it->d + 1 - d;
    f1->r = f->l = it->d + d;
    f1->v += it->f;
    f0->ty &= ~2;
    f1->ty &= ~1;
    f1->ty |= 2;
    f->ty |= 1;
    f0->spl(f);
  }
  while (f->md >= dep[fa[i]] * 2) {
    f->maxd()->spl(f), del(f);
  }
  return f;
}
int main() {
  scanf("%d", &n);
  for (int i = 1, u, v, l; i < n; i++)
    scanf("%d%d%d", &u, &v, &l), link(u, v, l), link(v, u, l);
  int k;
  scanf("%d", &k);
  for (int i = 0, p; i < k; i++)
    scanf("%d%d%d", &I[i].d, &I[i].f, &p), I[i].next = fi[p], fi[p] = I + i;
  init(1);
  node* f = dfs(1);
  printf("%d\n", f->maxv());
}