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 MAXN = 5e5 + 10;
const int MAXM = 4e6 + 10;
const long long MOD = 1e9 + 7;
const long long INF = 0x3f3f3f3f;
const unsigned long long BASE = 233;
const int base = 5;
mt19937_64 mt(time(0));
char rubbish[110];
bool GETDATA;
inline long long read() {
  long long x = 0, f = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = -1;
  } while (ch < '0' || ch > '9');
  do {
    x = x * 10 + ch - 48;
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return x * f;
}
inline void write(long long x, char con = '\n') {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10, 0);
  putchar(x % 10 + '0');
  if (con) {
    printf("%c", con);
  }
}
long long N, M, K, Q;
pair<int, int> a[MAXN];
int con[MAXN];
vector<int> es[MAXN];
bool vis[MAXN];
struct SegmentTree {
  int b[MAXN];
  int depth[MAXN];
  pair<int, int> idx[MAXN];
  int ord[MAXN];
  pair<int, int> seg[MAXN << 2];
  int lz[MAXN << 2];
  int cnt;
  int root;
  void dfs(int u, int fa, int floor) {
    int v;
    depth[u] = floor;
    idx[u].first = ++cnt;
    ord[cnt] = u;
    for (int i : es[u]) {
      v = a[i].first == u ? a[i].second : a[i].first;
      if (v == fa) {
        continue;
      }
      b[v] = con[i] ? (b[u] ^ 1) : b[u];
      dfs(v, u, floor + 1);
    }
    idx[u].second = cnt;
  }
  void pushup(int o) {
    seg[o].first = max(seg[(o << 1)].first, seg[(o << 1 | 1)].first);
    seg[o].second = max(seg[(o << 1)].second, seg[(o << 1 | 1)].second);
  }
  void pushdown(int o) {
    if (lz[o]) {
      swap(seg[(o << 1)].first, seg[(o << 1)].second);
      swap(seg[(o << 1 | 1)].first, seg[(o << 1 | 1)].second);
      lz[(o << 1)] ^= 1;
      lz[(o << 1 | 1)] ^= 1;
      lz[o] ^= 1;
    }
  }
  void build(int o, int l, int r) {
    lz[o] = 0;
    if (l == r) {
      seg[o].first = b[ord[l]] ? 0 : depth[ord[l]];
      seg[o].second = b[ord[l]] ? depth[ord[l]] : 0;
      return;
    }
    int m = l + r >> 1;
    build((o << 1), l, m);
    build((o << 1 | 1), m + 1, r);
    pushup(o);
  }
  void updata(int o, int l, int r, int x, int y) {
    if (x <= l && r <= y) {
      lz[o] ^= 1;
      swap(seg[o].first, seg[o].second);
      return;
    }
    int m = l + r >> 1;
    pushdown(o);
    if (x <= m) {
      updata((o << 1), l, m, x, y);
    }
    if (m < y) {
      updata((o << 1 | 1), m + 1, r, x, y);
    }
    pushup(o);
  }
  void seg_init(int _root) {
    cnt = 0;
    root = _root;
    b[root] = 0;
    dfs(root, root, 0);
    build(1, 1, cnt);
  }
  int query(int now) {
    now = depth[a[now].first] > depth[a[now].second] ? a[now].first
                                                     : a[now].second;
    updata(1, 1, N, idx[now].first, idx[now].second);
    return seg[1].first;
  }
} A, B;
int Find(int x) {
  queue<pair<int, int> > q;
  pair<int, int> now;
  int u, v;
  for (int i = 1; i <= N; i++) {
    vis[i] = false;
  }
  while (!q.empty()) {
    q.pop();
  }
  q.push(pair<int, int>(x, 0));
  while (!q.empty()) {
    now = q.front();
    q.pop();
    u = now.first;
    vis[u] = true;
    now.second++;
    for (int i : es[u]) {
      v = a[i].first == u ? a[i].second : a[i].first;
      if (vis[v]) {
        continue;
      }
      now.first = v;
      q.push(now);
    }
  }
  return u;
}
void init() {
  for (int i = 1; i <= N; i++) {
    es[i].clear();
  }
}
void solve() {
  long long ans = 0;
  int now;
  N = read();
  init();
  for (int i = 1; i < N; i++) {
    a[i] = pair<int, int>{read(), read()};
    con[i] = read();
    es[a[i].first].push_back(i);
    es[a[i].second].push_back(i);
  }
  now = Find(1);
  A.seg_init(now);
  now = Find(now);
  B.seg_init(now);
  M = read();
  while (M--) {
    now = read();
    write(max(A.query(now), B.query(now)));
  }
}
int main() {
  int T;
  T = 1;
  for (int t = 1; t <= T; t++) {
    GETDATA = false;
    solve();
  }
  return 0;
}