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;
using ll = long long;
using cd = complex<double>;
using ul = unsigned long;
void f_io() {
  ios_base ::sync_with_stdio(false);
  cin.tie(nullptr);
}
int cc = 0, hi[(ll)(5e5 + 7)][2], bin[(ll)(5e5 + 7) * 2][2];
bool la[8 * (ll)(5e5 + 7)][2];
pair<int, int> ar[(ll)(5e5 + 7)][2], seg[8 * (ll)(5e5 + 7)][2];
vector<pair<int, bool>> gr[(ll)(5e5 + 7)];
vector<int> ve[2];
vector<pair<int, pair<int, int>>> vp;
bool ch = 0;
void dfs(int node, int par, bool fl) {
  hi[node][ch] = hi[par][ch] + 1;
  ve[ch].push_back(node);
  ar[node][ch].first = ve[ch].size();
  bin[ve[ch].size()][ch] = fl;
  for (pair<int, int> x : gr[node]) {
    if (x.first != par) {
      dfs(x.first, node, fl ^ x.second);
    }
  }
  ve[ch].push_back(node);
  ar[node][ch].second = ve[ch].size();
  bin[ve[ch].size()][ch] = fl;
}
pair<int, int> dfs(int node, int par) {
  pair<int, int> m1, m2;
  for (pair<int, int> x : gr[node]) {
    if (x.first != par) {
      pair<int, int> p = dfs(x.first, node);
      if (p > m1) {
        m2 = m1;
        m1 = p;
      } else if (p > m2) {
        m2 = p;
      }
    }
  }
  if (m1.first == 0) {
    return make_pair(1, node);
  } else if (m2.first) {
    vp.push_back(
        make_pair(m1.first + m2.first, make_pair(m1.second, m2.second)));
  }
  vp.push_back(make_pair(m1.first, make_pair(node, m1.second)));
  return make_pair(m1.first + 1, m1.second);
}
void laz(int ind, int l, int r, bool fl) {
  if (la[ind][fl]) {
    swap(seg[ind][fl].first, seg[ind][fl].second);
    if (l < r) {
      la[ind << 1][fl] ^= 1;
      la[ind << 1 | 1][fl] ^= 1;
    }
    la[ind][fl] = 0;
  }
}
void build(int ind, int l, int r) {
  if (l == r) {
    seg[ind][ch].first = (bin[l][ch] == 0) * hi[ve[ch][l - 1]][ch];
    seg[ind][ch].second = (bin[l][ch] == 1) * hi[ve[ch][l - 1]][ch];
    return;
  }
  int x = ind << 1, y = ind << 1 | 1, m = (l + r) / 2;
  build(x, l, m), build(y, m + 1, r);
  seg[ind][ch].first = max(seg[x][ch].first, seg[y][ch].first);
  seg[ind][ch].second = max(seg[x][ch].second, seg[y][ch].second);
}
void rup(int ind, int l, int r, int st, int en, bool fl) {
  laz(ind, l, r, fl);
  if (r < st || en < l) {
    return;
  }
  if (l >= st && r <= en) {
    la[ind][fl] ^= 1;
    laz(ind, l, r, fl);
    return;
  }
  int x = ind << 1, y = ind << 1 | 1, m = (l + r) / 2;
  rup(x, l, m, st, en, fl);
  rup(y, m + 1, r, st, en, fl);
  seg[ind][fl].first = max(seg[x][fl].first, seg[y][fl].first);
  seg[ind][fl].second = max(seg[x][fl].second, seg[y][fl].second);
}
int main() {
  f_io();
  int n;
  cin >> n;
  vector<pair<int, int>> ed;
  for (int i = 1; i < n; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    ed.push_back(make_pair(u, v));
    gr[u].push_back(make_pair(v, w));
    gr[v].push_back(make_pair(u, w));
  }
  dfs(1, 0);
  sort(vp.begin(), vp.end());
  ch = 0;
  dfs(vp.back().second.first, 0, 0);
  for (int i = 0; i < ve[0].size(); i++) {
  }
  int nn = ve[0].size();
  build(1, 1, nn);
  ch = 1;
  dfs(vp.back().second.second, 0, 0);
  build(1, 1, nn);
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int x;
    cin >> x;
    x--;
    int n1 =
        hi[ed[x].first][0] < hi[ed[x].second][0] ? ed[x].second : ed[x].first;
    int n2 =
        hi[ed[x].first][1] < hi[ed[x].second][1] ? ed[x].second : ed[x].first;
    rup(1, 1, nn, ar[n1][0].first, ar[n1][0].second, 0);
    rup(1, 1, nn, ar[n2][1].first, ar[n2][1].second, 1);
    laz(1, 1, nn, 0);
    laz(1, 1, nn, 1);
    cout << max(seg[1][0].first, seg[1][1].first) - 1 << '\n';
  }
}