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>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int n, m, r1, r2, t1[2000005][2], t2[2000005][2], d1[500005], a1[500005],
    d2[500005], a2[500005];
int i1[500005], o1[500005], i2[500005], o2[500005], st, s1[500005], s2[500005],
    L, R;
int f1[500005], f2[500005];
bool b1[2000005], b2[2000005];
vector<int> v[500005], e[500005], ve[500005];
int mx(int x, int y) { return x > y ? x : y; }
void dfs(int x, int y) {
  d1[x] = d1[y] + 1;
  i1[x] = ++st;
  s1[st] = x;
  for (int i = 0; i < v[x].size(); ++i) {
    int z = v[x][i];
    if (z != y) {
      a1[z] = a1[x] ^ e[x][i];
      f1[ve[x][i]] = z;
      dfs(z, x);
    }
  }
  o1[x] = st;
}
void bld1(int k, int l, int r) {
  if (l == r) {
    t1[k][a1[s1[l]]] = d1[s1[l]];
    return;
  }
  int m = (l + r) >> 1, lc = k << 1, rc = lc ^ 1;
  bld1(lc, l, m), bld1(rc, m + 1, r);
  t1[k][0] = mx(t1[lc][0], t1[rc][0]);
  t1[k][1] = mx(t1[lc][1], t1[rc][1]);
}
void bld2(int k, int l, int r) {
  if (l == r) {
    t2[k][a2[s2[l]]] = d2[s2[l]];
    return;
  }
  int m = (l + r) >> 1, lc = k << 1, rc = lc ^ 1;
  bld2(lc, l, m), bld2(rc, m + 1, r);
  t2[k][0] = mx(t2[lc][0], t2[rc][0]);
  t2[k][1] = mx(t2[lc][1], t2[rc][1]);
}
void mk1(int k, int l, int r) {
  if (l >= L && r <= R) {
    b1[k] ^= 1;
    swap(t1[k][0], t1[k][1]);
    return;
  }
  int m = (l + r) >> 1, lc = k << 1, rc = lc ^ 1;
  if (b1[k]) {
    b1[lc] ^= 1;
    swap(t1[lc][0], t1[lc][1]);
    b1[rc] ^= 1;
    swap(t1[rc][0], t1[rc][1]);
    b1[k] = 0;
  }
  if (L <= m) mk1(lc, l, m);
  if (R > m) mk1(rc, m + 1, r);
  t1[k][0] = mx(t1[lc][0], t1[rc][0]);
  t1[k][1] = mx(t1[lc][1], t1[rc][1]);
}
void mk2(int k, int l, int r) {
  if (l >= L && r <= R) {
    b2[k] ^= 1;
    swap(t2[k][0], t2[k][1]);
    return;
  }
  int m = (l + r) >> 1, lc = k << 1, rc = lc ^ 1;
  if (b2[k]) {
    b2[lc] ^= 1;
    swap(t2[lc][0], t2[lc][1]);
    b2[rc] ^= 1;
    swap(t2[rc][0], t2[rc][1]);
    b2[k] = 0;
  }
  if (L <= m) mk2(lc, l, m);
  if (R > m) mk2(rc, m + 1, r);
  t2[k][0] = mx(t2[lc][0], t2[rc][0]);
  t2[k][1] = mx(t2[lc][1], t2[rc][1]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    v[x].push_back(y), v[y].push_back(x);
    e[x].push_back(z), e[y].push_back(z);
    ve[x].push_back(i), ve[y].push_back(i);
  }
  dfs(1, 0);
  r2 = 1;
  for (int i = 1; i <= n; ++i)
    if (d1[i] > d1[r2]) r2 = i;
  a1[r2] = 0;
  st = 0;
  dfs(r2, 0);
  for (int i = 1; i <= n; ++i)
    if (d1[i] > d1[r1]) r1 = i;
  for (int i = 1; i <= n; ++i)
    a2[i] = a1[i], d2[i] = d1[i], i2[i] = i1[i], o2[i] = o1[i], s2[i] = s1[i],
    f2[i] = f1[i];
  a1[r1] = 0;
  st = 0;
  dfs(r1, 0);
  bld1(1, 1, n);
  bld2(1, 1, n);
  scanf("%d", &m);
  while (m--) {
    int x;
    scanf("%d", &x);
    L = i1[f1[x]], R = o1[f1[x]];
    mk1(1, 1, n);
    L = i2[f2[x]], R = o2[f2[x]];
    mk2(1, 1, n);
    printf("%d\n", mx(t1[1][0], t2[1][0]) - 1);
  }
  return 0;
}