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 N = 1e5 + 10;
int n, m;
int tot, fi[N], a[N << 1], ne[N << 1], c[N << 1];
vector<pair<int, int> > g[N];
struct Node {
  int pos, df, *delta;
  inline int TruePos() const { return pos + (df >= 0 ? -*delta : *delta); }
  inline void Merge(const Node &v) {
    assert(delta == v.delta);
    if (bool(df >= 0) != bool(df + v.df >= 0)) pos = v.pos;
    df += v.df;
  }
  inline friend bool operator<(const Node &u, const Node &v) {
    return u.TruePos() < v.TruePos();
  }
};
int *all[N];
set<Node> st[N];
struct Adj {
  int dis;
  set<Node>::iterator it;
  inline friend bool operator<(const Adj &u, const Adj &v) {
    return u.dis < v.dis ||
           (u.dis == v.dis && u.it->TruePos() < v.it->TruePos());
  }
};
multiset<Adj> diff[N];
inline void Add(int x, int y, int z) {
  a[++tot] = y;
  ne[tot] = fi[x];
  fi[x] = tot;
  c[tot] = z;
}
inline void AddDiff(int x, set<Node>::iterator it) {
  if (prev(it)->df < 0 && next(it)->df >= 0)
    diff[x].erase(diff[x].find((Adj){next(it)->pos - prev(it)->pos, prev(it)}));
  if (prev(it)->df < 0 && it->df >= 0)
    diff[x].insert((Adj){it->pos - prev(it)->pos, prev(it)});
  if (it->df < 0 && next(it)->df >= 0)
    diff[x].insert((Adj){next(it)->pos - it->pos, it});
}
inline void RemoveDiff(int x, set<Node>::iterator it) {
  if (prev(it)->df < 0 && it->df >= 0)
    diff[x].erase(diff[x].find((Adj){it->pos - prev(it)->pos, prev(it)}));
  if (it->df < 0 && next(it)->df >= 0)
    diff[x].erase(diff[x].find((Adj){next(it)->pos - it->pos, it}));
  if (prev(it)->df < 0 && next(it)->df >= 0)
    diff[x].insert((Adj){next(it)->pos - prev(it)->pos, prev(it)});
  st[x].erase(it);
}
inline void Insert(int x, int pos, int df) {
  Node np({pos + (df >= 0 ? *all[x] : -*all[x]), df, all[x]});
  auto nxt = st[x].lower_bound(np);
  if (nxt->TruePos() == np.TruePos()) {
    np.Merge(*nxt);
    RemoveDiff(x, nxt);
  }
  AddDiff(x, st[x].insert(np).first);
}
inline void Advance(int x, int l) {
  int nall = (*all[x] + l) * 2;
  while (!diff[x].empty() && diff[x].begin()->dis <= nall) {
    auto u = diff[x].begin()->it, v = next(u);
    Node nd(*u);
    nd.Merge(*v);
    RemoveDiff(x, u);
    RemoveDiff(x, v);
    AddDiff(x, st[x].insert(nd).first);
  }
  *all[x] += l;
}
inline int GetIncrease(int x, int tpos) {
  Node np({tpos + *all[x], 0, all[x]});
  set<Node>::iterator it = st[x].lower_bound(np);
  int ans = 0;
  if (it->TruePos() == tpos) {
    if (it->df < 0) ans = max(ans, -it->df);
    ++it;
  }
  if (it->TruePos() == tpos + 1) {
    if (it->df > 0) ans = max(ans, it->df);
  }
  return ans;
}
inline void Dfs(int x, int fa, int l) {
  all[x] = new int(0);
  st[x].insert((Node){(int)-2e9, 0, all[x]});
  st[x].insert((Node){(int)2e9, -1, all[x]});
  for (int i = fi[x]; i; i = ne[i])
    if (a[i] != fa) {
      Dfs(a[i], x, c[i]);
      if (st[x].size() < st[a[i]].size()) {
        st[x].swap(st[a[i]]);
        diff[x].swap(diff[a[i]]);
        swap(all[x], all[a[i]]);
      }
      for (__typeof(++st[a[i]].begin()) it = ++st[a[i]].begin(),
                                        it_end = --st[a[i]].end();
           it != it_end; ++it)
        Insert(x, it->TruePos(), it->df);
    }
  for (__typeof(g[x].begin()) it = g[x].begin(), it_end = g[x].end();
       it != it_end; ++it) {
    int tmp = GetIncrease(x, it->first);
    it->second = max(0, it->second - tmp);
  }
  Advance(x, 1);
  for (__typeof(g[x].begin()) it = g[x].begin(), it_end = g[x].end();
       it != it_end; ++it)
    if (it->second) {
      Insert(x, it->first, it->second);
      Insert(x, it->first + 1, -it->second);
    }
  Advance(x, l - 1);
}
int main() {
  scanf("%d", &n);
  for (int i = 1, x, y, z; i < n; ++i) {
    scanf("%d%d%d", &x, &y, &z);
    z <<= 1;
    Add(x, y, z);
    Add(y, x, z);
  }
  scanf("%d", &m);
  for (int i = 1, day, fish, pos; i <= m; ++i) {
    scanf("%d%d%d", &day, &fish, &pos);
    g[pos].push_back(pair<int, int>(day << 1, fish));
  }
  Dfs(1, 0, 1);
  int ans = 0, cur = 0;
  for (__typeof(++st[1].begin()) it = ++st[1].begin(), it_end = --st[1].end();
       it != it_end; ++it)
    ans = max(ans, cur += it->df);
  printf("%d\n", ans);
  return 0;
}