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;
const int N = 555555;
const int M = 1111111;
const int MOD = 998244353;
const int intINF = 1e9;
const long long llINF = 2e18;
const double pi = acos(-1.0);
const int inv2 = 5e8 + 4;
int read() {
  int v = 0, f = 1;
  char c = getchar();
  while (c < 48 || 57 < c) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();
  return v * f;
}
long long readll() {
  long long v = 0, f = 1;
  char c = getchar();
  while (c < 48 || 57 < c) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();
  return v * f;
}
unsigned long long readull() {
  long long v = 0, f = 1;
  char c = getchar();
  while (c < 48 || 57 < c) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();
  return v * f;
}
void predo() {}
int head[N], vet[M], len[M], nxt[M], tot, n;
void add(int a, int b, int c) {
  nxt[++tot] = head[a];
  vet[tot] = b;
  len[tot] = c;
  head[a] = tot;
}
struct edge {
  int x, y;
} E[M];
void init() {
  n = read();
  for (int i = (int)1; i <= (int)n - 1; i++) {
    int x = read(), y = read(), z = read();
    add(x, y, z);
    add(y, x, z);
    E[i].x = x;
    E[i].y = y;
  }
}
int st[N], ed[N], dis[N], dep[N], id[N], tim;
void dfs(int u, int fa) {
  st[u] = ++tim;
  id[tim] = u;
  int e = head[u];
  while (e) {
    int v = vet[e];
    if (v != fa) {
      dep[v] = dep[u] + 1;
      dis[v] = dis[u] ^ len[e];
      dfs(v, u);
    }
    e = nxt[e];
  }
  ed[u] = tim;
}
int ST[N][2], ED[N][2], d[N][2], dep1[N], dep2[N], r1, r2;
struct seg_tree {
  struct node {
    int s[2], tag;
  } t[N << 2];
  void pushup(int p) {
    t[p].s[0] = max(t[p << 1].s[0], t[p << 1 | 1].s[0]);
    t[p].s[1] = max(t[p << 1].s[1], t[p << 1 | 1].s[1]);
  }
  void pushdown(int p) {
    if (t[p].tag) {
      swap(t[p << 1].s[0], t[p << 1].s[1]);
      swap(t[p << 1 | 1].s[0], t[p << 1 | 1].s[1]);
      t[p << 1].tag ^= 1;
      t[p << 1 | 1].tag ^= 1;
      t[p].tag = 0;
    }
  }
  void update(int l, int r, int x, int y, int p) {
    if (x <= l && r <= y) {
      swap(t[p].s[0], t[p].s[1]);
      t[p].tag ^= 1;
      return;
    }
    pushdown(p);
    int mid = (l + r) >> 1;
    if (x <= mid) update(l, mid, x, y, p << 1);
    if (y > mid) update(mid + 1, r, x, y, p << 1 | 1);
    pushup(p);
  }
} T1, T2;
int id1[N], id2[N];
void build1(int l, int r, int p) {
  T1.t[p].s[0] = T1.t[p].s[1] = 0;
  T1.t[p].tag = 0;
  if (l == r) {
    if (id1[l]) T1.t[p].s[d[id1[l]][0]] = dep1[id1[l]];
    return;
  }
  int mid = (l + r) >> 1;
  build1(l, mid, p << 1);
  build1(mid + 1, r, p << 1 | 1);
  T1.pushup(p);
}
void build2(int l, int r, int p) {
  T2.t[p].s[0] = T2.t[p].s[1] = 0;
  T2.t[p].tag = 0;
  if (l == r) {
    if (id2[l]) T2.t[p].s[d[id2[l]][1]] = dep2[id2[l]];
    return;
  }
  int mid = (l + r) >> 1;
  build2(l, mid, p << 1);
  build2(mid + 1, r, p << 1 | 1);
  T2.pushup(p);
}
void solve() {
  tim = 0;
  dis[1] = dep[1] = 0;
  dfs(1, 0);
  int r1 = 1;
  for (int i = (int)1; i <= (int)n; i++) {
    if (dep[i] > dep[r1]) r1 = i;
  }
  tim = 0;
  dis[r1] = dep[r1] = 0;
  dfs(r1, 0);
  int r2 = 1;
  for (int i = (int)1; i <= (int)n; i++) {
    if (dep[i] > dep[r2]) r2 = i;
  }
  for (int i = (int)1; i <= (int)n; i++) {
    ST[i][0] = st[i];
    ED[i][0] = ed[i];
    d[i][0] = dis[i];
    dep1[i] = dep[i];
    id1[i] = id[i];
  }
  tim = 0;
  dis[r2] = dep[r2] = 0;
  dfs(r2, 0);
  for (int i = (int)1; i <= (int)n; i++) {
    ST[i][1] = st[i];
    ED[i][1] = ed[i];
    d[i][1] = dis[i];
    dep2[i] = dep[i];
    id2[i] = id[i];
  }
  build1(1, n, 1);
  build2(1, n, 1);
  int q = read();
  while (q--) {
    int id = read();
    int x = E[id].x, y = E[id].y;
    int u;
    if (dep1[x] > dep1[y])
      u = x;
    else
      u = y;
    T1.update(1, n, ST[u][0], ED[u][0], 1);
    if (dep2[x] > dep2[y])
      u = x;
    else
      u = y;
    T2.update(1, n, ST[u][1], ED[u][1], 1);
    int ans = 0;
    ans = max(ans, T1.t[1].s[0]);
    ans = max(ans, T2.t[1].s[0]);
    printf("%d\n", ans);
  }
}
int main() {
  predo();
  int cas = 1;
  while (cas--) {
    init();
    solve();
  }
  return 0;
}