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>
const int N = 500000;
std::vector<std::pair<int, int> > G[N + 5];
void adde(int u, int v, int w) {
  G[u].push_back(std::make_pair(v, w));
  G[v].push_back(std::make_pair(u, w));
}
int a[N + 5];
int dl[N + 5], dr[N + 5], dfn[N + 5], dcnt;
int dep[N + 5], fir[N + 5], arr[2 * N + 5], cnta;
void dfs1(int x, int fa) {
  dep[x] = dep[fa] + 1, dfn[dl[x] = (++dcnt)] = x, arr[fir[x] = (++cnta)] = x;
  for (auto to : G[x])
    if (to.first != fa)
      a[to.first] = a[x] ^ to.second, dfs1(to.first, x), arr[++cnta] = x;
  dr[x] = dcnt;
}
int st[22][2 * N + 5], lg[2 * N + 5];
void build() {
  for (int i = 2; i <= cnta; i++) lg[i] = lg[i >> 1] + 1;
  for (int i = 1; i <= cnta; i++) st[0][i] = arr[i];
  for (int j = 1; j < 22; j++) {
    int t = (1 << (j - 1));
    for (int i = 1; i + t <= cnta; i++)
      st[j][i] = (dep[st[j - 1][i]] < dep[st[j - 1][i + t]] ? st[j - 1][i]
                                                            : st[j - 1][i + t]);
  }
}
int lca(int u, int v) {
  u = fir[u], v = fir[v];
  if (u > v) std::swap(u, v);
  int p = lg[v - u + 1], q = (1 << p);
  return dep[st[p][u]] < dep[st[p][v - q + 1]] ? st[p][u] : st[p][v - q + 1];
}
int dist(int u, int v) { return dep[u] + dep[v] - 2 * dep[lca(u, v)]; }
struct type {
  int u, v;
  friend type operator+(const type &a, const type &b) {
    if (a.u == -1) return b;
    if (b.u == -1) return a;
    int t[4] = {a.u, a.v, b.u, b.v}, mx = 0, p = 0, q = 0;
    for (int i = 0; i < 4; i++)
      for (int j = i + 1; j < 4; j++)
        if (dist(t[i], t[j]) > mx) mx = dist(t[i], t[j]), p = t[i], q = t[j];
    return (type){p, q};
  }
};
namespace segtree {
int le[4 * N + 5], ri[4 * N + 5];
bool tag[4 * N + 5];
type mx[4 * N + 5][2];
void addtag(int x) { tag[x] ^= 1, std::swap(mx[x][0], mx[x][1]); }
void pushup(int x) {
  mx[x][0] = mx[(x << 1)][0] + mx[(x << 1 | 1)][0],
  mx[x][1] = mx[(x << 1)][1] + mx[(x << 1 | 1)][1];
}
void pushdown(int x) {
  if (tag[x]) addtag((x << 1)), addtag((x << 1 | 1));
  tag[x] = 0;
}
void build(int x, int l, int r) {
  le[x] = l, ri[x] = r, tag[x] = 0;
  if (l == r) {
    mx[x][a[dfn[l]]] = (type){dfn[l], dfn[l]};
    mx[x][!a[dfn[l]]] = (type){-1, -1};
    return;
  }
  int m = (l + r) >> 1;
  build((x << 1), l, m), build((x << 1 | 1), m + 1, r), pushup(x);
}
void rev(int x, int ql, int qr) {
  if (ql <= le[x] && ri[x] <= qr) {
    addtag(x);
    return;
  }
  if (le[x] > qr || ri[x] < ql) return;
  pushdown(x), rev((x << 1), ql, qr), rev((x << 1 | 1), ql, qr), pushup(x);
}
int ans() {
  return std::max(dist(mx[1][0].u, mx[1][0].v), dist(mx[1][1].u, mx[1][1].v));
}
}  // namespace segtree
const int SZ = 1 << 19;
char buf[SZ], *ie = buf + SZ, *ip = ie - 1;
inline int read() {
  if (++ip == ie) fread(ip = buf, 1, SZ, stdin);
  while (*ip < '-')
    if (++ip == ie) fread(ip = buf, 1, SZ, stdin);
  bool f = *ip == '-';
  if (f)
    if (++ip == ie) fread(ip = buf, 1, SZ, stdin);
  int x = *ip & 15;
  if (++ip == ie) fread(ip = buf, 1, SZ, stdin);
  while (*ip > '-') {
    x *= 10;
    x += *ip & 15;
    if (++ip == ie) fread(ip = buf, 1, SZ, stdin);
  }
  return f ? -x : x;
}
int u[N + 5], v[N + 5];
int main() {
  int n = read();
  for (int i = 1, w; i < n; i++)
    u[i] = read(), v[i] = read(), w = read(), adde(u[i], v[i], w);
  dfs1(1, 0), build(), segtree::build(1, 1, n);
  int m = read();
  for (int i = 1, x; i <= m; i++) {
    x = read();
    x = (dep[u[x]] < dep[v[x]] ? v[x] : u[x]);
    segtree::rev(1, dl[x], dr[x]);
    printf("%d\n", segtree::ans());
  }
}