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;
char _buf[100000], *_p1 = _buf, *_p2 = _buf;
inline int gi() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return (f == 1) ? x : -x;
}
inline int max(int a, int b) { return a > b ? a : b; }
inline int min(int a, int b) { return a < b ? a : b; }
const int maxn = 5e5 + 5;
int n, p[maxn], sz, maxpos, maxdis, fa[maxn], Q;
struct node {
  int u, v, w;
};
vector<node> edg;
struct edge {
  int v, w, nxt;
  edge(int vv = 0, int ww = 0, int nn = 0) { v = vv, w = ww, nxt = nn; }
} e[maxn << 1];
inline void add(int u, int v, int w) {
  e[++sz] = edge(v, w, p[u]);
  p[u] = sz;
}
struct segmentree {
  static const int maxn = 2e6 + 5;
  int rt;
  int dep[maxn], tot, dfn[maxn], siz[maxn], len[maxn], rk[maxn];
  bool tag[maxn];
  int maxv[maxn][2];
  inline void pushup(int u) {
    for (int i = 0; i <= 1; ++i) {
      if (maxv[u << 1][i] > maxv[u << 1 | 1][i])
        maxv[u][i] = maxv[u << 1][i];
      else
        maxv[u][i] = maxv[u << 1 | 1][i];
    }
  }
  inline void pushdown(int u) {
    if (tag[u]) {
      swap(maxv[u << 1][0], maxv[u << 1][1]);
      swap(maxv[u << 1 | 1][0], maxv[u << 1 | 1][1]);
      tag[u << 1] ^= 1, tag[u << 1 | 1] ^= 1, tag[u] = 0;
    }
  }
  inline void dfs(int u, int fa) {
    dfn[u] = ++tot;
    siz[u] = 1;
    rk[tot] = u;
    for (int i = p[u]; i != -1; i = e[i].nxt) {
      int v = e[i].v;
      if (v == fa) continue;
      if (e[i].w == 1)
        len[v] = len[u] ^ 1;
      else
        len[v] = len[u];
      dep[v] = dep[u] + 1;
      dfs(v, u);
      siz[u] += siz[v];
    }
  }
  inline void build(int u, int l, int r) {
    if (l == r) {
      maxv[u][len[rk[l]]] = dep[rk[l]];
      return;
    }
    int mid = (l + r) >> 1;
    build(u << 1, l, mid);
    build(u << 1 | 1, mid + 1, r);
    pushup(u);
  }
  inline int query(int u, int l, int r, int x, int y) {
    if (x <= l && y >= r) return maxv[u][0];
    int mid = (l + r) >> 1, ret = 0;
    pushdown(u);
    if (x <= mid) ret = query(u << 1, l, mid, x, y);
    if (y > mid) ret = max(ret, query(u << 1 | 1, mid + 1, r, x, y));
  }
  inline void update(int u, int l, int r, int x, int y) {
    if (x <= l && y >= r) {
      tag[u] ^= 1;
      swap(maxv[u][0], maxv[u][1]);
      return;
    }
    int mid = (l + r) >> 1;
    pushdown(u);
    if (x <= mid) update(u << 1, l, mid, x, y);
    if (y > mid) update(u << 1 | 1, mid + 1, r, x, y);
    pushup(u);
  }
  inline void change(int u, int v) {
    if (dep[u] > dep[v]) swap(u, v);
    update(1, 1, n, dfn[v], dfn[v] + siz[v] - 1);
  }
} tree1, tree2;
inline void dfs2(int u, int f, int dis) {
  if (dis > maxdis) {
    maxpos = u, maxdis = dis;
  }
  for (int i = p[u]; i != -1; i = e[i].nxt) {
    int v = e[i].v;
    if (v == f) continue;
    dfs2(v, u, dis + 1);
  }
}
inline void init() {
  dfs2(1, 0, 0);
  tree1.rt = maxpos;
  maxdis = 0;
  dfs2(maxpos, 0, 0);
  tree2.rt = maxpos;
  tree1.dfs(tree1.rt, 0);
  tree2.dfs(tree2.rt, 0);
  tree1.build(1, 1, n);
  tree2.build(1, 1, n);
}
inline void input() {
  memset(p, -1, sizeof(p));
  n = gi();
  node x;
  edg.push_back(x);
  for (int i = 1; i <= n - 1; ++i) {
    x.u = gi(), x.v = gi(), x.w = gi();
    edg.push_back(x);
    add(x.u, x.v, x.w);
    add(x.v, x.u, x.w);
  }
}
inline void solve() {
  Q = gi();
  while (Q--) {
    int x = gi();
    int u = edg[x].u, v = edg[x].v;
    tree1.change(u, v);
    tree2.change(u, v);
    printf("%d\n", max(tree1.query(1, 1, n, 1, n), tree2.query(1, 1, n, 1, n)));
  }
}
int main() {
  input();
  init();
  solve();
  return 0;
}