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", "inline", "-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
using namespace std;
int n, q, loc, maxv, root[2], cnt[2], l[2][500010], r[2][500010],
    val[2][500010], pos[2][500010], dep[2][500010];
int mx0[2][2000010], mx1[2][2000010], rev[2][2000010];
vector<pair<int, int> > v[500010], e;
inline int getint() {
  int r = 0;
  char c;
  c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') {
    r = r * 10 + c - '0';
    c = getchar();
  }
  return r;
}
inline void dfs(int x, int pr, int dist) {
  if (dist > maxv) {
    maxv = dist;
    loc = x;
  }
  for (int i = 0; i < v[x].size(); i++)
    if (v[x][i].first != pr) {
      dfs(v[x][i].first, x, dist + 1);
    }
}
inline void calc(int id, int x, int pr) {
  l[id][x] = ++cnt[id];
  pos[id][cnt[id]] = x;
  for (int i = 0; i < v[x].size(); i++)
    if (v[x][i].first != pr) {
      val[id][v[x][i].first] = val[id][x] ^ v[x][i].second;
      dep[id][v[x][i].first] = dep[id][x] + 1;
      calc(id, v[x][i].first, x);
    }
  r[id][x] = cnt[id];
}
inline void build(int id, int o, int l, int r) {
  rev[id][o] = 0;
  if (l == r) {
    if (val[id][pos[id][l]] == 0) {
      mx0[id][o] = dep[id][pos[id][l]];
      mx1[id][o] = -1000000007;
    } else {
      mx0[id][o] = -1000000007;
      mx1[id][o] = dep[id][pos[id][l]];
    }
  } else {
    int mid = (l + r) / 2;
    build(id, o * 2, l, mid);
    build(id, o * 2 + 1, mid + 1, r);
    mx0[id][o] = max(mx0[id][o * 2], mx0[id][o * 2 + 1]);
    mx1[id][o] = max(mx1[id][o * 2], mx1[id][o * 2 + 1]);
  }
}
inline void pushdown(int id, int o, int l, int r) {
  int lc = o * 2, rc = o * 2 + 1;
  if (l < r) {
    if (rev[id][o]) {
      swap(mx0[id][lc], mx1[id][lc]);
      rev[id][lc] ^= 1;
      swap(mx0[id][rc], mx1[id][rc]);
      rev[id][rc] ^= 1;
      rev[id][o] = 0;
    }
  }
}
inline void pushup(int id, int o, int l, int r) {
  int lc = o * 2, rc = o * 2 + 1;
  if (l < r) {
    mx0[id][o] = max(mx0[id][lc], mx0[id][rc]);
    mx1[id][o] = max(mx1[id][lc], mx1[id][rc]);
  }
}
inline void update(int id, int o, int l, int r, int xx, int yy) {
  if (r < xx || l > yy) return;
  if (xx <= l && r <= yy) {
    swap(mx0[id][o], mx1[id][o]);
    rev[id][o] ^= 1;
    return;
  }
  pushdown(id, o, l, r);
  int mid = (l + r) / 2;
  update(id, o * 2, l, mid, xx, yy);
  update(id, o * 2 + 1, mid + 1, r, xx, yy);
  pushup(id, o, l, r);
}
signed main() {
  n = getint();
  for (int i = 1; i < n; i++) {
    int x, y, c;
    x = getint();
    y = getint();
    c = getint();
    v[x].push_back(make_pair(y, c));
    v[y].push_back(make_pair(x, c));
    e.push_back(make_pair(x, y));
  }
  loc = 0;
  maxv = 0;
  dfs(1, -1, 0);
  root[0] = loc;
  loc = 0;
  maxv = 0;
  dfs(root[0], -1, 0);
  root[1] = loc;
  calc(0, root[0], -1);
  calc(1, root[1], -1);
  build(0, 1, 1, cnt[0]);
  build(1, 1, 1, cnt[1]);
  q = getint();
  for (int i = 1; i <= q; i++) {
    int x;
    x = getint();
    int xx = e[x - 1].first, yy = e[x - 1].second;
    if (dep[0][xx] < dep[0][yy])
      update(0, 1, 1, cnt[0], l[0][yy], r[0][yy]);
    else
      update(0, 1, 1, cnt[0], l[0][xx], r[0][xx]);
    if (dep[1][xx] < dep[1][yy])
      update(1, 1, 1, cnt[1], l[1][yy], r[1][yy]);
    else
      update(1, 1, 1, cnt[1], l[1][xx], r[1][xx]);
    printf("%d\n", max(mx0[0][1], mx0[1][1]));
  }
  return 0;
}