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 iinf = 1e9 + 10;
const long long inf = 1ll << 60;
const long long mod = 1e9 + 7;
void GG() {
  cout << "0\n";
  exit(0);
}
long long mpow(long long a, long long n, long long mo = mod) {
  long long re = 1;
  while (n > 0) {
    if (n & 1) re = re * a % mo;
    a = a * a % mo;
    n >>= 1;
  }
  return re;
}
long long inv(long long b, long long mo = mod) {
  if (b == 1) return b;
  return (mo - mo / b) * inv(mo % b, mo) % mo;
}
const int maxn = 5e5 + 5;
vector<pair<int, int> > g[maxn];
int A[maxn], B[maxn], C[maxn];
pair<int, int> bst = {-1, -1};
int n;
void far(int v, int p, int d = 0) {
  bst = max(bst, {d, v});
  for (pair<int, int> u : g[v]) {
    if (u.first != p) {
      far(u.first, v, d + 1);
    }
  }
}
int bot[maxn];
int L[maxn], R[maxn];
bool tg[maxn * 4];
int second[maxn * 4][2];
int mydep[maxn];
int IT = 0;
void push(int o, int l, int r) {
  if (tg[o]) {
    swap(second[o][0], second[o][1]);
    if (l != r) {
      tg[o * 2] ^= 1;
      tg[o * 2 + 1] ^= 1;
    }
    tg[o] = 0;
  }
}
void FLIP(int L, int R, int o = 1, int l = 0, int r = maxn - 1) {
  push(o, l, r);
  if (l > R || r < L) return;
  if (l >= L && r <= R) {
    tg[o] ^= 1;
    push(o, l, r);
    return;
  }
  int mid = (l + r) / 2;
  FLIP(L, R, o * 2, l, mid);
  FLIP(L, R, o * 2 + 1, mid + 1, r);
  second[o][0] = max(second[o * 2][0], second[o * 2 + 1][0]);
  second[o][1] = max(second[o * 2][1], second[o * 2 + 1][1]);
}
void build(int o, int l, int r) {
  if (l == r) {
    if (l < n) {
      second[o][0] = mydep[l];
    }
    return;
  }
  int mid = (l + r) / 2;
  build(o * 2, l, mid);
  build(o * 2 + 1, mid + 1, r);
  second[o][0] = max(second[o * 2][0], second[o * 2 + 1][0]);
}
void initdfs(int v, int p, int d = 0) {
  mydep[IT] = d;
  L[v] = R[v] = IT++;
  for (pair<int, int> u : g[v]) {
    if (u.first != p) {
      initdfs(u.first, v, d + 1);
      bot[u.second] = u.first;
      R[v] = R[u.first];
    }
  }
}
vector<int> que;
int ANS[maxn];
void go(int rt) {
  memset(second, 0, sizeof second);
  memset(tg, 0, sizeof tg);
  IT = 0;
  initdfs(rt, -1);
  build(1, 0, maxn - 1);
  for (int i = 0; i < n - 1; ++i) {
    if (C[i]) {
      FLIP(L[bot[i]], R[bot[i]]);
    }
  }
  for (int i = 0; i < (int)que.size(); ++i) {
    int x = que[i];
    FLIP(L[bot[x]], R[bot[x]]);
    ;
    ANS[i] = max(ANS[i], second[1][0]);
    ;
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    --a;
    --b;
    tie(A[i], B[i], C[i]) = tie(a, b, c);
    g[a].push_back({b, i});
    g[b].push_back({a, i});
  }
  far(0, -1, 0);
  int S1 = bst.second;
  bst = {-1, -1};
  far(S1, -1, 0);
  int S2 = bst.second;
  ;
  int q;
  cin >> q;
  while (q--) {
    int x;
    cin >> x;
    que.push_back(x - 1);
  }
  go(S2);
  go(S1);
  for (int i = 0; i < (int)que.size(); ++i) {
    cout << ANS[i] << '\n';
  }
}