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;
mt19937 rnd(229);
inline void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
struct info {
  long long m0 = 0, m1 = -1;
  info() {}
  info(long long a, long long b) : m0(a), m1(b) {}
  void reverse() { swap(m0, m1); }
};
info operator+(const info &a, const info &b) {
  return info(max(a.m0, b.m0), max(a.m1, b.m1));
}
struct segtree {
  segtree *l = nullptr, *r = nullptr;
  long long lb, rb;
  info val;
  long long need = 0;
  void pull() {
    if (lb + 1 < rb) {
      val = l->val + r->val;
    }
  }
  segtree() {}
  segtree(long long L, long long R, const vector<long long> &vals,
          const vector<long long> &d) {
    lb = L, rb = R;
    if (lb + 1 == rb) {
      if (vals[lb] == 0) {
        val = info(d[lb], -1);
      } else {
        val = info(-1, d[lb]);
      }
    } else {
      long long m = (lb + rb) / 2;
      l = new segtree(lb, m, vals, d);
      r = new segtree(m, rb, vals, d);
      pull();
    }
  }
  void push() {
    if (!need) return;
    val.reverse();
    if (lb + 1 < rb) {
      l->need ^= 1;
      r->need ^= 1;
    }
    need = 0;
  }
  void reverse(long long L, long long R) {
    push();
    if (L >= rb || lb >= R) return;
    if (L <= lb && R >= rb) {
      need ^= 1;
      push();
      return;
    }
    l->reverse(L, R);
    r->reverse(L, R);
    pull();
  }
  long long get() {
    push();
    return val.m0;
  }
};
vector<vector<long long> > g;
vector<vector<pair<long long, long long> > > fullgraph;
vector<long long> d, d1;
vector<long long> eiler, eiler1;
vector<long long> tin, tin1, tout, tout1;
vector<long long> vals, vals1;
void dfs0(long long v, long long p = -1) {
  for (auto u : g[v]) {
    if (u == p) continue;
    d[u] = d[v] + 1;
    dfs0(u, v);
  }
}
void dfs1(long long v, long long p = -1) {
  tin[v] = (long long)eiler.size();
  eiler.push_back(v);
  for (auto u : g[v]) {
    if (u == p) continue;
    d[u] = d[v] + 1;
    dfs1(u, v);
  }
  tout[v] = (long long)eiler.size();
}
void dfs11(long long v, long long p = -1) {
  tin1[v] = (long long)eiler1.size();
  eiler1.push_back(v);
  for (auto u : g[v]) {
    if (u == p) continue;
    d1[u] = d1[v] + 1;
    dfs11(u, v);
  }
  tout1[v] = (long long)eiler1.size();
}
pair<long long, long long> diameter(long long n) {
  d.assign(n, 0);
  eiler.clear();
  dfs0(0);
  long long root = 0;
  for (long long i = 0; i < n; ++i) {
    if (d[root] < d[i]) root = i;
  }
  tin.assign(n, 0);
  tout.assign(n, 0);
  d.assign(n, 0);
  dfs1(root);
  long long root1 = 0;
  for (long long i = 0; i < n; ++i) {
    if (d[root1] < d[i]) root1 = i;
  }
  eiler1.clear();
  d1.assign(n, 0);
  tin1.assign(n, 0);
  tout1.assign(n, 0);
  dfs11(root1);
  return {root, root1};
}
void fulldfs(long long v, long long p = -1) {
  for (auto u : fullgraph[v]) {
    if (u.first == p) continue;
    vals[u.first] = (vals[v] + u.second) % 2;
    fulldfs(u.first, v);
  }
}
void fulldfs1(long long v, long long p = -1) {
  for (auto u : fullgraph[v]) {
    if (u.first == p) continue;
    vals1[u.first] = (vals1[v] + u.second) % 2;
    fulldfs1(u.first, v);
  }
}
void solve() {
  long long n;
  cin >> n;
  g.assign(n, vector<long long>(0));
  vector<pair<long long, long long> > e(n - 1);
  fullgraph.assign(n, vector<pair<long long, long long> >(0));
  for (long long i = 0; i < n - 1; ++i) {
    long long a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
    fullgraph[a].push_back({b, c});
    fullgraph[b].push_back({a, c});
    e[i] = {a, b};
  }
  vector<pair<long long, long long> > e1 = e;
  pair<long long, long long> roots = diameter(n);
  long long root = roots.first, root1 = roots.second;
  vals.assign(n, 0);
  vals1.assign(n, 0);
  fulldfs(root);
  fulldfs1(root1);
  for (long long i = 0; i < n - 1; ++i) {
    if (d[e[i].first] > d[e[i].second]) {
      swap(e[i].first, e[i].second);
    }
    if (d1[e1[i].first] > d1[e1[i].second]) {
      swap(e1[i].first, e1[i].second);
    }
  }
  vector<long long> newvals(n, 0);
  vector<long long> newdepths(n, 0);
  for (long long i = 0; i < n; ++i) {
    newvals[i] = vals[eiler[i]];
    newdepths[i] = d[eiler[i]];
  }
  vector<long long> newvals1(n, 0);
  vector<long long> newdepths1(n, 0);
  for (long long i = 0; i < n; ++i) {
    newvals1[i] = vals1[eiler1[i]];
    newdepths1[i] = d1[eiler1[i]];
  }
  segtree *tree = new segtree(0, n, newvals, newdepths);
  segtree *tree1 = new segtree(0, n, newvals1, newdepths1);
  long long m;
  cin >> m;
  while (m--) {
    long long index;
    cin >> index;
    index--;
    long long vertex = e[index].second;
    long long vertex1 = e1[index].second;
    long long l = tin[vertex], r = tout[vertex];
    long long l1 = tin1[vertex1], r1 = tout1[vertex1];
    tree->reverse(l, r);
    tree1->reverse(l1, r1);
    cout << max(tree->get(), tree1->get()) << '\n';
  }
}
signed main() {
  fastio();
  long long T = 1;
  while (T--) {
    solve();
  }
  return 0;
}