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;
using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;
template <typename T>
using pair2 = pair<T, T>;
template <typename T>
T sgn(T a) {
  return (a < 0 ? -1 : (a > 0 ? 1 : 0));
}
const int maxn = 100005;
const int inf = 1e9;
vector<pair2<int>> gr[maxn], qs[maxn];
int sz[maxn];
int n, q;
int TIME = 0;
class tans {
 public:
  struct tpoint {
    int x, diff;
    tpoint(int x_, int diff_, int time = TIME) : diff(diff_) {
      x = x_ + sgn(diff) * time;
    }
    int pos(int time = TIME) const { return x - sgn(diff) * time; }
    bool operator<(const tpoint &other) const { return pos() < other.pos(); }
  };
  using ppoint = set<tpoint>::iterator;
  struct tseg : pair<int, ppoint> {
    bool operator<(const tseg &other) const {
      if (first != other.first) return first < other.first;
      return second->pos() < other.second->pos();
    }
    tseg(int a, const ppoint &b) : pair<int, ppoint>(a, b) {}
  };
  set<tseg> small;
  set<tpoint> bounds;
  void addsegment(ppoint l, ppoint r) {
    int speed = sgn(r->diff) - sgn(l->diff);
    if (speed > 0) {
      int t = (r->pos() - l->pos() + speed - 1) / speed + TIME;
      small.insert(tseg(t, l));
    }
  }
  void remsegment(ppoint l, ppoint r) {
    int speed = sgn(r->diff) - sgn(l->diff);
    if (speed > 0) {
      int t = (r->pos() - l->pos() + speed - 1) / speed + TIME;
      small.erase(small.find(tseg(t, l)));
    }
  }
  tans() {
    bounds.insert({-inf, 0});
    bounds.insert({inf, 0});
    addsegment(bounds.begin(), bounds.end());
  }
  void proceed(int time) {
    while (!small.empty() && small.begin()->first <= time) {
      auto itl = small.begin()->second;
      auto itr = next(itl);
      int ctime = small.begin()->first;
      remsegment(itl, itr);
      int pos = itl->pos(ctime);
      int cdiff = itl->diff + itr->diff;
      if (itr->pos(ctime) != pos && cdiff > 0) pos--;
      auto itll = prev(itl);
      auto itrr = next(itr);
      remsegment(itll, itl);
      remsegment(itr, itrr);
      bounds.erase(itl);
      bounds.erase(itr);
      auto me = bounds.insert(itrr, tpoint(pos, cdiff, ctime));
      addsegment(itll, me);
      addsegment(me, itrr);
    }
  }
  int getupd(int x) {
    int upd = 0;
    auto itr = bounds.lower_bound(tpoint(x, 0));
    if (itr->pos() == x && itr->diff < 0) upd = max(upd, -itr->diff);
    itr = bounds.lower_bound(tpoint(x + 1, 0));
    if (itr->pos() == x + 1 && itr->diff > 0) upd = max(upd, itr->diff);
    return upd;
  }
  void add(int x, int t) {
    tpoint toadd(x, t);
    auto itr = bounds.lower_bound(toadd);
    if (toadd < *itr) {
      auto itl = prev(itr);
      remsegment(itl, itr);
      auto me = bounds.insert(itr, toadd);
      addsegment(itl, me);
      addsegment(me, itr);
    } else {
      auto itl = prev(itr);
      auto me = itr;
      itr = next(itr);
      remsegment(itl, me);
      remsegment(me, itr);
      toadd = tpoint(x, t + me->diff);
      bounds.erase(me);
      me = bounds.insert(itr, toadd);
      addsegment(itl, me);
      addsegment(me, itr);
    }
  }
  vector<tpoint> getbounds() {
    return vector<tpoint>((bounds).begin(), (bounds).end());
  }
  int getans() {
    int answer = 0;
    int cur = 0;
    for (auto t : bounds) {
      cur += t.diff;
      answer = max(answer, cur);
    }
    return answer;
  }
};
using pans = tans *;
pans go(int cur, int pr = -1) {
  pans curans = NULL;
  for (auto e : gr[cur])
    if (e.first != pr) {
      TIME -= e.second * 2;
      auto t = go(e.first, cur);
      t->proceed(TIME + (e.second - 1) * 2);
      TIME += (e.second - 1) * 2;
      t->proceed(TIME + 1);
      TIME += 1;
      if (curans == NULL)
        curans = t;
      else {
        for (auto pt : t->getbounds()) {
          if (pt.pos() > -inf && pt.pos() < inf) curans->add(pt.pos(), pt.diff);
        }
      }
    }
  if (curans == NULL) curans = new tans();
  for (auto &curq : qs[cur]) {
    curq.second = max(0, curq.second - curans->getupd(curq.first));
  }
  curans->proceed(TIME + 1);
  TIME += 1;
  for (auto t : qs[cur]) {
    curans->add(t.first, t.second);
    curans->add(t.first + 1, -t.second);
  }
  return curans;
}
void preprocess(int cur, int pr = -1) {
  sz[cur] = 0;
  for (auto e : gr[cur])
    if (e.first != pr) {
      preprocess(e.first, cur);
      sz[cur] += sz[e.first];
    }
  sz[cur] += qs[cur].size();
  sort((gr[cur]).begin(), (gr[cur]).end(),
       [&](const pair2<int> &a, const pair2<int> &b) {
         return sz[a.first] > sz[b.first];
       });
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    a--, b--;
    gr[a].push_back({b, c});
    gr[b].push_back({a, c});
  }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int d, f, p;
    scanf("%d%d%d", &d, &f, &p);
    d *= 2;
    p--;
    qs[p].push_back({d, f});
  }
  preprocess(0);
  auto ans = go(0);
  cout << ans->getans() << endl;
  return 0;
}