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 inf = 0x3f3f3f3f;
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return x * f;
}
int n, wdep[500050], dep[500050], In[500050], Out[500050], p[500050], tot, Q,
    a[500050 << 1];
vector<tuple<int, int, int> > G[500050];
struct node {
  int l, r;
  int A[2], B, AB[2], BA[2], ABA[2];
  node() {
    A[0] = A[1] = B = AB[0] = AB[1] = BA[0] = BA[1] = ABA[0] = ABA[1] = -inf;
  }
  bool rev;
  void Rev() {
    swap(A[0], A[1]);
    swap(AB[0], AB[1]);
    swap(BA[0], BA[1]);
    rev ^= 1;
  }
} tree[500050 << 3];
void dfs(int u, int fa) {
  a[++tot] = u;
  In[u] = tot;
  for (auto [v, w, id] : G[u]) {
    if (v == fa) continue;
    p[id] = v;
    dep[v] = dep[u] + 1;
    wdep[v] = wdep[u] + w;
    dfs(v, u);
    a[++tot] = u;
  }
  Out[u] = tot;
}
inline void pushdown(int i) {
  if (tree[i].rev) {
    tree[i << 1].Rev();
    tree[i << 1 | 1].Rev();
    tree[i].rev = 0;
  }
}
inline void update(int i) {
  tree[i].B = max(tree[i << 1].B, tree[i << 1 | 1].B);
  for (int p = 0; p < 2; ++p) {
    tree[i].A[p] = max(tree[i << 1].A[p], tree[i << 1 | 1].A[p]);
    tree[i].AB[p] = max(max(tree[i << 1].AB[p], tree[i << 1 | 1].AB[p]),
                        tree[i << 1].A[p] + tree[i << 1 | 1].B);
    tree[i].BA[p] = max(max(tree[i << 1].BA[p], tree[i << 1 | 1].BA[p]),
                        tree[i << 1].B + tree[i << 1 | 1].A[p]);
    tree[i].ABA[p] = max(tree[i << 1].ABA[p], tree[i << 1 | 1].ABA[p]);
  }
  for (int p1 = 0; p1 < 2; ++p1) {
    for (int p2 = 0; p2 < 2; ++p2) {
      tree[i].ABA[p1 ^ p2] =
          max(tree[i].ABA[p1 ^ p2],
              max(tree[i << 1].AB[p1] + tree[i << 1 | 1].A[p2],
                  tree[i << 1].A[p1] + tree[i << 1 | 1].BA[p2]));
    }
  }
}
void build(int i, int l, int r) {
  tree[i].l = l;
  tree[i].r = r;
  if (l == r) {
    int u = a[l];
    int p = wdep[u] & 1;
    tree[i].A[p] = dep[u];
    tree[i].B = -2 * dep[u];
    tree[i].AB[p] = tree[i].BA[p] = -dep[u];
    return;
  }
  int mid = (l + r) >> 1;
  build(i << 1, l, mid);
  build(i << 1 | 1, mid + 1, r);
  update(i);
}
void Change(int i, int l, int r) {
  if (tree[i].l >= l && tree[i].r <= r) {
    tree[i].Rev();
    return;
  }
  pushdown(i);
  int mid = (tree[i].l + tree[i].r) >> 1;
  if (l <= mid) {
    Change(i << 1, l, r);
  }
  if (r > mid) {
    Change(i << 1 | 1, l, r);
  }
  update(i);
}
int main() {
  n = read();
  for (int i = 1; i < n; ++i) {
    int u = read(), v = read(), w = read();
    G[u].emplace_back(v, w, i);
    G[v].emplace_back(u, w, i);
  }
  dfs(1, 0);
  build(1, 1, tot);
  Q = read();
  while (Q--) {
    int u = read();
    Change(1, In[p[u]], Out[p[u]]);
    printf("%d\n", tree[1].ABA[0]);
  }
  return 0;
}