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")
char ibuf[1 << 20], obuf[1 << 20];
const char *sp, *ep;
char *op = obuf;
int read() {
  static int c, x;
  while (
      (c = (sp == ep && (ep = (sp = ibuf) + fread(ibuf, 1, sizeof ibuf, stdin)),
            *sp++)) < 48) {
  }
  x = c & 15;
  while (
      (c = (sp == ep && (ep = (sp = ibuf) + fread(ibuf, 1, sizeof ibuf, stdin)),
            *sp++)) >= 48)
    x = x * 10 + (c & 15);
  return x;
}
void write(const int &x) {
  if (x >= 10) write(x / 10);
  (op == obuf + sizeof obuf && (fwrite(obuf, 1, op - obuf, stdout), op = obuf),
   *op++ = ((x % 10) | 48));
}
typedef int arr[500010];
struct edge {
  int next, to;
  bool v;
} e[500010 << 1];
int n, rt;
arr head, dep;
inline void add(const int &x, const int &y, const bool &z) {
  static int ei = 1;
  e[++ei].next = head[x];
  e[ei].to = y;
  e[ei].v = z;
  head[x] = ei;
}
void dfs(const int f, const int &fa) {
  if (dep[f] > dep[rt]) rt = f;
  for (int i = head[f]; i; i = e[i].next) {
    const int t = e[i].to;
    if (t != fa) {
      dep[t] = dep[f] + 1;
      dfs(t, f);
    }
  }
}
struct solver {
  int cnt;
  arr dep, dfn, out, seg;
  bool sum[500010];
  int p0[500010 << 2], p1[500010 << 2];
  bool tag[500010 << 2];
  void dfs(const int &f, const int &fa) {
    seg[++cnt] = f;
    dfn[f] = cnt;
    for (int i = head[f]; i; i = e[i].next) {
      const int t = e[i].to;
      if (t != fa) {
        dep[t] = dep[f] + 1;
        sum[t] = sum[f] ^ e[i].v;
        dfs(t, f);
      }
    }
    out[f] = cnt;
  }
  inline void mark(const int &o) {
    tag[o] = !tag[o];
    std::swap(p0[o], p1[o]);
  }
  inline void pushup(const int &o) {
    p0[o] = std::max(p0[o << 1], p0[o << 1 | 1]);
    p1[o] = std::max(p1[o << 1], p1[o << 1 | 1]);
  }
  void build(const int &o, const int &l, const int &r) {
    if (l == r) {
      const int x = seg[l];
      if (sum[x]) {
        p1[o] = dep[x];
      } else {
        p0[o] = dep[x];
      }
      return;
    }
    const int mid = (l + r) >> 1;
    build(o << 1, l, mid);
    build(o << 1 | 1, mid + 1, r);
    pushup(o);
  }
  void modify(const int &o, const int &l, const int &r, const int &L,
              const int &R) {
    if (L <= l && r <= R) {
      mark(o);
      return;
    }
    const int mid = (l + r) >> 1;
    if (tag[o]) {
      mark(o << 1);
      mark(o << 1 | 1);
      tag[o] = false;
    }
    if (L <= mid) modify(o << 1, l, mid, L, R);
    if (mid < R) modify(o << 1 | 1, mid + 1, r, L, R);
    pushup(o);
  }
  inline void modify(const int &id) {
    int x = e[id << 1].to, y = e[id << 1 | 1].to;
    if (dep[x] < dep[y]) x = y;
    modify(1, 1, n, dfn[x], out[x]);
  }
} S1, S2;
int main() {
  n = read();
  for (int i = n; --i;) {
    const int x = read(), y = read(), z = read();
    add(x, y, z);
    add(y, x, z);
  }
  dfs(1, 0);
  S1.dfs(rt, 0);
  dep[rt] = 0;
  dfs(rt, 0);
  S2.dfs(rt, 0);
  S1.build(1, 1, n);
  S2.build(1, 1, n);
  for (int q = read(); q--;) {
    const int x = read();
    S1.modify(x);
    S2.modify(x);
    printf("%d\n", std::max(S1.p0[1], S2.p0[1]));
  }
  return 0;
}