#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());
}
