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;
const int maxn = 5e5 + 5, maxm = 1e6 + 5;
int mx[maxn << 2][2][2], fz[maxn << 2][2];
int color[maxn][2], cen[maxn][2], dis[maxn], DFS[maxn][2], EFS[maxn][2], t[2];
inline void push_up(int rt) {
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 2; j++)
      mx[rt][i][j] = max(mx[rt << 1][i][j], mx[rt << 1 | 1][i][j]);
}
inline void push_down(int rt, int l, int r) {
  if (fz[rt][1]) {
    swap(mx[rt << 1][1][0], mx[rt << 1][1][1]);
    swap(mx[rt << 1 | 1][1][0], mx[rt << 1 | 1][1][1]);
    fz[rt << 1][1] ^= 1, fz[rt << 1 | 1][1] ^= 1;
    fz[rt][1] = 0;
  }
  if (fz[rt][0]) {
    swap(mx[rt << 1][0][0], mx[rt << 1][0][1]);
    swap(mx[rt << 1 | 1][0][0], mx[rt << 1 | 1][0][1]);
    fz[rt << 1][0] ^= 1, fz[rt << 1 | 1][0] ^= 1;
    fz[rt][0] = 0;
  }
}
void build(int rt, int l, int r) {
  if (l == r) {
    mx[rt][1][color[l][1]] = cen[l][1];
    mx[rt][0][color[l][0]] = cen[l][0];
    return;
  }
  int m = (l + r) >> 1;
  build(rt << 1, l, m);
  build(rt << 1 | 1, m + 1, r);
  push_up(rt);
}
void update(int rt, int l, int r, int L, int R, int v) {
  if (L <= l && r <= R) {
    swap(mx[rt][v][0], mx[rt][v][1]);
    fz[rt][v] ^= 1;
    return;
  }
  push_down(rt, l, r);
  int m = (l + r) >> 1;
  if (L <= m) update(rt << 1, l, m, L, R, v);
  if (m < R) update(rt << 1 | 1, m + 1, r, L, R, v);
  push_up(rt);
}
int query(int rt, int l, int r, int L, int R) {
  if (L <= l && r <= R) return max(mx[rt][1][0], mx[rt][0][0]);
  push_down(rt, l, r);
  int m = (l + r) >> 1;
  if (L <= m)
    ;
  if (m < R)
    ;
  return 0;
}
int head[maxn], nume;
struct edge {
  int v, w, c, next;
} e[maxm];
inline void init_edge() {
  memset(head, -1, sizeof head);
  nume = 0;
}
inline void add_edge(int u, int v, int w = 0, int c = 0) {
  e[nume].v = v;
  e[nume].w = w;
  e[nume].c = c;
  e[nume].next = head[u];
  head[u] = nume++;
}
int a = 1, b = 1;
void dfs(int u, int f) {
  for (int i = head[u]; ~i; i = e[i].next) {
    int v = e[i].v;
    if (v != f) {
      dis[v] = dis[u] + 1;
      dfs(v, u);
    }
  }
}
void ddfs(int u, int f, int cl) {
  DFS[u][cl] = ++t[cl];
  for (int i = head[u]; ~i; i = e[i].next) {
    int v = e[i].v, w = e[i].w;
    if (v != f) {
      cen[t[cl] + 1][cl] = cen[DFS[u][cl]][cl] + 1;
      color[t[cl] + 1][cl] = color[DFS[u][cl]][cl] ^ w;
      ddfs(v, u, cl);
    }
  }
  EFS[u][cl] = t[cl];
}
int n, u[maxn], v[maxn], w[maxn];
int m, x;
int main() {
  init_edge();
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d%d", &u[i], &v[i], &w[i]);
    add_edge(u[i], v[i], w[i]);
    add_edge(v[i], u[i], w[i]);
  }
  dis[1] = 0;
  dfs(1, 0);
  for (int i = 1; i <= n; i++) {
    if (dis[i] > dis[a]) a = i;
  }
  dis[a] = 0;
  dfs(a, 0);
  for (int i = 1; i <= n; i++) {
    if (dis[i] > dis[b]) b = i;
  }
  ddfs(a, 0, 0);
  ddfs(b, 0, 1);
  build(1, 1, n);
  scanf("%d", &m);
  while (m--) {
    scanf("%d", &x);
    for (int i = 0; i <= 1; i++) {
      if (DFS[u[x]][i] < DFS[v[x]][i])
        update(1, 1, n, DFS[v[x]][i], EFS[v[x]][i], i);
      else
        update(1, 1, n, DFS[u[x]][i], EFS[u[x]][i], i);
    }
    printf("%d\n", max(mx[1][0][0], mx[1][1][0]));
  }
}