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 N = 1e6 + 1;
const int ts = 1 << 21;
int n;
int eu[N], ev[N], ew[N];
vector<int> adj[N];
int e[N], d2[N];
;
int st[N], en[N];
int ptr = 0;
int seq[N];
void dfs(int id, int p) {
  st[id] = ++ptr;
  seq[ptr] = id;
  for (auto c : adj[id]) {
    if (c == p) continue;
    e[c] = e[id] + 1;
    dfs(c, id);
    seq[++ptr] = id;
  }
  en[id] = ptr;
}
array<int, 9> a[ts];
bool lz[ts];
void putlz(int id) {
  swap(a[id][1], a[id][2]);
  swap(a[id][3], a[id][4]);
  swap(a[id][5], a[id][6]);
  swap(a[id][7], a[id][8]);
}
void pull(int id) {
  int lc = id * 2, rc = id * 2 + 1;
  for (int i = 0; i <= 8; i++) {
    a[id][i] = max(a[lc][i], a[rc][i]);
  }
  a[id][3] = max(a[id][3], a[lc][1] + a[rc][0]);
  a[id][4] = max(a[id][4], a[lc][2] + a[rc][0]);
  a[id][5] = max(a[id][5], a[lc][0] + a[rc][1]);
  a[id][6] = max(a[id][6], a[lc][0] + a[rc][2]);
  a[id][7] = max(a[id][7], a[lc][1] + a[rc][5]);
  a[id][7] = max(a[id][7], a[lc][3] + a[rc][1]);
  a[id][8] = max(a[id][8], a[lc][2] + a[rc][6]);
  a[id][8] = max(a[id][8], a[lc][4] + a[rc][2]);
}
void push(int id) {
  if (!lz[id]) return;
  putlz(id * 2);
  putlz(id * 2 + 1);
  lz[id * 2] ^= 1;
  lz[id * 2 + 1] ^= 1;
  lz[id] = false;
}
void build(int id, int l, int r) {
  for (int i = 0; i <= 8; i++) a[id][i] = -1e6;
  if (l == r) {
    int d = e[seq[l]];
    a[id][0] = -2 * d;
    a[id][1] = d;
    a[id][3] = -d;
    a[id][5] = -d;
    a[id][7] = 0;
    return;
  }
  int mid = (l + r) / 2;
  build(id * 2, l, mid);
  build(id * 2 + 1, mid + 1, r);
  pull(id);
}
void upd(int id, int l, int r, int ql, int qr) {
  if (l > qr || r < ql) return;
  if (ql <= l && r <= qr) {
    putlz(id);
    lz[id] ^= 1;
    return;
  }
  push(id);
  int mid = (l + r) / 2;
  upd(id * 2, l, mid, ql, qr);
  upd(id * 2 + 1, mid + 1, r, ql, qr);
  pull(id);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> eu[i] >> ev[i] >> ew[i];
    int u = eu[i], v = ev[i];
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1, 0);
  build(1, 1, 2 * n - 1);
  for (int i = 1; i < n; i++) {
    if (st[eu[i]] > st[ev[i]]) swap(eu[i], ev[i]);
    if (ew[i]) upd(1, 1, 2 * n - 1, st[ev[i]], en[ev[i]]);
  }
  int q;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int x;
    cin >> x;
    upd(1, 1, 2 * n - 1, st[ev[x]], en[ev[x]]);
    ew[x] ^= 1;
    cout << max(a[1][7], a[1][8]) << '\n';
  }
}