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 char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline long long read() {
  long long x = 0;
  char ch = getchar();
  bool positive = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') positive = 0;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return positive ? x : -x;
}
inline void write(long long a) {
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  if (a >= 10) write(a / 10);
  putchar('0' + a % 10);
}
inline void writeln(long long a) {
  write(a);
  puts("");
}
inline void wri(long long a) {
  write(a);
  putchar(' ');
}
const int N = 100005;
int n;
vector<pair<int, int> > ask[N], v[N];
struct Set {
  map<int, int> sz, sf;
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      q;
  int add;
  void bao(int x, int id) {
    if (id == 1) {
      auto it = sf.upper_bound(x - 2 * add);
      if (it == sf.begin()) return;
      it--;
      q.push(make_pair(x - it->first, x));
    } else {
      auto it = sz.lower_bound(x + 2 * add);
      if (it == sz.end()) return;
      q.push(make_pair(it->first - x, it->first));
    }
  }
  void move(int de) {
    while (q.size() && q.top().first <= 2 * (add + de)) {
      pair<int, int> t = q.top();
      q.pop();
      int x = t.second, y = t.second - t.first;
      auto xx = sz.find(x), yy = sf.find(y);
      if (xx == sz.end() || yy == sf.end()) continue;
      if (xx->second < -yy->second) {
        yy->second += xx->second;
        sz.erase(xx);
        bao(yy->first, -1);
      } else {
        xx->second += yy->second;
        sf.erase(yy);
        bao(xx->first, 1);
      }
    }
    add += de;
  }
  void insert(int x, int de) {
    if (de > 0) {
      sz[x + add] += de;
      bao(x + add, 1);
    } else {
      sf[x - add] += de;
      bao(x - add, -1);
    }
  }
  int get() {
    int ans = 0, dq = 0;
    for (auto i = sz.begin(), j = sf.begin(); i != sz.end() && j != sf.end();) {
      if (i == sz.end() ||
          (j != sf.end() && i->first - add >= j->first + add)) {
        dq += j->second;
        j++;
      } else {
        dq += i->second;
        i++;
      }
      ans = max(ans, dq);
    }
    return ans;
  }
  int cha(int pos) {
    return (sz.count(pos + add) ? sz[pos + add] : 0) +
           (sf.count(pos - add) ? sf[pos - add] : 0);
  }
  int size() { return sz.size() + sf.size(); }
} s[N];
void Merge(Set &x, Set &y) {
  for (auto i : y.sz) {
    x.insert(i.first - y.add, i.second);
  }
  for (auto i : y.sf) {
    x.insert(i.first + y.add, i.second);
  }
}
void print(Set s) {
  cout << s.add << endl;
  for (auto i : s.sz) cout << i.first - s.add << " " << i.second << " wzp\n";
  for (auto i : s.sf) cout << i.first + s.add << " " << i.second << " cqz\n";
  puts("");
}
void alb(int x) {
  for (auto i : ask[x])
    if (i.second > 0) {
      s[x].insert(i.first, i.second);
      s[x].insert(i.first + 1, -i.second);
    }
}
void dfs(int p, int fa) {
  for (auto i : v[p])
    if (i.first != fa) {
      int v = i.first, len = i.second;
      dfs(v, p);
      for (auto &j : ask[v])
        j.second -= max(0, max(-s[v].cha(j.first), s[v].cha(j.first + 1)));
      s[v].move(1);
      alb(v);
      s[v].move(len - 1);
      if (s[p].size() < s[v].size()) swap(s[p], s[v]);
      Merge(s[p], s[v]);
    }
}
int main() {
  n = read();
  for (int i = 1; i < n; i++) {
    int s = read(), t = read(), l = read() * 2;
    v[s].push_back(make_pair(t, l));
    v[t].push_back(make_pair(s, l));
  }
  int m = read();
  while (m--) {
    int d = read() * 2, x = read(), p = read();
    ask[p].push_back(make_pair(d, x));
  }
  v[0].push_back(make_pair(1, 2));
  dfs(0, 0);
  cout << s[0].get() << endl;
}