#include <bits/stdc++.h>
using namespace std;
const int inf = 2147483647;
int n, m, d[100010], now;
struct node {
  int first, d, v;
  bool operator<(const node &second) const {
    int a = first + now * d;
    int b = second.first + now * second.d;
    if (a == b) {
      return d < second.d;
    } else {
      return a < b;
    }
  }
};
struct col {
  node first, second;
  int ti;
  col(node a, node b) {
    first = a;
    second = b;
    ti = (second.first - first.first) / 2;
  }
  bool operator<(const col &a) const {
    if (ti != a.ti) {
      return ti < a.ti;
    }
    if (first.first != a.first.first) {
      return first.first < a.first.first;
    }
    if (first.v != a.first.v) {
      return first.v < a.first.v;
    }
    if (second.first != a.second.first) {
      return second.first < a.second.first;
    }
    return second.v < a.second.v;
  }
};
struct yxg {
  set<node> sn;
  set<col> sc;
  void insc(node first, node second) {
    if (first.d > 0 && second.d < 0) {
      sc.insert(col(first, second));
    }
  }
  void delc(node first, node second) {
    if (first.d > 0 && second.d < 0) {
      sc.erase(col(first, second));
    }
  }
  void del(node first) {
    set<node>::iterator it, nxt, pre;
    it = sn.insert(first).first;
    nxt = it;
    nxt++;
    pre = it;
    pre--;
    if (nxt != sn.end()) {
      delc(*it, *nxt);
    }
    if (it != sn.begin()) {
      delc(*pre, *it);
      if (nxt != sn.end()) {
        insc(*pre, *nxt);
      }
    }
    sn.erase(it);
  }
  void ins(node first) {
    if (!first.v) {
      return;
    }
    if (sn.find(first) != sn.end()) {
      first.v += sn.find(first)->v;
      del(*sn.find(first));
    }
    set<node>::iterator it, nxt, pre;
    it = sn.insert(first).first;
    nxt = it;
    nxt++;
    pre = it;
    pre--;
    if (it != sn.begin()) {
      if (nxt != sn.end()) {
        delc(*pre, *nxt);
      }
      insc(*pre, *it);
    }
    if (nxt != sn.end()) {
      insc(*it, *nxt);
    }
  }
  int reset(int first, int second) {
    node l, r;
    l = (node){first + 1 + now, -1, second};
    r = (node){first - 1 - now, 1, second};
    int a, b;
    if (sn.find(l) != sn.end()) {
      a = sn.find(l)->v;
    } else {
      a = 0;
    }
    if (sn.find(r) != sn.end()) {
      b = sn.find(r)->v;
    } else {
      b = 0;
    }
    return max(0, second - max(a, b));
  }
  node cancel(node first, node second) {
    if (first.v > second.v) {
      return (node){first.first, first.d, first.v - second.v};
    } else {
      return (node){second.first, second.d, second.v - first.v};
    }
  }
  void Col(col first) {
    del(first.first);
    del(first.second);
    ins(cancel(first.first, first.second));
  }
  void maintain(int first) {
    while (!sc.empty() && sc.begin()->ti <= first) {
      Col(*sc.begin());
    }
  }
  int ask() {
    int res = 0;
    for (set<node>::iterator it = sn.begin(); it != sn.end(); it++) {
      if ((*it).d > 0) {
        res += (*it).v;
      }
    }
    return res;
  }
} a[100010];
void merge(yxg &a, yxg &b) {
  if (a.sn.size() < b.sn.size()) {
    swap(a.sn, b.sn);
    swap(a.sc, b.sc);
  }
  for (set<node>::iterator it = b.sn.begin(); it != b.sn.end(); it++) {
    a.ins(*it);
  }
}
vector<pair<int, int> > v[100010], fish[100010];
void dfs(int first, int fa) {
  for (int i = 0; i < v[first].size(); i++) {
    int second = v[first][i].first;
    if (second == fa) {
      continue;
    }
    d[second] = d[first] + v[first][i].second;
    dfs(second, first);
  }
}
void solve(int first, int fa) {
  for (int i = 0; i < v[first].size(); i++) {
    int second = v[first][i].first;
    if (second == fa) {
      continue;
    }
    solve(second, first);
    now = -d[second];
    a[second].maintain(-(d[first] + 1));
    now = -(d[first] + 1);
    merge(a[first], a[second]);
  }
  now = -(d[first] + 1);
  for (int i = 0; i < fish[first].size(); i++) {
    fish[first][i].second =
        a[first].reset(fish[first][i].first, fish[first][i].second);
  }
  a[first].maintain(-d[first]);
  now = -d[first];
  for (int i = 0; i < fish[first].size(); i++) {
    a[first].ins((node){fish[first][i].first + now, -1, fish[first][i].second});
    a[first].ins((node){fish[first][i].first - now, 1, fish[first][i].second});
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int first, second, w;
    scanf("%d%d%d", &first, &second, &w);
    w *= 2;
    v[first].push_back(make_pair(second, w));
    v[second].push_back(make_pair(first, w));
  }
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int d, f, p;
    scanf("%d%d%d", &d, &f, &p);
    d *= 2;
    fish[p].push_back(make_pair(d, f));
  }
  dfs(1, 0);
  solve(1, 0);
  a[1].maintain(inf);
  printf("%d\n", a[1].ask());
  return 0;
}
