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;
inline int read() {
  int t = 0;
  char v = getchar();
  while (v < '0') v = getchar();
  while (v >= '0') t = (t << 3) + (t << 1) + v - 48, v = getchar();
  return t;
}
int n, m, c[500012], h[500012], cnt = 1, de[500012], L[500012], R[500012],
                                dfst = 0, rev[500012], le[500012], dft = 0,
                                g[1000012][20], Log[1000012];
struct Edge {
  int to, next, s;
} e[500012 << 1];
inline void AddEdge(int x, int y, int v) {
  e[++cnt] = (Edge){y, h[x], v};
  h[x] = cnt;
}
void dfs(int x, int prt) {
  de[x] = de[prt] + 1;
  rev[L[x] = ++dfst] = x;
  g[le[x] = ++dft][0] = de[x];
  int i, y;
  for (i = h[x]; i; i = e[i].next)
    if ((y = e[i].to) != prt)
      c[y] = c[x] ^ e[i].s, dfs(y, x), g[++dft][0] = de[x];
  R[x] = dfst;
}
inline int dlc(int x, int y) {
  x = le[x];
  y = le[y];
  (x > y) ? (x ^= y ^= x ^= y) : 0;
  int p = Log[y - x + 1];
  return min(g[x][p], g[y - (1 << p) + 1][p]);
}
inline int di(int x, int y) { return de[x] + de[y] - (dlc(x, y) << 1); }
struct Dia {
  int x, y, v;
  inline Dia(int xx = 0, int yy = 0, int vv = 0) {
    x = xx;
    y = yy;
    v = vv;
  }
  inline Dia operator+(const Dia &b) const {
    if (!x) return b;
    if (!b.x) return *this;
    int ox = x, oy = y, ov = v, v1;
    if (b.v > ov) ox = b.x, oy = b.y, ov = b.v;
    if ((v1 = di(x, b.x)) > ov) ov = v1, ox = x, oy = b.x;
    if ((v1 = di(x, b.y)) > ov) ov = v1, ox = x, oy = b.y;
    if ((v1 = di(y, b.x)) > ov) ov = v1, ox = y, oy = b.x;
    if ((v1 = di(y, b.y)) > ov) ov = v1, ox = y, oy = b.y;
    return Dia(ox, oy, ov);
  }
} s[500012 << 2][2];
bool re[500012 << 2];
inline void pus(int x) {
  s[x][0] = s[x << 1][0] + s[x << 1 | 1][0];
  s[x][1] = s[x << 1][1] + s[x << 1 | 1][1];
}
inline void Add(int x) {
  re[x] ^= 1;
  swap(s[x][0], s[x][1]);
}
inline void pd(int x) {
  if (re[x]) Add(x << 1), Add(x << 1 | 1), re[x] = 0;
}
void build(int p, int l, int r) {
  if (l == r) {
    int v = c[rev[l]];
    s[p][v] = Dia(rev[l], rev[l], 0);
    s[p][v ^ 1] = Dia(0, 0, 0);
    return;
  }
  int mid = (l + r) >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
  pus(p);
}
void change(int p, int l, int r, int L, int R) {
  if ((R < l) || (r < L)) return;
  if ((L <= l) && (r <= R)) {
    Add(p);
    return;
  }
  pd(p);
  int mid = (l + r) >> 1;
  change(p << 1, l, mid, L, R);
  change(p << 1 | 1, mid + 1, r, L, R);
  pus(p);
}
int main() {
  Log[0] = -1;
  for (int i = 1; i < 1000012; i++) Log[i] = Log[i >> 1] + 1;
  n = read();
  int i, j, x, y, v;
  for (i = 1; i < n; i++) {
    x = read(), y = read(), v = read();
    AddEdge(x, y, v);
    AddEdge(y, x, v);
  }
  dfs(1, 0);
  for (j = 1; j <= Log[dft]; j++)
    for (i = 1; i + (1 << j) - 1 <= dft; i++)
      g[i][j] = min(g[i][j - 1], g[i + (1 << (j - 1))][j - 1]);
  build(1, 1, dfst);
  m = read();
  while (m--) {
    v = read();
    v <<= 1;
    x = (de[e[v].to] < de[e[v ^ 1].to]) ? (e[v ^ 1].to) : (e[v].to);
    change(1, 1, dfst, L[x], R[x]);
    printf("%d\n", max(s[1][0].v, s[1][1].v));
  }
  return 0;
}