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;
template <typename T>
void chkmax(T &first, T second) {
  first < second ? first = second : T();
}
template <typename T>
void chkmin(T &first, T second) {
  first > second ? first = second : T();
}
template <typename T>
void readint(T &first) {
  first = 0;
  int f = 1;
  char c;
  for (c = getchar(); !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) first = first * 10 + (c - '0');
  first *= f;
}
const int MOD = 998244353;
inline int dmy(int first) { return first >= MOD ? first - MOD : first; }
inline void inc(int &first, int second) { first = dmy(first + second); }
int qmi(int first, int second) {
  int ans = 1;
  for (; second; second >>= 1, first = 1ll * first * first % MOD)
    if (second & 1) ans = 1ll * ans * first % MOD;
  return ans;
}
const int MAXN = 500005, MAXK = 19;
int n, _u[MAXN], _v[MAXN];
vector<pair<int, int> > G[MAXN];
int dfn[MAXN], size[MAXN], d0[MAXN], d1[MAXN], col[MAXN], ded[MAXN], dfn_cnt;
void dfs(int u, int pa, int *dep) {
  size[u] = 1;
  dfn[u] = ++dfn_cnt;
  ded[dfn_cnt] = u;
  for (auto p : G[u]) {
    int v = p.first, c = p.second;
    if (v == pa) continue;
    dep[v] = dep[u] + 1;
    col[v] = col[u] ^ c;
    dfs(v, u, dep);
    size[u] += size[v];
  }
}
int co[MAXN << 2], mu[MAXN << 2][2][2], tag[MAXN << 2];
void maintain(int id) {
  swap(mu[id][0][0], mu[id][1][0]);
  swap(mu[id][0][1], mu[id][1][1]);
  co[id] ^= 1;
  tag[id] ^= 1;
}
void update(int id) {
  for (int t = 0; t <= 1; ++t)
    mu[id][0][t] = max(mu[id << 1][0][t], mu[id << 1 | 1][0][t]),
    mu[id][1][t] = max(mu[id << 1][1][t], mu[id << 1 | 1][1][t]);
}
void pushdown(int id) {
  if (!tag[id]) return;
  maintain(id << 1), maintain(id << 1 | 1);
  tag[id] = 0;
}
void build(int id, int l, int r) {
  tag[id] = 0;
  if (l == r) {
    co[id] = col[ded[l]];
    mu[id][co[id]][0] = d0[ded[l]];
    mu[id][co[id]][1] = d1[ded[l]];
    return;
  }
  int mid = (l + r) >> 1;
  build(id << 1, l, mid);
  build(id << 1 | 1, mid + 1, r);
  update(id);
}
void modify(int id, int l, int r, int ql, int qr) {
  if (l == ql && r == qr) {
    maintain(id);
    return;
  }
  pushdown(id);
  int mid = (l + r) >> 1;
  if (qr <= mid)
    modify(id << 1, l, mid, ql, qr);
  else if (ql > mid)
    modify(id << 1 | 1, mid + 1, r, ql, qr);
  else
    modify(id << 1, l, mid, ql, mid),
        modify(id << 1 | 1, mid + 1, r, mid + 1, qr);
  update(id);
}
int query(int id, int l, int r, int ql, int qr, int t, int s) {
  if (l == ql && r == qr) return mu[id][t][s];
  pushdown(id);
  int mid = (l + r) >> 1;
  if (qr <= mid) return query(id << 1, l, mid, ql, qr, t, s);
  if (ql > mid) return query(id << 1 | 1, mid + 1, r, ql, qr, t, s);
  return max(query(id << 1, l, mid, ql, mid, t, s),
             query(id << 1 | 1, mid + 1, r, mid + 1, qr, t, s));
}
int qcol(int id, int l, int r, int first) {
  if (l == r) return co[id];
  pushdown(id);
  int mid = (l + r) >> 1;
  if (first <= mid) return qcol(id << 1, l, mid, first);
  return qcol(id << 1 | 1, mid + 1, r, first);
}
int main() {
  int Q;
  readint(n);
  for (int i = 1; i < n; ++i) {
    int c;
    readint(_u[i]), readint(_v[i]), readint(c);
    G[_u[i]].push_back(make_pair(_v[i], c));
    G[_v[i]].push_back(make_pair(_u[i], c));
  }
  dfs(1, -1, d1);
  int u = 1;
  for (int i = 2; i <= n; ++i)
    if (d1[i] > d1[u]) u = i;
  dfn_cnt = 0;
  dfs(u, -1, d0);
  int v = 1;
  for (int i = 2; i <= n; ++i)
    if (d0[i] > d0[v]) v = i;
  d1[v] = 0;
  dfn_cnt = 0;
  dfs(v, -1, d1);
  d1[0] = d0[0] = -1;
  for (int i = 1; i < n; ++i)
    if (d1[_u[i]] > d1[_v[i]]) swap(_u[i], _v[i]);
  memset(mu, -1, sizeof(mu));
  build(1, 1, n);
  readint(Q);
  while (Q--) {
    int first;
    readint(first);
    first = _v[first];
    modify(1, 1, n, dfn[first], dfn[first] + size[first] - 1);
    int cu = qcol(1, 1, n, dfn[u]), cv = qcol(1, 1, n, dfn[v]);
    if (cu == cv)
      printf("%d\n", d0[v]);
    else
      printf("%d\n", max(mu[1][cu][0], mu[1][cv][1]));
  }
  return 0;
}