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 long long DIM = 5E5 + 7;
const long long INF = 1E18;
struct node {
  long long first, second, num;
};
vector<node> G[DIM];
long long dist[DIM];
void dfs(long long v, long long par) {
  for (auto to : G[v]) {
    if (to.first == par) continue;
    dist[to.first] = dist[v] + 1;
    dfs(to.first, v);
  }
}
long long depth[2][DIM], col[2][DIM], tin[2][DIM], tout[2][DIM], vt[2][DIM],
    timer = 0, C[2][DIM];
void solve(long long v, long long par, long long type) {
  tin[type][v] = ++timer;
  vt[type][timer] = v;
  for (auto to : G[v]) {
    if (to.first == par) continue;
    C[type][to.num] = to.first;
    col[type][to.first] = col[type][v] ^ to.second;
    depth[type][to.first] = depth[type][v] + 1;
    solve(to.first, v, type);
  }
  tout[type][v] = timer;
}
pair<long long, long long> T[2][DIM * 4];
long long mod[2][DIM * 4];
void buildtree(long long t, long long tl, long long tr) {
  if (tl == tr) {
    if (col[0][vt[0][tl]] == 0) {
      T[0][t] = {depth[0][vt[0][tl]], -INF};
    } else {
      T[0][t] = {-INF, depth[0][vt[0][tl]]};
    }
    if (col[1][vt[1][tl]] == 0) {
      T[1][t] = {depth[1][vt[1][tl]], -INF};
    } else {
      T[1][t] = {-INF, depth[1][vt[1][tl]]};
    }
    return;
  }
  long long tm = (tl + tr) / 2;
  buildtree(t * 2 + 1, tl, tm);
  buildtree(t * 2 + 2, tm + 1, tr);
  for (long long i = 0; i < 2; ++i) {
    T[i][t].first = max(T[i][t * 2 + 1].first, T[i][t * 2 + 2].first);
    T[i][t].second = max(T[i][t * 2 + 1].second, T[i][t * 2 + 2].second);
  }
}
void push(long long t) {
  for (long long i = 0; i < 2; ++i) {
    if (mod[i][t] == 0) continue;
    swap(T[i][t * 2 + 1].first, T[i][t * 2 + 1].second);
    swap(T[i][t * 2 + 2].first, T[i][t * 2 + 2].second);
    mod[i][t * 2 + 1] ^= 1;
    mod[i][t * 2 + 2] ^= 1;
    mod[i][t] = 0;
  }
}
void update(long long t, long long tl, long long tr, long long l, long long r,
            long long type) {
  if (tl > r || l > tr) return;
  if (l <= tl && tr <= r) {
    swap(T[type][t].first, T[type][t].second);
    mod[type][t] ^= 1;
    return;
  }
  push(t);
  long long tm = (tl + tr) / 2;
  update(t * 2 + 1, tl, tm, l, r, type);
  update(t * 2 + 2, tm + 1, tr, l, r, type);
  T[type][t].first = max(T[type][t * 2 + 1].first, T[type][t * 2 + 2].first);
  T[type][t].second = max(T[type][t * 2 + 1].second, T[type][t * 2 + 2].second);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  for (long long i = 1; i < n; ++i) {
    long long u, v, t;
    cin >> u >> v >> t;
    G[u].push_back({v, t, i});
    G[v].push_back({u, t, i});
  }
  dfs(1, 0);
  long long mx = 0;
  for (long long i = 1; i <= n; ++i) {
    if (dist[i] > dist[mx]) mx = i;
  }
  memset(dist, 0, sizeof(dist));
  dfs(mx, mx);
  long long a = mx, b = 0;
  for (long long i = 1; i <= n; ++i) {
    if (dist[i] > dist[b]) b = i;
  }
  solve(a, a, 0);
  timer = 0;
  solve(b, b, 1);
  buildtree(0, 1, n);
  long long m;
  cin >> m;
  while (m--) {
    long long q;
    cin >> q;
    long long v1 = C[0][q], v2 = C[1][q];
    update(0, 1, n, tin[0][v1], tout[0][v1], 0);
    update(0, 1, n, tin[1][v2], tout[1][v2], 1);
    cout << max(T[0][0].first, T[1][0].first) << '\n';
  }
  return 0;
}