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;
int read(void) {
  int x = 0;
  register char ch = getchar();
  while (ch < 48) ch = getchar();
  while (ch > 47) x = x * 10 + ch - 48, ch = getchar();
  return x;
}
constexpr int Maxn = 5e5 + 5;
constexpr int LOG = 20;
int n, q;
struct Edge {
  int to, w, nxt, id;
} e[Maxn << 1];
int head[Maxn], tot_edge;
void add_edge(int u, int v, int w) {
  e[++tot_edge] = (Edge){v, w, head[u]};
  head[u] = tot_edge;
}
int dfn[Maxn], ed[Maxn], dfn_time, dfn_id[Maxn];
int sz[Maxn], dep[Maxn];
int xord[Maxn], e_son[Maxn];
int fad[Maxn << 1], fa_time, fdfn[Maxn];
int ST[Maxn << 1][LOG + 1], lg[Maxn << 1];
void dfs(int u, int fa, int depth) {
  sz[u] = 1;
  dep[u] = depth;
  dfn[u] = ++dfn_time;
  dfn_id[dfn_time] = u;
  fdfn[u] = ++fa_time;
  fad[fa_time] = u;
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].to, w = e[i].w;
    if (v == fa) continue;
    xord[v] = xord[u] ^ w;
    dfs(v, u, depth + 1);
    sz[u] += sz[v];
    e_son[(i + 1) >> 1] = v;
    fad[++fa_time] = u;
  }
  ed[u] = dfn[u] + sz[u] - 1;
}
inline int min_dep(int x, int y) { return (dep[x] < dep[y]) ? x : y; }
int get_lca(int x, int y) {
  if (x == y) return x;
  int l = fdfn[x], r = fdfn[y];
  if (l > r) swap(l, r);
  int k = lg[r - l + 1];
  return min_dep(ST[l][k], ST[r - (1 << k) + 1][k]);
}
int get_dist(int x, int y) { return dep[x] + dep[y] - 2 * dep[get_lca(x, y)]; }
struct diam {
  int x, y, d;
  diam() : x(0), y(0), d(0) {}
  diam(int x, int y) : x(x), y(y) { d = (x == y) ? 0 : get_dist(x, y); }
  diam(int x, int y, int d) : x(x), y(y), d(d) {}
  diam(const diam &da) : x(da.x), y(da.y), d(da.d) {}
  friend bool operator<(const diam &x, const diam &y) { return x.d < y.d; }
  friend diam operator+(const diam &x, const diam &y) {
    if (!x.x) return y;
    if (!y.x) return x;
    diam res = max(x, y);
    res = max(res, max(diam(x.x, y.x), diam(x.x, y.y)));
    res = max(res, max(diam(x.y, y.x), diam(x.y, y.y)));
    return res;
  }
};
diam tr[Maxn << 2][2];
bool rev[Maxn << 2];
void pushup(int p) {
  tr[p][0] = tr[(p << 1)][0] + tr[((p << 1) | 1)][0];
  tr[p][1] = tr[(p << 1)][1] + tr[((p << 1) | 1)][1];
}
void build(int p, int l, int r) {
  rev[p] = false;
  if (l == r) {
    int x = dfn_id[l];
    int y = xord[x];
    tr[p][y] = diam(x, x);
    tr[p][y ^ 1] = diam();
    return;
  }
  int mid = (l + r) >> 1;
  build((p << 1), l, mid);
  build(((p << 1) | 1), mid + 1, r);
  pushup(p);
}
void apply(int p) {
  swap(tr[p][0], tr[p][1]);
  rev[p] ^= 1;
}
void pushdown(int p, int l, int r) {
  if (rev[p]) {
    if (l != r) {
      apply((p << 1));
      apply(((p << 1) | 1));
    }
    rev[p] = false;
  }
}
void modify(int p, int l, int r, int L, int R) {
  if (L > r || l > R) return;
  if (L <= l && r <= R) return apply(p);
  pushdown(p, l, r);
  int mid = (l + r) >> 1;
  modify((p << 1), l, mid, L, R);
  modify(((p << 1) | 1), mid + 1, r, L, R);
  pushup(p);
}
int main() {
  n = read();
  for (int i = 1; i < n; ++i) {
    int u, v, w;
    u = read(), v = read(), w = read();
    add_edge(u, v, w);
    add_edge(v, u, w);
  }
  xord[1] = 0;
  dfn_time = fa_time = 0;
  dfs(1, 0, 1);
  int szf = fa_time;
  lg[0] = -1;
  for (int i = 1; i <= szf; ++i) {
    ST[i][0] = fad[i];
    lg[i] = lg[i >> 1] + 1;
  }
  for (int j = 1; j <= LOG; ++j) {
    for (int i = 1; i + (1 << j) - 1 <= szf; ++i) {
      ST[i][j] = min_dep(ST[i][j - 1], ST[i + (1 << (j - 1))][j - 1]);
    }
  }
  build(1, 1, n);
  q = read();
  while (q--) {
    int x = read();
    int u = e_son[x];
    modify(1, 1, n, dfn[u], ed[u]);
    printf("%d\n", max(tr[1][0], tr[1][1]).d);
  }
  return 0;
}