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", "unroll-all-loops")
#pragma GCC target("sse4.2")
using namespace std;
ifstream in;
ofstream out;
const long long kk = 1000;
const long long ml = kk * kk;
const long long mod = ml * kk + 7;
const long long inf = ml * ml * ml + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n;
int r1, r2;
vector<vector<int>> e;
vector<pair<int, int>> all_e;
vector<pair<int, int>> act;
bool viv = false;
struct Tree {
  int s = 1;
  int n = 0;
  vector<pair<int, int>> t;
  vector<bool> swp;
  void build(vector<int> dist, vector<pair<int, int>> seg) {
    if (viv) {
      for (auto i : dist) cout << i << ' ';
      cout << endl;
      for (auto p : seg) cout << p.first << ' ' << p.second << "; ";
      cout << endl;
    }
    n = dist.size();
    s = 1;
    while (s < n) s <<= 1;
    t.resize(2 * s);
    swp.resize(2 * s, false);
    for (int i = 0; i < n; i++) t[s + i] = {dist[i], 0};
    for (int i = s - 1; i > 0; i--) upd(i);
    if (viv) show();
  }
  void upd(int v) {
    if (v >= s) return;
    t[v].first = max(t[2 * v + 0].first, t[2 * v + 1].first);
    t[v].second = max(t[2 * v + 0].second, t[2 * v + 1].second);
  }
  void push(int v) {
    if (v >= s) return;
    if (!swp[v]) return;
    swp[2 * v + 0] = swp[2 * v + 0] ^ true;
    swp[2 * v + 1] = swp[2 * v + 1] ^ true;
    swap(t[2 * v + 0].first, t[2 * v + 0].second);
    swap(t[2 * v + 1].first, t[2 * v + 1].second);
    swp[v] = false;
  }
  void _xor(int l, int r, int v, int tl, int tr) {
    if (r <= tl || tr <= l) return;
    push(v);
    if (l <= tl && tr <= r) {
      swap(t[v].first, t[v].second);
      swp[v] = swp[v] ^ true;
      return;
    }
    int _time = tl + tr >> 1;
    _xor(l, r, 2 * v + 0, tl, _time);
    _xor(l, r, 2 * v + 1, _time, tr);
    upd(v);
  }
  void _xor(pair<int, int> p) {
    int l = p.first, r = p.second;
    r++;
    _xor(l, r, 1, 0, s);
  }
  int get_ans() {
    if (viv) show();
    return t[1].first;
  }
  void show() {
    for (long long i = 1; i < 2 * s; i++) {
      cout << '\t' << '{' << t[i].first << ' ' << t[i].second << "} ";
      if ((i & (i + 1)) == 0) cout << endl;
    }
  }
} t[2];
vector<int> d;
void DFS1(int v, int c = 0) {
  d[v] = c;
  for (auto u : e[v])
    if (d[u] == -1) DFS1(u, c + 1);
}
int far(int v) {
  d.clear();
  d.resize(n, -1);
  DFS1(v);
  int u = 0;
  for (int i = 0; i < n; i++)
    if (d[i] > d[u]) u = i;
  return u;
}
vector<int> dist[2];
vector<pair<int, int>> seg[2];
int _time;
void DFS2(int v, int root, int c = 0) {
  dist[root == r2][_time] = c;
  seg[root == r2][v].first = _time++;
  for (auto u : e[v])
    if (seg[root == r2][u].first == -1) DFS2(u, root, c + 1);
  dist[root == r2][_time] = c;
  seg[root == r2][v].second = _time++;
}
void work(int root) {
  dist[root == r2].resize(2 * n, -1);
  seg[root == r2].resize(n, (pair<int, int>){-1, -1});
  _time = 0;
  DFS2(root, root);
  t[root == r2].build(dist[root == r2], seg[root == r2]);
}
void prepare() {
  r1 = far(0);
  r2 = far(r1);
  work(r1);
  work(r2);
}
int dis(int root, int v) {
  int tp = (root == r2);
  int pl = seg[tp][v].first;
  return dist[tp][pl];
}
void change(pair<int, int> p, int root) {
  int down = p.first;
  int up = p.second;
  if (dis(root, up) > dis(root, down)) swap(down, up);
  auto sg = seg[root == r2][down];
  t[root == r2]._xor(sg);
}
void change(pair<int, int> p) {
  change(p, r1);
  change(p, r2);
}
void get_ans() {
  int ans = 0;
  ans = max(ans, t[0].get_ans());
  ans = max(ans, t[1].get_ans());
  cout << ans << '\n';
}
void solve() {
  cin >> n;
  e.resize(n);
  for (int i = 1; i < n; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    e[a].push_back(b);
    e[b].push_back(a);
    if (c) act.push_back({a, b});
    all_e.push_back((pair<int, int>){a, b});
  }
  prepare();
  for (auto p : act) change(p);
  int q;
  cin >> q;
  while (q--) {
    int num;
    cin >> num;
    num--;
    change(all_e[num]);
    get_ans();
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) solve();
  return 0;
}