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;
namespace IO {
inline char ch() {
  static char s[1 << 16], *S, *T;
  return (S == T) && (T = (S = s) + fread(s, 1, 1 << 16, stdin), S == T) ? EOF
                                                                         : *S++;
}
template <typename T>
void read(T &x) {
  x = 0;
  int f(1);
  char c = ch();
  for (; !isdigit(c); c = ch())
    if (c == '-') f = -1;
  for (; isdigit(c); c = ch()) x = x * 10 + c - '0';
  x *= f;
}
}  // namespace IO
using namespace IO;
const int maxn = 500005;
int n, m, hd[maxn], cnt = 1, tS, tT, tmp;
struct edge {
  int ed, nxt, len;
} e[2 * maxn];
inline void star(int u, int v, int l) {
  e[++cnt] = (edge){v, hd[u], l};
  hd[u] = cnt;
  e[++cnt] = (edge){u, hd[v], l};
  hd[v] = cnt;
}
void Find_Far(int x, int fa, int dis) {
  if (dis > tmp) tT = x, tmp = dis;
  for (int i = hd[x]; i; i = e[i].nxt) {
    int y = e[i].ed;
    if (y == fa) continue;
    Find_Far(y, x, dis + 1);
  }
}
const int saxn = 2000005;
struct segment_tree {
  int mx[saxn][2], fg[saxn];
  inline void pushup(int now) {
    mx[now][0] = max(mx[(now << 1)][0], mx[(now << 1 | 1)][0]);
    mx[now][1] = max(mx[(now << 1)][1], mx[(now << 1 | 1)][1]);
  }
  inline void pushdown(int now) {
    if (!fg[now]) return;
    fg[now] = 0;
    fg[(now << 1)] ^= 1;
    fg[(now << 1 | 1)] ^= 1;
    swap(mx[(now << 1)][0], mx[(now << 1)][1]);
    swap(mx[(now << 1 | 1)][0], mx[(now << 1 | 1)][1]);
  }
  void build(int now, int l, int r, int *valdep, int *valdis, int *valid) {
    fg[now] = 0;
    if (l == r) {
      memset(mx[now], 0, sizeof mx[now]);
      mx[now][valdis[valid[l]]] = valdep[valid[l]];
      return;
    }
    build((now << 1), l, ((l + r) >> 1), valdep, valdis, valid);
    build((now << 1 | 1), ((l + r) >> 1) + 1, r, valdep, valdis, valid);
    pushup(now);
  }
  void Modify(int now, int l, int r, int L, int R) {
    if (r < L || R < l) return;
    if (L <= l && r <= R) {
      fg[now] ^= 1;
      swap(mx[now][0], mx[now][1]);
      return;
    }
    pushdown(now);
    Modify((now << 1), l, ((l + r) >> 1), L, R);
    Modify((now << 1 | 1), ((l + r) >> 1) + 1, r, L, R);
    pushup(now);
  }
};
struct Tree_seg {
  int tL[maxn], tR[maxn], Rt;
  int dep[maxn], ds[maxn], tim, id[maxn];
  segment_tree seg;
  void Dfs1(int x, int fa) {
    tL[x] = ++tim;
    id[tim] = x;
    for (int i = hd[x]; i; i = e[i].nxt) {
      int y = e[i].ed;
      if (y == fa) continue;
      dep[y] = dep[x] + 1;
      ds[y] = ds[x] ^ e[i].len;
      Dfs1(y, x);
    }
    tR[x] = tim;
  }
  void build() {
    dep[Rt] = 0;
    ds[Rt] = 0;
    tim = 0;
    Dfs1(Rt, 0);
    seg.build(1, 1, tim, dep, ds, id);
  }
  int Switch(int x, int y) {
    if (tL[x] <= tL[y] && tL[y] <= tR[x]) swap(x, y);
    seg.Modify(1, 1, tim, tL[x], tR[x]);
    return seg.mx[1][0];
  }
} rS, rT;
int main() {
  read(n);
  for (int i(1); i < n; ++i) {
    int u, v, l;
    read(u);
    read(v);
    read(l);
    star(u, v, l);
  }
  Find_Far(1, 0, 0);
  tS = tT;
  tmp = 0;
  Find_Far(tS, 0, 0);
  rS.Rt = tS;
  rS.build();
  rT.Rt = tT;
  rT.build();
  int m;
  read(m);
  while (m--) {
    int x;
    read(x);
    x *= 2;
    int ans1 = rS.Switch(e[x].ed, e[x ^ 1].ed);
    int ans2 = rT.Switch(e[x].ed, e[x ^ 1].ed);
    printf("%d\n", max(ans1, ans2));
  }
  return 0;
}