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 Imx = 2147483647;
const long long Lbig = 2e18;
const int mod = 1e9 + 7;
struct fastio {
  char s[100000];
  int it, len;
  fastio() { it = len = 0; }
  inline char get() {
    if (it < len) return s[it++];
    it = 0;
    len = fread(s, 1, 100000, stdin);
    if (len == 0)
      return EOF;
    else
      return s[it++];
  }
  bool notend() {
    char c = get();
    while (c == ' ' || c == '\n') c = get();
    if (it > 0) it--;
    return c != EOF;
  }
} _buff;
inline long long getnum() {
  long long r = 0;
  bool ng = 0;
  char c;
  c = _buff.get();
  while (c != '-' && (c < '0' || c > '9')) c = _buff.get();
  if (c == '-') ng = 1, c = _buff.get();
  while (c >= '0' && c <= '9') r = r * 10 + c - '0', c = _buff.get();
  return ng ? -r : r;
}
template <class T>
inline void putnum(T x) {
  if (x < 0) putchar('-'), x = -x;
  register short a[20] = {}, sz = 0;
  while (x) a[sz++] = x % 10, x /= 10;
  if (sz == 0) putchar('0');
  for (int i = sz - 1; i >= 0; i--) putchar('0' + a[i]);
}
inline char getreal() {
  char c = _buff.get();
  while (c <= 32) c = _buff.get();
  return c;
}
long long qpow(long long x, long long k) {
  return k == 0 ? 1
                : 1ll * qpow(1ll * x * x % mod, k >> 1) * (k & 1 ? x : 1) % mod;
}
const int maxn = 100111;
int CURT;
struct Function {
  int T;
  void UPDT() { CURT = T; }
  struct element {
    int x, v;
    element(int X = 0, int V = 0) {
      x = X;
      v = V;
    }
    inline int getT() const { return v > 0 ? x - CURT : x + CURT; }
    bool operator<(const element &t) const {
      if (getT() != t.getT()) return getT() < t.getT();
      return v < t.v;
    }
  };
  int get_element_T(const element &t) {
    UPDT();
    return t.getT();
  }
  unordered_map<int, int> M[2];
  set<element> all;
  set<pair<int, pair<int, int> > > st;
  void debug(int id) {
    UPDT();
    if (0) cout << "Debug " << id << " T=" << T << endl;
    for (set<element>::iterator it = all.begin(); it != all.end(); it++)
      if (0) cout << it->getT() << "," << it->v << " ";
    if (0) cout << endl;
    for (auto it : M[0])
      if (0) cout << it.first << "," << it.second << " ";
    if (0) cout << endl;
    for (auto it : M[1])
      if (0) cout << it.first << "," << it.second << " ";
    if (0) cout << endl;
  }
  void add_relation(int x, int y) {
    int t = (y - x + 1) / 2;
    assert(t > 0);
    st.insert(make_pair(t, make_pair(x, y)));
  }
  void all_insert(element x) {
    if (x.v == 0) return;
    UPDT();
    all.insert(x);
    set<element>::iterator it = all.find(x);
    if (x.v > 0 && it != all.begin()) {
      it--;
      if (it->v < 0) add_relation(it->x, x.x);
    } else if (x.v < 0) {
      it++;
      if (it != all.end() && it->v > 0) add_relation(x.x, it->x);
    }
  }
  void all_del(element x) {
    if (x.v == 0) return;
    UPDT();
    set<element>::iterator it = all.find(x), it0 = it, it1 = it0;
    assert(it != all.end());
    it1++;
    if (it0 != all.begin() && it1 != all.end()) {
      it0--;
      if (it0->v < 0 && it1->v > 0) add_relation(it0->x, it1->x);
    }
    all.erase(x);
  }
  void add(int t, int p, int v) {
    if (v == 0) return;
    int cur = 0;
    if (M[t].find(p) != M[t].end()) all_del(element(p, M[t][p])), cur = M[t][p];
    M[t][p] = cur + v;
    all_insert(element(p, M[t][p]));
  }
  void Add(int x, int v) {
    if (v == 0) return;
    int t = v > 0, p, q;
    if (t)
      p = x + T, q = x - T;
    else
      p = x - T, q = x + T;
    int qval = ((M[t ^ 1]).find(q) == (M[t ^ 1]).end() ? 0 : M[t ^ 1][q]);
    if (qval) {
      if (abs(qval) >= abs(v))
        add(t ^ 1, q, v), v = 0;
      else
        add(t ^ 1, q, -qval), v += qval;
    }
    add(t, p, v);
    assert(
        (((M[t]).find(p) == (M[t]).end() ? 0 : M[t][p]) != 0) +
            (((M[t ^ 1]).find(q) == (M[t ^ 1]).end() ? 0 : M[t ^ 1][q]) != 0) <=
        1);
  }
  void merge(int x, int y) {
    if (M[0].find(x) != M[0].end() && M[1].find(y) != M[1].end()) {
      int dlt = min(-M[0][x], M[1][y]);
      assert(dlt >= 0);
      add(0, x, dlt);
      add(1, y, -dlt);
    }
  }
  void go(int dt) {
    int nT = T + dt;
    while (st.size() > 0 && st.begin()->first <= nT) {
      merge(st.begin()->second.first, st.begin()->second.second);
      st.erase(st.begin());
    }
    T = nT;
  }
  int getmx() {
    UPDT();
    int v = 0, mx = 0;
    for (set<element>::iterator it = all.begin(); it != all.end(); it++) {
      v += it->v;
      mx = max(mx, v);
    }
    return mx;
  }
  int getdlt(int x) {
    return ((M[0]).find(x - T) == (M[0]).end() ? 0 : M[0][x - T]) +
           ((M[1]).find(x + T) == (M[1]).end() ? 0 : M[1][x + T]);
  }
  int getndlt(int x, int f) {
    int d0 = getdlt(x);
    int d1 = getdlt(x + 1);
    return max(0, f - max(0, max(0 - d0, d1)));
  }
} yxg[maxn * 2];
int tot;
int Merge(int x, int y) {
  if (yxg[x].all.size() > yxg[y].all.size()) return Merge(y, x);
  for (set<Function::element>::iterator it = yxg[x].all.begin();
       it != yxg[x].all.end(); it++) {
    yxg[y].Add(yxg[x].get_element_T(*it), it->v);
  }
  return y;
}
int n, m;
vector<pair<int, int> > con[maxn];
vector<pair<int, int> > v[maxn];
int id[maxn];
void dfs(int x, int pre = -1) {
  id[x] = 0;
  for (int i = 0; i < con[x].size(); i++) {
    int u = con[x][i].first;
    if (u == pre) continue;
    dfs(u, x);
    yxg[id[u]].go(con[x][i].second * 2 - 1);
    if (id[x] == 0)
      id[x] = id[u];
    else
      id[x] = Merge(id[x], id[u]);
  }
  if (id[x] == 0) id[x] = ++tot;
  if (x != 1) {
    vector<int> V;
    for (int i = 0; i < v[x].size(); i++) {
      int d = v[x][i].first;
      int f = v[x][i].second;
      V.push_back(yxg[id[x]].getndlt(d * 2, f));
    }
    yxg[id[x]].go(1);
    for (int i = 0; i < v[x].size(); i++) {
      int d = v[x][i].first;
      int f = v[x][i].second;
      yxg[id[x]].Add(d * 2, V[i]);
      yxg[id[x]].Add(d * 2 + 1, -V[i]);
    }
  } else {
    for (int i = 0; i < v[x].size(); i++) {
      int d = v[x][i].first;
      int f = v[x][i].second;
      yxg[id[x]].Add(d * 2, f);
      yxg[id[x]].Add(d * 2 + 1, -f);
    }
  }
}
int main() {
  n = getnum();
  for (int i = 1; i < n; i++) {
    int x, y, d;
    x = getnum(), y = getnum(), d = getnum();
    con[x].push_back(make_pair(y, d));
    con[y].push_back(make_pair(x, d));
  }
  m = getnum();
  for (int i = 1; i <= m; i++) {
    int d, f, p;
    d = getnum(), f = getnum(), p = getnum();
    v[p].push_back(make_pair(d, f));
  }
  dfs(1);
  int ans = yxg[id[1]].getmx();
  cout << ans << endl;
  return 0;
}