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;
struct Edge {
  int to;
  int tp;
  int index;
};
int timer = 0;
vector<vector<Edge> > gr;
vector<pair<int, int> > seg;
vector<int> tin;
vector<int> val;
vector<int> euler;
void dfs(int vertex, int last, int W) {
  tin[vertex] = timer++;
  val[vertex] = W;
  euler.push_back(vertex);
  for (auto ed : gr[vertex]) {
    if (ed.to == last) continue;
    int index = ed.index;
    seg[index].first = timer;
    dfs(ed.to, vertex, W ^ ed.tp);
    seg[index].second = timer - 1;
  }
}
int mx = -1;
int opt;
void dfs2(int vertex, int last, int d) {
  if (d > mx) {
    mx = d;
    opt = vertex;
  }
  for (auto ed : gr[vertex]) {
    int to = ed.to;
    if (to == last) continue;
    dfs2(to, vertex, d + 1);
  }
}
pair<int, int> find_diameter() {
  dfs2(0, -1, 0);
  int kek = opt;
  mx = -1;
  dfs2(kek, -1, 0);
  return make_pair(kek, opt);
}
int n;
vector<int> dist;
void dfs3(int vertex, int last, int d) {
  dist[vertex] = d;
  for (auto ed : gr[vertex]) {
    int to = ed.to;
    if (to == last) continue;
    dfs3(to, vertex, d + 1);
  }
}
struct Vertex {
  int max[2];
  bool need_push;
};
vector<Vertex> rmq;
void build(int i, int l, int r) {
  if (r - l == 1) {
    int W = euler[l];
    rmq[i].need_push = false;
    rmq[i].max[val[W]] = dist[W];
    rmq[i].max[1 - val[W]] = -1;
    return;
  }
  int mid = (l + r) / 2;
  build(2 * i + 1, l, mid);
  build(2 * i + 2, mid, r);
  rmq[i].need_push = false;
  for (int j = 0; j < 2; ++j) {
    rmq[i].max[j] = max(rmq[2 * i + 1].max[j], rmq[2 * i + 2].max[j]);
  }
}
void push(int i, int l, int r) {
  if (r - l <= 1) return;
  if (!rmq[i].need_push) return;
  rmq[i].need_push = false;
  for (int j = 2 * i + 1; j <= 2 * i + 2; ++j) {
    rmq[j].need_push ^= 1;
    swap(rmq[j].max[0], rmq[j].max[1]);
  }
}
void upd(int i, int l, int r, int l1, int r1) {
  push(i, l, r);
  if (l1 >= r1) return;
  if (l == l1 && r == r1) {
    swap(rmq[i].max[0], rmq[i].max[1]);
    rmq[i].need_push = true;
    return;
  }
  int mid = (l + r) / 2;
  upd(2 * i + 1, l, mid, l1, min(r1, mid));
  upd(2 * i + 2, mid, r, max(l1, mid), r1);
  for (int j = 0; j < 2; ++j) {
    rmq[i].max[j] = max(rmq[2 * i + 1].max[j], rmq[2 * i + 2].max[j]);
  }
}
int get_val(int i, int l, int r, int index) {
  push(i, l, r);
  if (r - l == 1) {
    if (rmq[i].max[0] == -1) return 1;
    return 0;
  }
  int mid = (l + r) / 2;
  if (index < mid) return get_val(2 * i + 1, l, mid, index);
  return get_val(2 * i + 2, mid, r, index);
}
vector<int> solve(int vertex, vector<int> queries) {
  vector<int> ans;
  dist.assign(n, -1);
  dfs3(vertex, -1, 0);
  rmq.assign(4 * n, {});
  build(0, 0, n);
  for (auto first : queries) {
    upd(0, 0, n, seg[first].first, seg[first].second + 1);
    int T = get_val(0, 0, n, tin[vertex]);
    ans.push_back(rmq[0].max[T]);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  gr.assign(n, {});
  for (int i = 0; i < n - 1; ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    u--, v--;
    gr[u].push_back({v, w, i});
    gr[v].push_back({u, w, i});
  }
  seg.assign(n - 1, make_pair(-1, -1));
  tin.assign(n, -1);
  val.assign(n, -1);
  dfs(0, -1, 0);
  pair<int, int> p = find_diameter();
  vector<int> queries;
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int first;
    cin >> first;
    first--;
    queries.push_back(first);
  }
  auto a = solve(p.first, queries);
  auto b = solve(p.second, queries);
  for (int i = 0; i < q; ++i) cout << max(a[i], b[i]) << '\n';
}