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 mod = 1e9 + 7;
int n;
vector<vector<pair<int, int>>> g;
int far(int v) {
  vector<int> d(n + 1, -1);
  d[v] = 0;
  queue<int> q;
  q.push(v);
  while (!q.empty()) {
    int s = q.front();
    q.pop();
    for (auto x : g[s]) {
      int u = x.first;
      if (d[u] == -1) {
        d[u] = d[s] + 1;
        q.push(u);
      }
    }
  }
  int id = 1;
  for (int i = 2; i <= n; ++i) {
    if (d[i] > d[id]) id = i;
  }
  return id;
}
void dfs(int v, int p, vector<int>& tin, vector<int>& tout, vector<int>& d,
         vector<int>& h, vector<int>& e, int& timer) {
  tin[v] = timer++;
  e.push_back(v);
  for (auto x : g[v]) {
    int u = x.first, w = x.second;
    if (u == p) continue;
    d[u] = (d[v] + w) % 2;
    h[u] = h[v] + 1;
    dfs(u, v, tin, tout, d, h, e, timer);
  }
  tout[v] = timer;
}
struct segtree {
  int size;
  vector<vector<int>> tree;
  vector<int> modify;
  segtree(int n) {
    size = 1;
    while (size < n) size <<= 1;
    tree.resize(2 * size - 1, vector<int>(2));
    modify.resize(2 * size - 1);
  }
  void get(int v) {
    tree[v][0] = max(tree[2 * v + 1][0], tree[2 * v + 2][0]);
    tree[v][1] = max(tree[2 * v + 1][1], tree[2 * v + 2][1]);
  }
  void push(int v) {
    if (modify[v]) {
      modify[2 * v + 1] ^= 1;
      modify[2 * v + 2] ^= 1;
      swap(tree[2 * v + 1][0], tree[2 * v + 1][1]);
      swap(tree[2 * v + 2][0], tree[2 * v + 2][1]);
    }
    modify[v] = 0;
  }
  void upd(int v, int lx, int rx, int l, int h, int d) {
    if (lx + 1 == rx) {
      tree[v][d] = h;
      return;
    }
    int m = (lx + rx) / 2;
    if (l < m)
      upd(2 * v + 1, lx, m, l, h, d);
    else
      upd(2 * v + 2, m, rx, l, h, d);
    get(v);
  }
  void upd(int l, int h, int d) { upd(0, 0, size, l, h, d); }
  void rev(int v, int lx, int rx, int l, int r) {
    if (l <= lx and rx <= r) {
      modify[v] ^= 1;
      swap(tree[v][0], tree[v][1]);
      return;
    }
    if (rx <= l or r <= lx) {
      return;
    }
    push(v);
    int m = (lx + rx) / 2;
    rev(2 * v + 1, lx, m, l, r);
    rev(2 * v + 2, m, rx, l, r);
    get(v);
  }
  void rev(int l, int r) { rev(0, 0, size, l, r); }
  int ans() { return tree[0][0]; }
};
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  g.resize(n + 1);
  vector<vector<int>> edges;
  for (int i = 0, u, v, w; i < n - 1; ++i) {
    cin >> u >> v >> w;
    g[u].push_back({v, w});
    g[v].push_back({u, w});
    edges.push_back({u, v});
  }
  int S = far(1), T = far(S);
  vector<int> tin1(n + 1), tin2(n + 1), h1(n + 1), h2(n + 1), tout1(n + 1),
      tout2(n + 1), d1(n + 1), d2(n + 1), e1, e2;
  int timer = 0;
  dfs(S, -1, tin1, tout1, d1, h1, e1, timer);
  timer = 0;
  dfs(T, -1, tin2, tout2, d2, h2, e2, timer);
  segtree ST1(n), ST2(n);
  for (int i = 0; i < n; ++i) {
    ST1.upd(i, h1[e1[i]], d1[e1[i]]);
    ST2.upd(i, h2[e2[i]], d2[e2[i]]);
  }
  int q;
  cin >> q;
  while (q-- > 0) {
    int id;
    cin >> id;
    id--;
    int u = edges[id][0], v = edges[id][1];
    if (h1[u] > h1[v])
      ST1.rev(tin1[u], tout1[u]);
    else
      ST1.rev(tin1[v], tout1[v]);
    if (h2[u] > h2[v])
      ST2.rev(tin2[u], tout2[u]);
    else
      ST2.rev(tin2[v], tout2[v]);
    cout << max(ST1.ans(), ST2.ans()) << '\n';
  }
  return 0;
}