Problem: In the Land of Fire there are n villages and n-1 bidirectional road, and there is a path between any pair of villages by roads. There are only two types of roads: stone ones and sand ones. Since the Land of Fire is constantly renovating, every morning workers choose a single road and flip its type (so it becomes a stone road if it was a sand road and vice versa). Also everyone here loves ramen, that's why every morning a ramen pavilion is set in the middle of every stone road, and at the end of each day all the pavilions are removed.

For each of the following m days, after another road is flipped, Naruto and Jiraiya choose a simple path — that is, a route which starts in a village and ends in a (possibly, the same) village, and doesn't contain any road twice. Since Naruto and Jiraiya also love ramen very much, they buy a single cup of ramen on each stone road and one of them eats it. Since they don't want to offend each other, they only choose routes where they can eat equal number of ramen cups. Since they both like traveling, they choose any longest possible path. After every renovation find the maximal possible length of a path (that is, the number of roads in it) they can follow.

Input

The first line contains the only positive integer n (2 ≤ n ≤ 500 000) standing for the number of villages in the Land of Fire.

Each of the following (n-1) lines contains a description of another road, represented as three positive integers u, v and t (1 ≤ u, v ≤ n, t ∈ \{0,1\}). The first two numbers denote the villages connected by the road, and the third denotes the initial type of the road: 0 for the sand one and 1 for the stone one. Roads are numbered from 1 to (n-1) in the order from the input.

The following line contains a positive integer m (1 ≤ m ≤ 500 000) standing for the number of days Naruto and Jiraiya travel for.

Each of the following m lines contains the single integer id (1 ≤ id ≤ n-1) standing for the index of the road whose type is flipped on the morning of corresponding day.

It is guaranteed that there is a road path between any pair of villages.

Output

Output m lines. In the i-th of them print the only integer denoting the maximal possible length of any valid path on the i-th day.

Example

Input


5
1 2 0
1 3 0
3 5 0
3 4 0
5
3
4
1
3
4


Output


3
2
3
3
2

Note

After the renovation of the 3-rd road the longest path consists of the roads 1, 2 and 4.

After the renovation of the 4-th road one of the longest paths consists of the roads 1 and 2.

After the renovation of the 1-st road one of the longest paths consists of the roads 1, 2 and 3.

After the renovation of the 3-rd road the longest path consists of the roads 1, 2 and 4.

After the renovation of the 4-rd road one of the longest paths consists of the roads 2 and 4.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
const long long mod = 1e9 + 7;
long long n;
vector<vector<pair<long long, long long>>> g;
long long far(long long v) {
  vector<long long> d(n + 1, -1);
  d[v] = 0;
  queue<long long> q;
  q.push(v);
  while (!q.empty()) {
    long long s = q.front();
    q.pop();
    for (auto x : g[s]) {
      long long u = x.first;
      if (d[u] == -1) {
        d[u] = d[s] + 1;
        q.push(u);
      }
    }
  }
  long long id = 1;
  for (long long i = 2; i <= n; ++i) {
    if (d[i] > d[id]) id = i;
  }
  return id;
}
void dfs(long long v, long long p, vector<long long>& tin,
         vector<long long>& tout, vector<long long>& d, vector<long long>& h,
         vector<long long>& e, long long& timer) {
  tin[v] = timer++;
  e.push_back(v);
  for (auto x : g[v]) {
    long long u = x.first, w = x.second;
    if (u == p) continue;
    d[u] = (d[v] + w) % 2;
    h[u] = h[v] + 1;
    dfs(u, v, tin, tout, d, h, e, timer);
  }
  tout[v] = timer;
}
struct segtree {
  long long size;
  vector<vector<long long>> tree;
  vector<long long> modify;
  segtree(long long n) {
    size = 1;
    while (size < n) size <<= 1;
    tree.resize(2 * size - 1, vector<long long>(2));
    modify.resize(2 * size - 1);
  }
  void get(long long v) {
    tree[v][0] = max(tree[2 * v + 1][0], tree[2 * v + 2][0]);
    tree[v][1] = max(tree[2 * v + 1][1], tree[2 * v + 2][1]);
  }
  void push(long long v) {
    if (modify[v]) {
      modify[2 * v + 1] ^= 1;
      modify[2 * v + 2] ^= 1;
      swap(tree[2 * v + 1][0], tree[2 * v + 1][1]);
      swap(tree[2 * v + 2][0], tree[2 * v + 2][1]);
    }
    modify[v] = 0;
  }
  void upd(long long v, long long lx, long long rx, long long l, long long h,
           long long d) {
    if (lx + 1 == rx) {
      tree[v][d] = h;
      return;
    }
    long long m = (lx + rx) / 2;
    if (l < m)
      upd(2 * v + 1, lx, m, l, h, d);
    else
      upd(2 * v + 2, m, rx, l, h, d);
    get(v);
  }
  void upd(long long l, long long h, long long d) { upd(0, 0, size, l, h, d); }
  void rev(long long v, long long lx, long long rx, long long l, long long r) {
    if (l <= lx and rx <= r) {
      modify[v] ^= 1;
      swap(tree[v][0], tree[v][1]);
      return;
    }
    if (rx <= l or r <= lx) {
      return;
    }
    push(v);
    long long m = (lx + rx) / 2;
    rev(2 * v + 1, lx, m, l, r);
    rev(2 * v + 2, m, rx, l, r);
    get(v);
  }
  void rev(long long l, long long r) { rev(0, 0, size, l, r); }
  long long ans() { return tree[0][0]; }
};
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  g.resize(n + 1);
  vector<vector<long long>> edges;
  for (long long i = 0, u, v, w; i < n - 1; ++i) {
    cin >> u >> v >> w;
    g[u].push_back({v, w});
    g[v].push_back({u, w});
    edges.push_back({u, v});
  }
  long long S = far(1), T = far(S);
  vector<long long> tin1(n + 1), tin2(n + 1), h1(n + 1), h2(n + 1),
      tout1(n + 1), tout2(n + 1), d1(n + 1), d2(n + 1), e1, e2;
  long long timer = 0;
  dfs(S, -1, tin1, tout1, d1, h1, e1, timer);
  timer = 0;
  dfs(T, -1, tin2, tout2, d2, h2, e2, timer);
  segtree ST1(n), ST2(n);
  for (long long i = 0; i < n; ++i) {
    ST1.upd(i, h1[e1[i]], d1[e1[i]]);
    ST2.upd(i, h2[e2[i]], d2[e2[i]]);
  }
  long long q;
  cin >> q;
  while (q-- > 0) {
    long long id;
    cin >> id;
    id--;
    long long u = edges[id][0], v = edges[id][1];
    if (h1[u] > h1[v])
      ST1.rev(tin1[u], tout1[u]);
    else
      ST1.rev(tin1[v], tout1[v]);
    if (h2[u] > h2[v])
      ST2.rev(tin2[u], tout2[u]);
    else
      ST2.rev(tin2[v], tout2[v]);
    cout << max(ST1.ans(), ST2.ans()) << '\n';
  }
  return 0;
}