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