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>
#include <bits/stdc++.h>
using namespace std;
const int N = 100003;
int rd() {
  int ch = getchar(), x = 0;
  for (; ch < '0' || ch > '9'; ch = getchar())
    ;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  return x;
}
template <typename T>
bool chmax(T &a, const T &b) {
  if (a < b) return a = b, 1;
  return 0;
}
int n;
vector<pair<int, int> > G[N], V[N];
struct DS {
  map<int, int> ps, ng;
  int tag;
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      pq;
  void reb(int x, bool op) {
    if (op) {
      auto it = ng.upper_bound(x - (tag << 1));
      if (it == ng.begin()) return;
      --it;
      pq.emplace(x - it->first, x);
    } else {
      auto it = ps.lower_bound(x + (tag << 1));
      if (it == ps.end()) return;
      pq.emplace(it->first - x, it->first);
    }
  }
  void ins(int x, int val) {
    if (val > 0) {
      ps[x + tag] += val;
      reb(x + tag, true);
    } else {
      ng[x - tag] += val;
      reb(x - tag, false);
    }
  }
  int get() const {
    int res = 0, now = 0;
    auto i = ps.begin(), j = ng.begin();
    while (i != ps.end() && j != ng.end()) {
      if (i->first - j->first >= (tag << 1)) {
        now += j->second;
        ++j;
      } else {
        now += i->second;
        ++i;
      }
      chmax(res, now);
    }
    return res;
  }
  void work(int l) {
    while (!pq.empty()) {
      pair<int, int> _ = pq.top();
      if (_.first > (tag + l << 1)) break;
      pq.pop();
      int x = _.second, y = x - _.first;
      auto i = ps.find(x), j = ng.find(y);
      if (i == ps.end() || j == ng.end()) continue;
      if (i->second + j->second < 0) {
        j->second += i->second;
        ps.erase(i);
        reb(j->first, false);
      } else {
        i->second += j->second;
        ng.erase(j);
        reb(i->first, true);
      }
    }
    tag += l;
  }
  size_t size() const { return ps.size() + ng.size(); }
  int qry(int p) const {
    auto i = ps.find(p + tag), j = ng.find(p - tag);
    return (i == ps.end() ? 0 : i->second) + (j == ng.end() ? 0 : j->second);
  }
  void operator+=(const DS &o) {
    for (pair<int, int> i : o.ps) ins(i.first - o.tag, i.second);
    for (pair<int, int> i : o.ng) ins(i.first + o.tag, i.second);
  }
} S[N];
void dfs(int x, int fa) {
  for (pair<int, int> _ : G[x])
    if (_.first != fa) {
      int v = _.first, len = _.second;
      dfs(v, x);
      for (pair<int, int> &i : V[v])
        i.second -= max(0, max(-S[v].qry(i.first), S[v].qry(i.first + 1)));
      S[v].work(1);
      for (pair<int, int> i : V[v])
        if (i.second > 0) {
          S[v].ins(i.first, i.second);
          S[v].ins(i.first + 1, -i.second);
        }
      S[v].work(len - 1);
      if (S[x].size() < S[v].size()) swap(S[x], S[v]);
      S[x] += S[v];
    }
}
int main() {
  n = rd();
  for (int i = 1; i < n; ++i) {
    int u = rd(), v = rd(), l = rd() << 1;
    G[u].emplace_back(v, l);
    G[v].emplace_back(u, l);
  }
  int m = rd();
  G[0].emplace_back(1, 2);
  while (m--) {
    int d = rd() << 1, f = rd(), p = rd();
    V[p].emplace_back(d, f);
  }
  dfs(0, 0);
  printf("%d\n", S[0].get());
}
