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;
template <typename T1, typename T2>
string print_iterable(T1 begin_iter, T2 end_iter, int counter) {
  bool done_something = false;
  stringstream res;
  res << "[";
  for (; begin_iter != end_iter and counter; ++begin_iter) {
    done_something = true;
    counter--;
    res << *begin_iter << ", ";
  }
  string str = res.str();
  if (done_something) {
    str.pop_back();
    str.pop_back();
  }
  str += "]";
  return str;
}
vector<int> SortIndex(int size, std::function<bool(int, int)> compare) {
  vector<int> ord(size);
  for (int i = 0; i < size; i++) ord[i] = i;
  sort(ord.begin(), ord.end(), compare);
  return ord;
}
template <typename T>
bool MinPlace(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool MaxPlace(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T>& p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  out << "[";
  for (int i = 0; i < (int)v.size(); i++) {
    out << v[i];
    if (i != (int)v.size() - 1) out << ", ";
  }
  out << "]";
  return out;
}
template <class TH>
void _dbg(const char* name, TH val) {
  clog << name << ": " << val << endl;
}
template <class TH, class... TA>
void _dbg(const char* names, TH curr_val, TA... vals) {
  while (*names != ',') clog << *names++;
  clog << ": " << curr_val << ", ";
  _dbg(names + 1, vals...);
}
struct Edge {
  int u, v, id;
  int t;
};
int N, Q;
const int MAXN = 1 << 19;
int dep[MAXN];
vector<int> aa[MAXN];
vector<int> ids[MAXN];
Edge edges[MAXN];
int queries[MAXN];
vector<int> prequery;
void dfs(int v, int p) {
  for (int a : aa[v]) {
    if (a == p) continue;
    dep[a] = dep[v] + 1;
    dfs(a, v);
  }
}
int from[MAXN];
int to[MAXN];
int cnt;
int dist[MAXN];
int ff0[2 * MAXN], ff1[2 * MAXN];
void preproc(int v, int p) {
  cnt++;
  int id = cnt;
  ff0[MAXN + id] = dist[v];
  for (int i = 0; i < ((int)((aa[v]).size())); i++) {
    int a = aa[v][i];
    if (a == p) continue;
    dist[a] = dist[v] + 1;
    from[ids[v][i]] = cnt + 1;
    preproc(a, v);
    to[ids[v][i]] = cnt;
  }
}
bool flag[2 * MAXN];
void f(int v, int l, int r, int a, int b) {
  if (a <= l and r <= b) {
    swap(ff0[v], ff1[v]);
    flag[v] ^= 1;
    return;
  }
  if (r < a or b < l) return;
  if (flag[v]) {
    flag[v] = false;
    swap(ff0[2 * v], ff1[2 * v]);
    swap(ff0[2 * v + 1], ff1[2 * v + 1]);
    flag[2 * v] ^= 1, flag[2 * v + 1] ^= 1;
  }
  int m = (l + r) / 2;
  f(2 * v, l, m, a, b);
  f(2 * v + 1, m + 1, r, a, b);
  ff0[v] = max(ff0[2 * v], ff0[2 * v + 1]);
  ff1[v] = max(ff1[2 * v], ff1[2 * v + 1]);
}
void process(int x) { f(1, 0, MAXN - 1, from[x], to[x]); }
vector<int> solve(int root) {
  dist[root] = 0;
  cnt = 0;
  for (int i = 1; i < 2 * MAXN; i++) ff0[i] = ff1[i] = 0, flag[i] = false;
  preproc(root, -1);
  for (int i = MAXN - 1; i >= 1; i--) {
    ff0[i] = max(ff0[2 * i], ff0[2 * i + 1]);
  }
  for (int q : prequery) process(q);
  vector<int> ans(Q);
  for (int q = 0; q < Q; q++) {
    process(queries[q]);
    ans[q] = ff0[1];
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  for (int i = 0; i < N - 1; i++) {
    int u, v, t;
    cin >> u >> v >> t;
    aa[u].push_back(v);
    aa[v].push_back(u);
    ids[u].push_back(i + 1);
    ids[v].push_back(i + 1);
    if (t) prequery.push_back(i + 1);
  }
  dfs(1, 0);
  int A = 1;
  for (int v = 2; v <= N; v++)
    if (dep[v] > dep[A]) A = v;
  dep[A] = 0;
  dfs(A, 0);
  int B = 1;
  for (int v = 2; v <= N; v++)
    if (dep[v] > dep[B]) B = v;
  cin >> Q;
  for (int i = 0; i < Q; i++) cin >> queries[i];
  vector<int> ans1 = solve(A);
  vector<int> ans2 = solve(B);
  for (int i = 0; i < Q; i++) cout << max(ans1[i], ans2[i]) << "\n";
}