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")
using namespace std;
inline int read() {
  int x = 0, f = 1, c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  return f == 1 ? x : -x;
}
const int N = 5e5 + 4;
struct edge {
  int v, w, nxt;
} e[N << 1];
int first[N], cnt = 1;
inline void addedge(int u, int v, int w) {
  e[++cnt] = (edge){v, w, first[u]};
  first[u] = cnt;
}
int n, Q, tim, siz[N], dep[N], son[N], top[N], idx[N], dfn[N], fa[N], dis[N],
    iw[N];
void dfs_1(int x) {
  siz[x] = 1;
  idx[dfn[x] = ++tim] = x;
  for (int i = first[x], v; i; i = e[i].nxt) {
    v = e[i].v;
    if (v == fa[x]) continue;
    fa[v] = x;
    dep[v] = dep[x] + 1;
    dis[v] = dis[x] ^ e[i].w;
    iw[i >> 1] = v;
    dfs_1(v);
    siz[x] += siz[v];
    if (siz[v] > siz[son[x]]) son[x] = v;
  }
}
int mn[N << 1][20], lg[N << 1], st[N];
void dfs_2(int x) {
  mn[st[x] = ++tim][0] = x;
  for (int i = first[x], v; i; i = e[i].nxt) {
    v = e[i].v;
    if (v == fa[x]) continue;
    dfs_2(v);
    mn[++tim][0] = x;
  }
}
inline int cmp(int x, int y) { return dep[x] < dep[y] ? x : y; }
inline void prepare() {
  tim = 0;
  dfs_2(1);
  for (int i = 2; i <= tim; i++) lg[i] = lg[i >> 1] + 1;
  for (int j = 1; j <= lg[tim]; j++)
    for (int i = 1, r = 1 << j; r <= tim; i++, r++)
      mn[i][j] = cmp(mn[i][j - 1], mn[i + (1 << j - 1)][j - 1]);
}
inline int getlca(int x, int y) {
  x = st[x];
  y = st[y];
  if (x > y) x ^= y ^= x ^= y;
  int k = lg[y - x + 1];
  return cmp(mn[x][k], mn[y - (1 << k) + 1][k]);
}
struct node {
  int p1, p2, w;
  node() {}
  node(int x, int y, int v) : p1(x), p2(y), w(v) {}
};
inline bool upd(int &x, int v) {
  if (x < v) {
    x = v;
    return 1;
  }
  return 0;
}
inline int distan(int x, int y) {
  return (!x || !y) ? -1 : dep[x] + dep[y] - dep[getlca(x, y)] * 2;
}
inline node operator+(const node &a, const node &b) {
  node ret = a.w > b.w ? a : b;
  if (upd(ret.w, distan(a.p1, b.p1))) {
    ret.p1 = a.p1;
    ret.p2 = b.p1;
  }
  if (upd(ret.w, distan(a.p1, b.p2))) {
    ret.p1 = a.p1;
    ret.p2 = b.p2;
  }
  if (upd(ret.w, distan(a.p2, b.p1))) {
    ret.p1 = a.p2;
    ret.p2 = b.p1;
  }
  if (upd(ret.w, distan(a.p2, b.p2))) {
    ret.p1 = a.p2;
    ret.p2 = b.p2;
  }
  return ret;
}
namespace seg {
node t[N << 2][2];
int lz[N << 2];
inline void pushup(int p) {
  t[p][0] = t[(p << 1)][0] + t[(p << 1 | 1)][0];
  t[p][1] = t[(p << 1)][1] + t[(p << 1 | 1)][1];
}
inline void pushnow(int p) {
  swap(t[p][0], t[p][1]);
  lz[p] ^= 1;
}
inline void pushdown(int p) {
  if (!lz[p]) return;
  pushnow((p << 1));
  pushnow((p << 1 | 1));
  lz[p] ^= 1;
}
void build(int p, int l, int r) {
  if (l == r) {
    t[p][dis[idx[r]]].p1 = t[p][dis[idx[r]]].p2 = idx[r];
    t[p][dis[idx[r]] ^ 1].w = -1;
    return;
  }
  build((p << 1), l, ((l + r) >> 1));
  build((p << 1 | 1), ((l + r) >> 1) + 1, r);
  pushup(p);
}
void modify(int p, int l, int r, int ql, int qr) {
  if (ql <= l && r <= qr) {
    pushnow(p);
    return;
  }
  pushdown(p);
  if (ql <= ((l + r) >> 1)) modify((p << 1), l, ((l + r) >> 1), ql, qr);
  if (((l + r) >> 1) < qr) modify((p << 1 | 1), ((l + r) >> 1) + 1, r, ql, qr);
  pushup(p);
}
}  // namespace seg
int main() {
  n = read();
  for (int i = 1, u, v, w; i < n; i++) {
    u = read();
    v = read();
    w = read();
    addedge(u, v, w);
    addedge(v, u, w);
  }
  dfs_1(1);
  prepare();
  seg::build(1, 1, n);
  for (int Q = read(), x; Q--;) {
    x = iw[read()];
    seg::modify(1, 1, n, dfn[x], dfn[x] + siz[x] - 1);
    cout << max(seg::t[1][0].w, seg::t[1][1].w) << "\n";
  }
  return (0 - 0);
}