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 long long mod = 998244353;
const long long N = 2e5 + 100;
struct edge {
  long long to;
  long long cost;
  edge(long long to_ = 0, long long cost_ = 0) : to(to_), cost(cost_) {}
};
vector<edge> vec[N];
vector<pair<long long, long long> > up[N];
vector<pair<long long, long long> > down[N];
vector<long long> vt[N];
long long dep[N];
long long nd[N], back[N], pos[N], cmb[N], par[N], len[N];
pair<pair<long long, long long>, pair<long long, long long> > now[N];
long long now_sz = 0;
void dfs(long long v = 0, long long p = -1, long long d = 0) {
  dep[v] = d;
  nd[v] = 1;
  for (auto e : vec[v]) {
    if (e.to != p) {
      dfs(e.to, v, d + e.cost);
      nd[v] += nd[e.to];
    }
  }
}
void heavy_light(long long v = 0, long long p = -1, long long b = -1) {
  vt[now_sz].push_back(v);
  par[now_sz] = b;
  back[v] = b;
  pos[v] = len[now_sz]++;
  cmb[v] = now_sz;
  bool fl = 0;
  for (auto e : vec[v]) {
    if (e.to != p && nd[e.to] * 2 >= nd[v]) {
      heavy_light(e.to, v, b);
      fl = 1;
      break;
    }
  }
  if (!fl) {
    now_sz++;
  }
  for (auto e : vec[v]) {
    if (e.to != p && nd[e.to] * 2 < nd[v]) {
      heavy_light(e.to, v, v);
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  for (long long i = 0; i < n - 1; i++) {
    long long a, b;
    long long w;
    cin >> a >> b >> w;
    a--;
    b--;
    w *= n;
    w--;
    vec[a].push_back(edge(b, w));
    vec[b].push_back(edge(a, w));
  }
  dfs();
  heavy_light();
  long long m;
  cin >> m;
  long long all = 0;
  for (long long i = 0; i < m; i++) {
    long long t;
    long long f, v;
    cin >> t >> f >> v;
    t *= n;
    v--;
    up[v].push_back(make_pair(t + dep[v], f));
    down[v].push_back(make_pair(t - dep[v] - 1, f));
    all += f;
  }
  long long ret = 0;
  for (long long t = now_sz - 1; t >= 0; t--) {
    long long sz = 0;
    for (long long i = 0; i < (long long)vt[t].size(); i++) {
      long long v = vt[t][i];
      for (long long j = 0; j < (long long)up[v].size(); j++) {
        pair<long long, long long> p = up[v][j];
        now[sz++] = make_pair(make_pair(p.first, -1),
                              make_pair(p.first - 2 * dep[v], p.second));
      }
      for (long long j = 0; j < (long long)down[v].size(); j++) {
        pair<long long, long long> p = down[v][j];
        now[sz++] = make_pair(make_pair(p.first + 2 * dep[v], 1), p);
      }
    }
    multiset<pair<long long, long long> > st;
    multiset<pair<long long, long long> >::iterator it;
    sort(now, now + sz);
    for (long long i = sz - 1; i >= 0; i--) {
      if (now[i].first.second == -1) {
        pair<long long, long long> q = now[i].second;
        while (q.second > 0) {
          it = st.lower_bound(make_pair(q.first, -1));
          if (it != st.end()) {
            pair<long long, long long> p = *it;
            long long df = now[i].first.first - p.first;
            if (t == 0 || df >= 2 * dep[par[t]]) {
              st.erase(it);
              long long c = min(q.second, p.second);
              ret += c;
              q.second -= c;
              p.second -= c;
              if (p.second > 0) {
                st.insert(p);
              }
            } else {
              break;
            }
          } else {
            break;
          }
        }
        if (q.second > 0 && t > 0) {
          up[par[t]].push_back(make_pair(now[i].first.first, q.second));
        }
      } else {
        st.insert(now[i].second);
      }
    }
    if (t > 0) {
      for (it = st.begin(); it != st.end(); it++) {
        down[par[t]].push_back(*it);
      }
      st.clear();
    }
  }
  cout << all - ret;
  return 0;
}