#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';
}
