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>
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long long MOD = 998244353;
const long double PI = acosl(-1.0);
const long double E = 1e-15;
mt19937_64 rnd(time(0));
int n, m, k, T, in1[1100001], in2[1100001], out1[1100001], out2[1100001];
pair<int, int> zn[500001];
vector<int> c[500001], z1, z2;
long long binpow(long long h, long long r, long long md) {
  long long l = 1;
  while (r) {
    if (r & 1) l *= h, l %= md;
    h *= h;
    h %= md;
    r /= 2;
  }
  return l;
}
struct segment_tree {
  pair<int, int> d[5000001];
  bool leaf[5000001], tt[5000001];
  void push(int h) {
    if (tt[h] && !leaf[h]) {
      tt[h * 2] ^= tt[h];
      swap(d[h * 2].first, d[h * 2].second);
      tt[h * 2 + 1] ^= tt[h];
      swap(d[h * 2 + 1].first, d[h * 2 + 1].second);
    }
    tt[h] = 0;
  }
  void build(int h, int l, int r, vector<int>& v) {
    if (l == r) {
      leaf[h] = 1;
      d[h] = make_pair(v[l], 0);
      return;
    }
    int w = (l + r) / 2;
    build(h * 2, l, w, v);
    build(h * 2 + 1, w + 1, r, v);
    d[h].first = max(d[h * 2].first, d[h * 2 + 1].first);
    d[h].second = max(d[h * 2].second, d[h * 2 + 1].second);
  }
  void update(int h, int l, int r, int x, int y) {
    if (x > y) return;
    push(h);
    if (l == x && y == r) {
      tt[h] = 1;
      swap(d[h].first, d[h].second);
      push(h);
      return;
    }
    int w = (l + r) / 2;
    update(h * 2, l, w, x, min(y, w));
    update(h * 2 + 1, w + 1, r, max(x, w + 1), y);
    d[h].first = max(d[h * 2].first, d[h * 2 + 1].first);
    d[h].second = max(d[h * 2].second, d[h * 2 + 1].second);
  }
};
segment_tree g1, g2;
long long mx, p1, p2;
void dfs(int h, int p = -1) {
  pair<int, int> o1 = make_pair(0, h), o2 = make_pair(0, h);
  for (int i = 0; i < c[h].size(); i++)
    if (c[h][i] != p) {
      dfs(c[h][i], h);
      if (zn[c[h][i]].first + 1 > o1.first)
        swap(o1, o2), o1 = zn[c[h][i]], o1.first++;
      else if (zn[c[h][i]].first + 1 > o2.first)
        o2 = zn[c[h][i]], o2.first++;
    }
  if (o1.first + o2.first > mx)
    mx = o1.first + o2.first, p1 = o1.second, p2 = o2.second;
  zn[h] = o1;
}
void dfs1(int h, int k = 0, int p = -1) {
  in1[h] = z1.size();
  z1.push_back(k);
  for (int i = 0; i < c[h].size(); i++)
    if (c[h][i] != p) {
      dfs1(c[h][i], k + 1, h);
    }
  out1[h] = z1.size();
  z1.push_back(k);
}
void dfs2(int h, int k = 0, int p = -1) {
  in2[h] = z2.size();
  z2.push_back(k);
  for (int i = 0; i < c[h].size(); i++)
    if (c[h][i] != p) {
      dfs2(c[h][i], k + 1, h);
    }
  out2[h] = z2.size();
  z2.push_back(k);
}
void solve() {
  cin >> n;
  long long tt = 0;
  vector<pair<int, int> > v, zpr;
  for (int i = 1; i < n; i++) {
    long long x, y, z;
    cin >> x >> y >> z;
    c[x].push_back(y);
    c[y].push_back(x);
    v.push_back(make_pair(x, y));
    if (z) zpr.push_back(make_pair(x, y));
    tt = z;
  }
  if (n == 2) {
    long long q;
    cin >> q;
    for (int i = 0; i < q; i++) {
      long long x;
      cin >> x;
      tt ^= 1;
      cout << (tt ? 0 : 1) << "\n";
    }
    exit(0);
  }
  dfs(1);
  dfs1(p1);
  dfs2(p2);
  g1.build(1, 0, z1.size() - 1, z1);
  g2.build(1, 0, z2.size() - 1, z2);
  for (int i = 0; i < zpr.size(); i++) {
    int x = zpr[i].first, y = zpr[i].second;
    if (in1[x] > in1[y]) swap(x, y);
    g1.update(1, 0, z1.size() - 1, in1[y], out1[y]);
    if (in2[x] > in2[y]) swap(x, y);
    g2.update(1, 0, z2.size() - 1, in2[y], out2[y]);
  }
  long long q;
  cin >> q;
  while (q--) {
    long long h;
    cin >> h;
    h--;
    int x = v[h].first, y = v[h].second;
    if (in1[x] > in1[y]) swap(x, y);
    g1.update(1, 0, z1.size() - 1, in1[y], out1[y]);
    if (in2[x] > in2[y]) swap(x, y);
    g2.update(1, 0, z2.size() - 1, in2[y], out2[y]);
    cout << max(g1.d[1].first, g2.d[1].first) << "\n";
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}