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 MAXN = 1e5 + 5;
template <typename T>
void chkmax(T &x, T y) {
  x = max(x, y);
}
template <typename T>
void chkmin(T &x, T y) {
  x = min(x, y);
}
template <typename T>
void read(T &x) {
  x = 0;
  int f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -f;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  x *= f;
}
template <typename T>
void write(T x) {
  if (x < 0) x = -x, putchar('-');
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
template <typename T>
void writeln(T x) {
  write(x);
  puts("");
}
struct Pair {
  int x, y;
};
int n, m, curr, depth[MAXN];
vector<Pair> a[MAXN], b[MAXN];
struct Info {
  int pos, type, val;
};
bool operator<(Info a, Info b) {
  int apos = a.pos + a.type * curr;
  int bpos = b.pos + b.type * curr;
  if (apos == bpos)
    return a.type < b.type;
  else
    return apos < bpos;
}
struct Crash {
  Info a, b;
  int when;
  void calc() {
    int apos = a.pos + a.type * curr;
    int bpos = b.pos + b.type * curr;
    when = curr - (bpos - apos + 1) / 2;
  }
};
Crash make(Info a, Info b) {
  Crash ans = (Crash){a, b};
  ans.calc();
  return ans;
}
bool operator<(Crash a, Crash b) {
  if (a.when == b.when)
    return make_pair(a.a, a.b) < make_pair(b.a, b.b);
  else
    return a.when > b.when;
}
struct Container {
  set<Info> Val;
  set<Crash> Del;
  void EraseCrash(Info a, Info b) {
    if (a.type == -1 && b.type == 1) Del.erase(make(a, b));
  }
  void InsertCrash(Info a, Info b) {
    if (a.type == -1 && b.type == 1) Del.insert(make(a, b));
  }
  void erase(Info a) {
    set<Info>::iterator pos = Val.find(a), suf = pos;
    suf++;
    if (pos != Val.begin()) {
      set<Info>::iterator pre = pos;
      pre--;
      EraseCrash(*pre, *pos);
      if (suf != Val.end()) InsertCrash(*pre, *suf);
    }
    if (suf != Val.end()) EraseCrash(*pos, *suf);
    Val.erase(pos);
  }
  void insert(Info a) {
    if (a.val == 0) return;
    if (Val.find(a) != Val.end()) {
      a.val += (*Val.find(a)).val;
      erase(*Val.find(a));
    }
    if (a.val == 0) return;
    set<Info>::iterator pos = Val.insert(a).first, suf = pos;
    suf++;
    if (pos != Val.begin()) {
      set<Info>::iterator pre = pos;
      pre--;
      InsertCrash(*pre, *pos);
      if (suf != Val.end()) EraseCrash(*pre, *suf);
    }
    if (suf != Val.end()) InsertCrash(*pos, *suf);
  }
  void process(Crash a) {
    erase(a.a), erase(a.b);
    int tmp = a.a.val + a.b.val;
    if (tmp == 0) return;
    if (tmp > 0)
      a.b.val = tmp, insert(a.b);
    else
      a.a.val = tmp, insert(a.a);
  }
  void maintain(int timer) {
    while (!Del.empty() && timer <= (*Del.begin()).when) process(*Del.begin());
    curr = timer;
  }
  void debug(int pos, int timer) {
    maintain(timer);
    cerr << "Debugging In Progress. At Point " << pos
         << " Current Time: " << timer << endl;
    set<Info>::iterator i;
    cerr << "Set Val: " << endl;
    for (i = Val.begin(); i != Val.end(); i++)
      cerr << (*i).pos << '(' << (*i).pos + curr * (*i).type << ')' << ' '
           << (*i).type << ' ' << (*i).val << endl;
    set<Crash>::iterator j;
    cerr << "Del Val: " << endl;
    for (j = Del.begin(); j != Del.end(); j++) {
      cerr << (*j).a.pos << '(' << (*j).a.pos + curr * (*j).a.type << ')' << ' '
           << (*j).a.type << ' ' << (*j).a.val << ' ';
      cerr << (*j).b.pos << '(' << (*j).b.pos + curr * (*j).b.type << ')' << ' '
           << (*j).b.type << ' ' << (*j).b.val << ' ';
      cerr << "Collide Time: " << (*j).when << endl;
    }
  }
  void join(Container &a, int timer) {
    maintain(timer);
    if (a.Val.size() > Val.size()) {
      swap(Val, a.Val);
      swap(Del, a.Del);
    }
    set<Info>::iterator i;
    for (i = a.Val.begin(); i != a.Val.end(); i++) insert(*i);
  }
  int delta(int pos) {
    Info tmp = (Info){pos + curr, -1, 0};
    Info tnp = (Info){pos + 1 - curr, 1, 0};
    int vtmp = 0, vtnp = 0;
    if (Val.find(tmp) != Val.end()) vtmp = -(*Val.find(tmp)).val;
    if (Val.find(tnp) != Val.end()) vtnp = (*Val.find(tnp)).val;
    return max(vtmp, vtnp);
  }
  void modify(vector<Pair> &a, int from, int to) {
    maintain(from);
    for (unsigned i = 0; i < a.size(); i++) {
      int tmp = delta(a[i].x);
      a[i].y = max(0, a[i].y - tmp);
    }
    maintain(from - 1);
    for (unsigned i = 0; i < a.size(); i++) {
      insert((Info){a[i].x - curr, 1, a[i].y});
      insert((Info){a[i].x + 1 + curr, -1, -a[i].y});
    }
    maintain(to);
  }
  int calcans() {
    int ans = 0, now = 0;
    set<Info>::iterator i;
    for (i = Val.begin(); i != Val.end(); i++) {
      now += (*i).val;
      chkmax(ans, now);
    }
    return ans;
  }
} dp[MAXN];
void dfs(int pos, int fa) {
  for (unsigned i = 0; i < a[pos].size(); i++)
    if (a[pos][i].x != fa) {
      depth[a[pos][i].x] = depth[pos] + a[pos][i].y;
      dfs(a[pos][i].x, pos);
    }
}
void work(int pos, int fa, int last) {
  for (unsigned i = 0; i < a[pos].size(); i++)
    if (a[pos][i].x != fa) {
      int tmp = a[pos][i].x;
      work(tmp, pos, depth[pos]);
      dp[pos].join(dp[a[pos][i].x], depth[pos]);
    }
  dp[pos].modify(b[pos], depth[pos], last);
}
int main() {
  read(n);
  for (int i = 1; i <= n - 1; i++) {
    int x, y, z;
    read(x), read(y), read(z);
    a[x].push_back((Pair){y, z * 2});
    a[y].push_back((Pair){x, z * 2});
  }
  read(m);
  for (int i = 1; i <= m; i++) {
    int d, f, p;
    read(d), read(f), read(p);
    b[p].push_back((Pair){d * 2, f});
  }
  dfs(1, 0);
  work(1, 0, -2);
  writeln(dp[1].calcans());
  return 0;
}