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;
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while ((c < '0' || c > '9') && (c != '-')) c = getchar();
  if (c == '-') f = -1, c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x * f;
}
const int N = 1e5 + 10;
int n, m;
vector<pair<int, int>> e[N], Q[N];
int _tag;
inline int getpos(pair<int, int> v) {
  return v.first + (v.second > 0 ? -_tag : _tag);
}
struct cmp {
  bool operator()(pair<int, int> a, pair<int, int> b) {
    return getpos(a) < getpos(b);
  }
};
struct DS {
  int tag;
  set<pair<int, int>, cmp> val;
  set<pair<int, pair<int, int>>> cra;
  inline void ins_cra(pair<int, int> l, pair<int, int> r) {
    if (l.second < 0 && r.second > 0)
      cra.insert({(r.first - l.first + 1) / 2, l});
  }
  inline void era_cra(pair<int, int> l, pair<int, int> r) {
    if (l.second < 0 && r.second > 0)
      cra.erase({(r.first - l.first + 1) / 2, l});
  }
  inline void erase(pair<int, int> v) {
    auto it = val.find(v);
    auto pre = it, nxt = it;
    ++nxt;
    if (pre != val.begin()) {
      --pre;
      era_cra(*pre, *it);
      if (nxt != val.end()) ins_cra(*pre, *nxt);
    }
    if (nxt != val.end()) era_cra(*it, *nxt);
    val.erase(it);
  }
  inline void insert(pair<int, int> v) {
    if (v.second == 0) return;
    _tag = tag;
    auto it =
        val.find(make_pair(v.first + (v.second > 0 ? tag : -tag), v.second));
    if (it != val.end()) v.second += it->second, erase(*it);
    if (v.second == 0) return;
    v.first += (v.second > 0 ? tag : -tag);
    val.insert(v);
    it = val.upper_bound(v);
    auto nxt = it;
    --it;
    auto pre = it;
    if (pre != val.begin()) {
      --pre;
      ins_cra(*pre, *it);
      if (nxt != val.end()) era_cra(*pre, *nxt);
    }
    if (nxt != val.end()) ins_cra(*it, *nxt);
  }
  inline void Merge(DS &p) {
    if (((int)(val).size()) < ((int)(p.val).size())) {
      swap(tag, p.tag), swap(val, p.val), swap(cra, p.cra);
    }
    _tag = p.tag;
    vector<pair<int, int>> tmp;
    for (auto i : p.val) tmp.push_back({getpos(i), i.second});
    _tag = tag;
    for (auto i : tmp) insert(i);
  }
  inline void fix(pair<int, pair<int, int>> v) {
    auto it = val.find(v.second);
    pair<int, int> l = *it;
    ++it;
    pair<int, int> r = *it;
    erase(l), erase(r);
    if (l.second + r.second != 0) {
      if (l.second + r.second > 0)
        insert({getpos(r), l.second + r.second});
      else
        insert({getpos(l), l.second + r.second});
    }
  }
  inline void Move(int x) {
    _tag = tag;
    while (!cra.empty() && cra.begin()->first - tag <= x) fix(*cra.begin());
    tag += x;
  }
  inline int get(int pos) {
    _tag = tag;
    auto it = val.find({pos + tag, 1});
    if (it == val.end()) return 0;
    return it->second;
  }
  inline void Add(vector<pair<int, int>> v, int d) {
    _tag = tag;
    vector<pair<int, int>> tmp;
    for (auto i : v) {
      int a = get(i.first - 1), b = get(i.first), c = get(i.first + 1);
      tmp.push_back(
          {i.first, max(0, i.second - (max({a, a + b, a + b + c}) - a - b))});
    }
    Move(1);
    for (auto i : tmp) insert(i), insert({i.first + 1, -i.second});
    Move(d - 1);
  }
  inline long long getans() {
    _tag = tag;
    long long now = 0, ans = 0;
    for (auto i : val) now += i.second, ans = max(ans, now);
    return ans;
  }
} dp[N];
inline void dfs(int u, int fa, int fw) {
  for (auto v : e[u])
    if (v.first != fa) {
      dfs(v.first, u, v.second), dp[u].Merge(dp[v.first]);
    }
  dp[u].Add(Q[u], fw);
}
int main() {
  n = read();
  for (register int i = (1); i < (n); i++) {
    int x = read(), y = read(), z = read() << 1;
    e[x].emplace_back(y, z), e[y].emplace_back(x, z);
  }
  m = read();
  for (register int i = (1); i <= (m); i++) {
    int d = read() << 1, v = read(), u = read();
    Q[u].emplace_back(d, v);
  }
  dfs(1, 0, 1), printf("%lld\n", dp[1].getans());
}