#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
using ll = long long;
using pii = pair<int, int>;
vector<pii> v[N], f[N];
int n, m, cur, dep[N];
struct Node {
  int x, d, v;
  Node(int x, int d, int v, int t = 0) : x(x - d * t), d(d), v(v) {}
};
inline bool operator<(const Node &a, const Node &b) {
  int p = a.x + cur * a.d, q = b.x + cur * b.d;
  return p == q ? a.d < b.d : p < q;
}
struct Collision {
  Node x, y;
  int t;
  Collision(Node x, Node y) : x(x), y(y), t((y.x - x.x) >> 1) {}
};
inline bool operator<(const Collision &a, const Collision &b) {
  return a.t != b.t ? a.t < b.t
                    : make_tuple(a.x.x, a.x.v, a.y.x, a.y.v) <
                          make_tuple(b.x.x, b.x.v, b.y.x, b.y.v);
}
struct Info {
  set<Collision> c;
  set<Node> nd;
  inline void insc(Node x, Node y) {
    if (x.d > 0 && y.d < 0) c.insert(Collision(x, y));
  }
  inline void erasec(Node x, Node y) {
    if (x.d > 0 && y.d < 0) c.erase(Collision(x, y));
  }
  void ins(Node x) {
    if (!x.v) return;
    if (nd.count(x)) x.v += nd.find(x)->v, erase(*nd.find(x));
    auto it = nd.insert(x).first, nxt = it;
    ++nxt;
    if (it != nd.begin()) {
      auto pre = it;
      --pre;
      if (nxt != nd.end()) erasec(*pre, *nxt);
      insc(*pre, x);
    }
    if (nxt != nd.end()) insc(x, *nxt);
  }
  void erase(Node x) {
    auto it = nd.find(x), nxt = it;
    ++nxt;
    if (nxt != nd.end()) erasec(x, *nxt);
    if (it != nd.begin()) {
      auto pre = it;
      --pre;
      erasec(*pre, x);
      if (nxt != nd.end()) insc(*pre, *nxt);
    }
    nd.erase(it);
  }
  int reset(int x, int y) {
    Node l(x + 1, -1, y, cur), r(x - 1, 1, y, cur);
    return max(0, y - max(nd.find(l) == nd.end() ? 0 : nd.find(l)->v,
                          nd.find(r) == nd.end() ? 0 : nd.find(r)->v));
  }
  Node cancel(Node x, Node y) {
    if (x.v > y.v)
      return Node(x.x, x.d, x.v - y.v);
    else
      return Node(y.x, y.d, y.v - x.v);
  }
  inline void collide(Collision x) {
    erase(x.x);
    erase(x.y);
    ins(cancel(x.x, x.y));
  }
  void maintain(int x) {
    while (!c.empty() && c.begin()->t <= x) collide(*c.begin());
  }
  void merge(Info &b) {
    if (nd.size() < b.nd.size()) swap(nd, b.nd), swap(c, b.c);
    for (auto &i : b.nd) ins(i);
  }
  int query() {
    int ret = 0;
    for (auto &i : nd)
      if (i.d > 0) ret += i.v;
    return ret;
  }
} info[N];
void dfs(int pos, int fa) {
  for (auto &i : v[pos]) {
    int vv = i.first, ww = i.second;
    if (vv == fa) continue;
    dep[vv] = dep[pos] + ww;
    dfs(vv, pos);
  }
}
void solve(int pos, int fa) {
  for (auto &i : v[pos]) {
    int vv = i.first;
    if (vv == fa) continue;
    solve(vv, pos);
    cur = -dep[vv];
    info[vv].maintain(-(dep[pos] + 1));
    cur = -(dep[pos] + 1);
    info[pos].merge(info[vv]);
  }
  cur = -(dep[pos] + 1);
  for (auto &i : f[pos]) i.second = info[pos].reset(i.first, i.second);
  info[pos].maintain(-dep[pos]);
  cur = -dep[pos];
  for (auto &i : f[pos])
    info[pos].ins(Node(i.first, -1, i.second, cur)),
        info[pos].ins(Node(i.first, 1, i.second, cur));
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int t1, t2, t3;
    cin >> t1 >> t2 >> t3;
    t3 <<= 1;
    v[t1].push_back({t2, t3});
    v[t2].push_back({t1, t3});
  }
  cin >> m;
  for (int i = 1; i <= m; i++) {
    int d, v, w;
    cin >> d >> v >> w;
    d <<= 1;
    f[w].push_back({d, v});
  }
  dfs(1, 0);
  solve(1, 0);
  info[1].maintain(INT_MAX);
  cout << info[1].query() << endl;
  return 0;
}
