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 maxn = 5e5;
vector<pair<long long, long long>> g[maxn];
long long v1 = 0;
long long v2 = 0;
vector<pair<pair<long long, long long>, long long>> t1(maxn * 4);
vector<pair<pair<long long, long long>, long long>> t2(maxn * 4);
vector<long long> pp1;
vector<pair<pair<long long, long long>, long long>> op1(maxn);
vector<long long> pp2;
vector<pair<pair<long long, long long>, long long>> op2(maxn);
long long n;
long long dist[maxn];
void push(vector<pair<pair<long long, long long>, long long>> &t, long long v) {
  if (t[v].second == 1) {
    t[v].second = 0;
    t[v * 2].second ^= 1;
    swap(t[v * 2].first.first, t[v * 2].first.second);
    t[v * 2 + 1].second ^= 1;
    swap(t[v * 2 + 1].first.first, t[v * 2 + 1].first.second);
  }
}
void upd(vector<pair<pair<long long, long long>, long long>> &t, long long v,
         long long tl, long long tr, long long pos, long long dist,
         long long T) {
  if (tl == tr) {
    if (T == 0) {
      t[v].first.first = dist;
      t[v].first.second = 0;
    } else {
      t[v].first.first = 0;
      t[v].first.second = dist;
    }
    return;
  }
  long long tm = (tl + tr) / 2;
  if (pos <= tm) {
    upd(t, v * 2, tl, tm, pos, dist, T);
  } else {
    upd(t, v * 2 + 1, tm + 1, tr, pos, dist, T);
  }
  t[v].first.first = max(t[v * 2].first.first, t[v * 2 + 1].first.first);
  t[v].first.second = max(t[v * 2].first.second, t[v * 2 + 1].first.second);
}
void update(vector<pair<pair<long long, long long>, long long>> &t, long long v,
            long long tl, long long tr, long long l, long long r) {
  if (tl > r || tr < l) return;
  if (l <= tl && tr <= r) {
    swap(t[v].first.first, t[v].first.second);
    t[v].second ^= 1;
    return;
  }
  push(t, v);
  long long tm = (tl + tr) / 2;
  update(t, v * 2, tl, tm, l, r);
  update(t, v * 2 + 1, tm + 1, tr, l, r);
  t[v].first.first = max(t[v * 2].first.first, t[v * 2 + 1].first.first);
  t[v].first.second = max(t[v * 2].first.second, t[v * 2 + 1].first.second);
}
long long get(vector<pair<pair<long long, long long>, long long>> &t,
              long long v, long long tl, long long tr, long long l,
              long long r) {
  if (tl > r || tr < l) return 0;
  if (l <= tl && tr <= r) {
    if (t[v].second == 1) {
      return t[v].first.second;
    } else
      return t[v].first.first;
  }
  push(t, v);
  long long tm = (tl + tr) / 2;
  return max(get(t, v * 2, tl, tm, l, r), get(t, v * 2 + 1, tm + 1, tr, l, r));
}
void dfs(vector<pair<pair<long long, long long>, long long>> &t,
         vector<long long> &pp,
         vector<pair<pair<long long, long long>, long long>> &op, long long v,
         long long p, long long sum, long long H) {
  upd(t, 1, 0, n - 1, pp.size(), H, sum % 2);
  op[v].first.first = pp.size();
  op[v].second = H;
  pp.push_back(v);
  for (long long i = 0; i < g[v].size(); ++i) {
    long long to = g[v][i].first;
    if (to == p) continue;
    dfs(t, pp, op, to, v, sum + g[v][i].second, H + 1);
  }
  op[v].first.second = pp.size() - 1;
}
void jupaS(long long v, long long p) {
  for (long long i = 0; i < g[v].size(); ++i) {
    long long to = g[v][i].first;
    if (to == p) continue;
    dist[to] = dist[v] + 1;
    jupaS(to, v);
  }
}
signed main() {
  cin.tie();
  cout.tie();
  ios_base::sync_with_stdio(false);
  cin >> n;
  vector<pair<long long, long long>> y;
  for (long long i = 0; i < n - 1; ++i) {
    long long a, b, t;
    cin >> a >> b >> t;
    a--;
    b--;
    y.push_back({a, b});
    g[a].push_back({b, t});
    g[b].push_back({a, t});
  }
  jupaS(0, -1);
  long long mx = 0;
  for (long long k = 0; k < n; ++k) {
    if (dist[mx] < dist[k]) mx = k;
  }
  v1 = mx;
  dist[v1] = 0;
  jupaS(v1, -1);
  mx = 0;
  for (long long k = 0; k < n; ++k) {
    if (dist[mx] < dist[k]) mx = k;
  }
  v2 = mx;
  dfs(t1, pp1, op1, v1, -1, 0, 0);
  dfs(t2, pp2, op2, v2, -1, 0, 0);
  long long q;
  cin >> q;
  for (long long j = 0; j < q; ++j) {
    long long id;
    cin >> id;
    id--;
    long long a = y[id].first;
    long long b = y[id].second;
    if (op1[a].second > op1[b].second) swap(a, b);
    update(t1, 1, 0, n - 1, op1[b].first.first, op1[b].first.second);
    if (op2[a].second > op2[b].second) swap(a, b);
    update(t2, 1, 0, n - 1, op2[b].first.first, op2[b].first.second);
    long long mx = get(t1, 1, 0, n - 1, 0, n - 1);
    long long mx1 = get(t2, 1, 0, n - 1, 0, n - 1);
    cout << max(mx, mx1) << "\n";
  }
}