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;
inline int readint() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
int _tmp[20];
int _tn;
inline void printint(int x) {
  int f = 1;
  if (x == 0) {
    puts("0");
    return;
  }
  if (x < 0) {
    f = -1;
    x = -x;
  }
  _tn = 0;
  while (x) {
    _tmp[++_tn] = x % 10;
    x /= 10;
  }
  if (f == -1) putchar('-');
  for (int i = _tn; i >= 1; i--) putchar('0' + _tmp[i]);
  puts("");
}
inline void chmax(int &x, int y) { x = max(x, y); }
const int N = 5e5 + 5;
const int INF = 123456789;
int n, m, t = 1, q;
int X[N], Y[N], Z[N], p[N], B[N], E[N], d[N], poi[N * 2];
vector<int> nei[N];
void dfs(int x) {
  B[x] = E[x] = ++m;
  poi[m] = x;
  for (int i = 0; i < int(nei[x].size()); i++) {
    int to = nei[x][i];
    if (to != p[x]) {
      p[to] = x;
      d[to] = d[x] + 1;
      dfs(to);
      E[x] = ++m;
      poi[m] = x;
    }
  }
}
int lson[N * 4];
int rson[N * 4];
int val1[2][N * 4];
int val2[N * 4];
int val3[2][N * 4];
int val4[2][N * 4];
int val5[2][N * 4];
int tag[N * 4];
void update(int pos) {
  for (int i = 0; i < 2; i++) {
    val1[i][pos] = max(val1[i][lson[pos]], val1[i][rson[pos]]);
    val3[i][pos] = max(val3[i][lson[pos]], val3[i][rson[pos]]);
    val4[i][pos] = max(val4[i][lson[pos]], val4[i][rson[pos]]);
    val5[i][pos] = max(val5[i][lson[pos]], val5[i][rson[pos]]);
  }
  val2[pos] = max(val2[lson[pos]], val2[rson[pos]]);
  for (int i = 0; i < 2; i++) {
    if (val1[i][lson[pos]] != -INF && val2[rson[pos]] != -INF)
      chmax(val3[i][pos], val1[i][lson[pos]] + val2[rson[pos]]);
    if (val2[lson[pos]] != -INF && val1[i][rson[pos]] != -INF)
      chmax(val4[i][pos], val2[lson[pos]] + val1[i][rson[pos]]);
  }
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 2; j++) {
      if (val1[i][lson[pos]] != -INF && val4[i][rson[pos]] != -INF)
        chmax(val5[i ^ j][pos], val1[i][lson[pos]] + val4[i][rson[pos]]);
      if (val3[i][lson[pos]] != -INF && val1[i][rson[pos]] != -INF)
        chmax(val5[i ^ j][pos], val3[i][lson[pos]] + val1[i][rson[pos]]);
    }
}
void flip(int pos) {
  tag[pos] ^= 1;
  swap(val1[0][pos], val1[1][pos]);
  swap(val3[0][pos], val3[1][pos]);
  swap(val4[0][pos], val4[1][pos]);
}
void pushdown(int pos) {
  if (tag[pos]) {
    flip(lson[pos]);
    flip(rson[pos]);
    tag[pos] = 0;
  }
}
void build(int pos, int x, int y) {
  for (int i = 0; i < 2; i++)
    val1[i][pos] = val3[i][pos] = val4[i][pos] = val5[i][pos] = -INF;
  val2[pos] = -INF;
  if (x == y) {
    val1[0][pos] = d[poi[x]];
    val2[pos] = -2 * d[poi[x]];
    val3[0][pos] = val4[0][pos] = -d[poi[x]];
    val5[0][pos] = 0;
    return;
  }
  int mid = (x + y) >> 1;
  lson[pos] = ++t;
  rson[pos] = ++t;
  build(lson[pos], x, mid);
  build(rson[pos], mid + 1, y);
  update(pos);
}
void modify(int pos, int x, int y, int l, int r) {
  if (x >= l && y <= r) {
    flip(pos);
    return;
  }
  if (x > r || y < l) return;
  pushdown(pos);
  int mid = (x + y) >> 1;
  modify(lson[pos], x, mid, l, r);
  modify(rson[pos], mid + 1, y, l, r);
  update(pos);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d%d", X + i, Y + i, Z + i);
    nei[X[i]].push_back(Y[i]);
    nei[Y[i]].push_back(X[i]);
  }
  p[1] = 1;
  dfs(1);
  build(1, 1, m);
  for (int i = 1; i < n; i++)
    if (Z[i]) {
      int x = X[i], y = Y[i];
      if (p[y] == x) swap(x, y);
      modify(1, 1, m, B[x], E[x]);
    }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int id;
    scanf("%d", &id);
    int x = X[id], y = Y[id];
    if (p[y] == x) swap(x, y);
    modify(1, 1, m, B[x], E[x]);
    printf("%d\n", val5[0][1]);
  }
  return 0;
}