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 = 100005;
vector<pair<int, int>> adj[N], fish[N];
int n, m, now, depth[N];
struct node_t {
  int x, d, v;
  node_t(int x, int d, int v, int t = 0) : x(x - d * t), d(d), v(v) {}
  bool operator<(const node_t &b) const {
    int p = x + now * d, q = b.x + now * b.d;
    return p == q ? d < b.d : p < q;
  }
};
struct collision_t {
  node_t x, y;
  int when;
  collision_t(node_t x, node_t y) : x(x), y(y) { when = y.x - x.x >> 1; }
  bool operator<(const collision_t &b) const {
    if (when != b.when) {
      return when < b.when;
    } else {
      return make_tuple(x.x, x.v, y.x, y.v) <
             make_tuple(b.x.x, b.x.v, b.y.x, b.y.v);
    }
  }
};
struct info_t {
  set<collision_t> collisions;
  set<node_t> nodes;
  void insert_collision(node_t x, node_t y) {
    if (x.d > 0 && y.d < 0) {
      collisions.insert(collision_t(x, y));
    }
  }
  void erase_collision(node_t x, node_t y) {
    if (x.d > 0 && y.d < 0) {
      collisions.erase(collision_t(x, y));
    }
  }
  void insert(node_t x) {
    if (!x.v) {
      return;
    }
    if (nodes.find(x) != nodes.end()) {
      x.v += nodes.find(x)->v;
      erase(*nodes.find(x));
    }
    auto it = nodes.insert(x).first, next = it;
    ++next;
    if (it != nodes.begin()) {
      auto prev = it;
      --prev;
      if (next != nodes.end()) {
        erase_collision(*prev, *next);
      }
      insert_collision(*prev, x);
    }
    if (next != nodes.end()) {
      insert_collision(x, *next);
    }
  }
  void erase(node_t x) {
    auto it = nodes.find(x), next = it;
    ++next;
    if (next != nodes.end()) {
      erase_collision(x, *next);
    }
    if (it != nodes.begin()) {
      auto prev = it;
      --prev;
      erase_collision(*prev, x);
      if (next != nodes.end()) {
        insert_collision(*prev, *next);
      }
    }
    nodes.erase(it);
  }
  int reset(int x, int y) {
    node_t l(x + 1, -1, y, now), r(x - 1, 1, y, now);
    return max(0, y - max(nodes.find(l) == nodes.end() ? 0 : nodes.find(l)->v,
                          nodes.find(r) == nodes.end() ? 0 : nodes.find(r)->v));
  }
  node_t cancel(node_t x, node_t y) {
    if (x.v > y.v) {
      return node_t(x.x, x.d, x.v - y.v);
    } else {
      return node_t(y.x, y.d, y.v - x.v);
    }
  }
  void collide(collision_t x) {
    erase(x.x);
    erase(x.y);
    insert(cancel(x.x, x.y));
  }
  void maintain(int x) {
    while (!collisions.empty() && collisions.begin()->when <= x) {
      collide(*collisions.begin());
    }
  }
  void merge(info_t &b) {
    if (nodes.size() < b.nodes.size()) {
      swap(nodes, b.nodes);
      swap(collisions, b.collisions);
    }
    for (auto x : b.nodes) {
      insert(x);
    }
  }
  int query() {
    int answer = 0;
    for (auto x : nodes) {
      if (x.d > 0) {
        answer += x.v;
      }
    }
    return answer;
  }
} info[N];
void dfs(int x, int parent) {
  for (auto e : adj[x]) {
    int y = e.first, w = e.second;
    if (y != parent) {
      depth[y] = depth[x] + w;
      dfs(y, x);
    }
  }
}
void solve(int x, int parent) {
  for (auto e : adj[x]) {
    int y = e.first, w = e.second;
    if (y != parent) {
      solve(y, x);
      now = -depth[y];
      info[y].maintain(-(depth[x] + 1));
      now = -(depth[x] + 1);
      info[x].merge(info[y]);
    }
  }
  now = -(depth[x] + 1);
  for (auto &e : fish[x]) {
    e.second = info[x].reset(e.first, e.second);
  }
  info[x].maintain(-depth[x]);
  now = -depth[x];
  for (auto e : fish[x]) {
    info[x].insert(node_t(e.first, -1, e.second, now));
    info[x].insert(node_t(e.first, 1, e.second, now));
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int x, y, w;
    scanf("%d %d %d", &x, &y, &w);
    --x;
    --y;
    w <<= 1;
    adj[x].emplace_back(y, w);
    adj[y].emplace_back(x, w);
  }
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) {
    int day, value, where;
    scanf("%d %d %d", &day, &value, &where);
    day <<= 1;
    --where;
    fish[where].emplace_back(day, value);
  }
  dfs(0, -1);
  solve(0, -1);
  info[0].maintain(INT_MAX);
  printf("%d\n", info[0].query());
  return 0;
}