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;
struct aaa {
  int x, y, op;
} a[500010];
int ans, cnt, n, tx, ty, tot, mx, e[1000010], nt[1000010], hd[1000010],
    dep[500010], ru[500010], chu[500010], id[500010], f[2000010][2][2],
    val[1000010], d[500010], jl[500010][2], lz[2000010];
void build(int x, int y, int w) {
  tot++;
  e[tot] = y;
  val[tot] = w;
  nt[tot] = hd[x];
  hd[x] = tot;
}
void get(int x, int fa) {
  int i;
  dep[x] = dep[fa] + 1;
  if (dep[x] > dep[mx]) mx = x;
  for (i = hd[x]; i; i = nt[i]) {
    if (e[i] == fa) continue;
    get(e[i], x);
  }
}
void dfs(int x, int fa) {
  int i;
  ru[x] = ++cnt;
  id[cnt] = x;
  dep[x] = dep[fa] + 1;
  for (i = hd[x]; i; i = nt[i]) {
    if (e[i] == fa) continue;
    d[e[i]] = d[x] ^ val[i];
    dfs(e[i], x);
  }
  chu[x] = cnt;
}
void pushup(int x) {
  int i, j;
  for (i = 0; i < 2; i++)
    for (j = 0; j < 2; j++)
      f[x][i][j] = max(f[x * 2][i][j], f[x * 2 + 1][i][j]);
}
void build1(int x, int l, int r) {
  if (l == r) {
    if (d[id[l]] == 0) {
      f[x][0][0] = jl[id[l]][0];
      f[x][1][0] = jl[id[l]][1];
    } else {
      f[x][0][1] = jl[id[l]][0];
      f[x][1][1] = jl[id[l]][1];
    }
    return;
  }
  int mid = (l + r) / 2;
  build1(x * 2, l, mid);
  build1(x * 2 + 1, mid + 1, r);
  pushup(x);
}
void pushdown(int x) {
  if (lz[x]) {
    lz[x * 2] ^= 1;
    lz[x * 2 + 1] ^= 1;
    lz[x] = 0;
    swap(f[x * 2][0][0], f[x * 2][0][1]);
    swap(f[x * 2][1][0], f[x * 2][1][1]);
    swap(f[x * 2 + 1][0][0], f[x * 2 + 1][0][1]);
    swap(f[x * 2 + 1][1][0], f[x * 2 + 1][1][1]);
  }
}
void xiu(int x, int l, int r, int t, int k) {
  if (l == t && r == k) {
    lz[x] ^= 1;
    swap(f[x][0][0], f[x][0][1]);
    swap(f[x][1][0], f[x][1][1]);
    return;
  }
  pushdown(x);
  int mid = (l + r) / 2;
  if (mid >= k)
    xiu(x * 2, l, mid, t, k);
  else if (t > mid)
    xiu(x * 2 + 1, mid + 1, r, t, k);
  else
    xiu(x * 2, l, mid, t, mid), xiu(x * 2 + 1, mid + 1, r, mid + 1, k);
  pushup(x);
}
int get(int x, int l, int r, int t) {
  if (l == r) {
    return d[id[l]] ^ lz[x];
  }
  pushdown(x);
  int mid = (l + r) / 2;
  if (mid >= t)
    return get(x * 2, l, mid, t);
  else
    return get(x * 2 + 1, mid + 1, r, t);
}
int main() {
  int t1, i, op0, op1;
  scanf("%d", &n);
  for (i = 1; i < n; i++) {
    scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].op);
    build(a[i].x, a[i].y, a[i].op);
    build(a[i].y, a[i].x, a[i].op);
  }
  get(1, 0);
  tx = mx;
  mx = 0;
  get(tx, 0);
  for (i = 1; i <= n; i++) jl[i][0] = dep[i] - 1;
  ty = mx;
  get(ty, 0);
  for (i = 1; i <= n; i++) jl[i][1] = dep[i] - 1;
  dfs(1, 0);
  build1(1, 1, n);
  scanf("%d", &t1);
  while (t1--) {
    scanf("%d", &i);
    if (dep[a[i].x] < dep[a[i].y]) swap(a[i].x, a[i].y);
    xiu(1, 1, n, ru[a[i].x], chu[a[i].x]);
    op0 = get(1, 1, n, ru[tx]);
    op1 = get(1, 1, n, ru[ty]);
    ans = 0;
    if (op0 == 0)
      ans = max(ans, f[1][0][0]);
    else
      ans = max(ans, f[1][0][1]);
    if (op1 == 0)
      ans = max(ans, f[1][1][0]);
    else
      ans = max(ans, f[1][1][1]);
    printf("%d\n", ans);
  }
}