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 inf = (int)1e9;
const long long INF = (long long)2e18;
const int MOD = 998244353;
int _abs(int x) { return x < 0 ? -x : x; }
int add(int x, int y) {
  x += y;
  return x >= MOD ? x - MOD : x;
}
int sub(int x, int y) {
  x -= y;
  return x < 0 ? x + MOD : x;
}
void Add(int &x, int y) {
  x += y;
  if (x >= MOD) x -= MOD;
}
void Sub(int &x, int y) {
  x -= y;
  if (x < 0) x += MOD;
}
void Mul(int &x, int y) { x = (long long)(x) * (y) % MOD; }
int qpow(int x, int y) {
  int ret = 1;
  while (y) {
    if (y & 1) ret = (long long)(ret) * (x) % MOD;
    x = (long long)(x) * (x) % MOD;
    y >>= 1;
  }
  return ret;
}
void checkmin(int &x, int y) {
  if (x > y) x = y;
}
void checkmax(int &x, int y) {
  if (x < y) x = y;
}
void checkmin(long long &x, long long y) {
  if (x > y) x = y;
}
void checkmax(long long &x, long long y) {
  if (x < y) x = y;
}
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c > '9' || c < '0') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  return x * f;
}
const int N = 500005;
int n, m, d[N], mxdep, mxid;
vector<pair<int, int> > v[N];
pair<int, int> E[N];
void dfs1(int u, int f) {
  if (mxdep < d[u]) mxdep = d[u], mxid = u;
  for (auto &e : v[u]) {
    int to = e.first, w = e.second;
    if (to == f) continue;
    d[to] = d[u] + 1;
    dfs1(to, u);
  }
}
struct Tree {
  int a[N], dep[N], rt;
  int dfn[N], out[N], id[N], dfn_clock = 0;
  int rev[N << 2], mx0[N << 2], mx1[N << 2];
  void pushup(int x) {
    mx0[x] = max(mx0[x << 1], mx0[x << 1 | 1]);
    mx1[x] = max(mx1[x << 1], mx1[x << 1 | 1]);
  }
  void pushdown(int x) {
    if (rev[x]) {
      rev[x << 1] ^= rev[x];
      rev[x << 1 | 1] ^= rev[x];
      rev[x] = 0;
      swap(mx0[x << 1], mx1[x << 1]);
      swap(mx0[x << 1 | 1], mx1[x << 1 | 1]);
    }
  }
  void build(int x, int l, int r) {
    if (l == r) {
      if (a[id[l]] == 0)
        mx0[x] = dep[id[l]], mx1[x] = -inf;
      else
        mx0[x] = -inf, mx1[x] = dep[id[l]];
      return;
    }
    int mid = (l + r) >> 1;
    build(x << 1, l, mid);
    build(x << 1 | 1, mid + 1, r);
    pushup(x);
  }
  void update(int x, int l, int r, int L, int R) {
    if (L <= l && r <= R) {
      rev[x] ^= 1;
      swap(mx0[x], mx1[x]);
      return;
    }
    int mid = (l + r) >> 1;
    pushdown(x);
    if (mid >= L) update(x << 1, l, mid, L, R);
    if (mid < R) update(x << 1 | 1, mid + 1, r, L, R);
    pushup(x);
  }
  void dfs(int u, int f) {
    dfn[u] = ++dfn_clock;
    id[dfn_clock] = u;
    for (auto &e : v[u]) {
      int to = e.first, w = e.second;
      if (to == f) continue;
      dep[to] = dep[u] + 1;
      a[to] = (a[u] ^ w);
      dfs(to, u);
    }
    out[u] = dfn_clock;
  }
  void init() {
    dep[rt] = 0;
    dfs(rt, -1);
    build(1, 1, n);
  }
  void change(int x, int y) {
    if (dep[x] > dep[y]) swap(x, y);
    update(1, 1, n, dfn[y], out[y]);
  }
} T1, T2;
int main() {
  n = read();
  for (int i = 1; i < n; i++) {
    int x = read(), y = read(), z = read();
    E[i] = make_pair(x, y);
    v[x].push_back(make_pair(y, z));
    v[y].push_back(make_pair(x, z));
  }
  mxdep = -1;
  dfs1(1, -1);
  T1.rt = mxid;
  d[mxid] = 0;
  mxdep = -1;
  dfs1(mxid, -1);
  T2.rt = mxid;
  T1.init();
  T2.init();
  m = read();
  while (m--) {
    int x = read();
    T1.change(E[x].first, E[x].second);
    T2.change(E[x].first, E[x].second);
    int ans = max(T1.mx0[1], T2.mx0[1]);
    printf("%d\n", ans);
  }
  return 0;
}