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 ii = pair<int, int>;
using vi = vector<int>;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
struct Node {
  Node *l = 0, *r = 0;
  int lo, hi;
  int mx[2];
  bool lz = 0;
  Node(int _lo, int _hi) : lo(_lo), hi(_hi) { mx[0] = mx[1] = 0; }
  Node(ii v[], int _lo, int _hi) : lo(_lo), hi(_hi) {
    mx[0] = mx[1] = 0;
    if (lo + 1 < hi) {
      int mid = lo + (hi - lo) / 2;
      l = new Node(v, lo, mid);
      r = new Node(v, mid, hi);
      for (int i : {0, 1}) mx[i] = max(l->mx[i], r->mx[i]);
    } else {
      mx[v[lo].first] = v[lo].second;
    }
  }
  void upd() {
    swap(mx[0], mx[1]);
    lz ^= 1;
  }
  void flip(int L, int R) {
    if (R <= lo || hi <= L) return;
    if (L <= lo && hi <= R) {
      upd();
    } else {
      push(), l->flip(L, R), r->flip(L, R);
      for (int i : {0, 1}) mx[i] = max(l->mx[i], r->mx[i]);
    }
  }
  void push() {
    if (lo + 1 < hi and lz) {
      l->upd(), r->upd();
    }
    lz = 0;
  }
};
const int N = 5e5 + 5;
int n, q;
int l[N], r[N], w[N];
vi g[N];
int d1, d2;
int tym;
ii dis[N];
int IN[N], OUT[N];
int EDGE[N];
ii dis_[N];
void dfs(int u, int daddy, int pe) {
  IN[u] = ++tym;
  EDGE[pe] = u;
  for (int i : g[u]) {
    int v = l[i] ^ r[i] ^ u;
    if (v != daddy) {
      dis[v] = {dis[u].first ^ w[i], dis[u].second + 1};
      dfs(v, u, i);
    }
  }
  OUT[u] = tym;
}
int main(int argc, char const *argv[]) {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    scanf("%d %d %d", &l[i], &r[i], &w[i]);
    g[l[i]].emplace_back(i);
    g[r[i]].emplace_back(i);
  }
  dis[1] = {0, 0};
  dfs(1, 0, 0);
  {
    int mx = INT_MIN;
    for (int i = 1; i <= n; ++i) {
      if (dis[i].second > mx) {
        d1 = i;
        mx = dis[i].second;
      }
    }
  }
  42;
  vi in[2], out[2], e[2];
  Node *t[2];
  dis[d1] = {0, 0}, tym = 0;
  dfs(d1, 0, 0);
  for (int i = 1; i <= n; ++i) {
    dis_[IN[i]] = dis[i];
  }
  42;
  t[0] = new Node(dis_, 1, n + 1);
  42;
  in[0] = vi(IN, IN + 1 + n);
  out[0] = vi(OUT, OUT + 1 + n);
  e[0] = vi(EDGE, EDGE + 1 + n);
  {
    int mx = INT_MIN;
    for (int i = 1; i <= n; ++i) {
      if (dis[i].second > mx) {
        d2 = i;
        mx = dis[i].second;
      }
    }
  }
  dis[d2] = {0, 0}, tym = 0;
  dfs(d2, 0, 0);
  for (int i = 1; i <= n; ++i) {
    dis_[IN[i]] = dis[i];
  }
  42;
  t[1] = new Node(dis_, 1, n + 1);
  in[1] = vi(IN, IN + 1 + n);
  out[1] = vi(OUT, OUT + 1 + n);
  e[1] = vi(EDGE, EDGE + 1 + n);
  scanf("%d", &q);
  while (q--) {
    int id;
    scanf("%d", &id);
    42;
    int ans = 0;
    for (int i : {0, 1}) {
      42;
      t[i]->flip(in[i][e[i][id]], out[i][e[i][id]] + 1);
      ans = max(ans, t[i]->mx[0]);
    }
    42;
    42;
    printf("%d\n", ans);
  }
  return 0;
}