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 <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const double EPS = 1e-9;
const double PI = acos(-1.);
const long long LL_INF = 1e17 + 16;
const int INF = 1e9 + 10;
const long long MOD = 1e9 + 7;
const int MAXN = 5e5 + 5;
struct edge {
  int s, to, t;
  edge() {}
  edge(int _s, int _to, int _t) { s = _s, to = _to, t = _t; }
  int get_to(int from) { return from == s ? to : s; }
} ee[MAXN];
vector<int> g[MAXN];
int used[MAXN];
int dis[2][MAXN];
void dfs1(int ind, int s) {
  used[s] = 1;
  for (int i = (0); i < (int)((int)(g[s]).size()); i++) {
    int to = ee[g[s][i]].get_to(s);
    if (!used[to]) {
      dis[ind][to] = dis[ind][s] + 1;
      dfs1(ind, to);
    }
  }
}
int tin[2][MAXN], tout[2][MAXN], _timer[2];
int ee_to[2][MAXN];
void dfs2(int ind, int s) {
  used[s] = 1;
  tin[ind][s] = tout[ind][s] = _timer[ind]++;
  for (int i = (0); i < (int)((int)(g[s]).size()); i++) {
    int to = ee[g[s][i]].get_to(s);
    if (!used[to]) {
      ee_to[ind][g[s][i]] = to;
      dfs2(ind, to);
      tout[ind][s] = tout[ind][to];
    }
  }
}
struct item {
  int val[2];
  int t;
  item() { val[0] = val[1] = t = 0; }
  void swap() {
    t ^= 1;
    std::swap(val[0], val[1]);
  }
};
template <typename temp_type>
struct segment_tree {
  int n;
  int vals[MAXN];
  temp_type tt[4 * MAXN];
  temp_type combine(const temp_type &v1, const temp_type &v2) {
    temp_type res;
    res.t = 0;
    for (int i = (0); i < (int)(2); i++) {
      res.val[i] = max(v1.val[i], v2.val[i]);
    }
    return res;
  }
  void push(int ind) {
    if (tt[ind].t) {
      tt[ind].swap();
      tt[ind << 1].swap();
      tt[(ind << 1) + 1].swap();
    }
  }
  void build(int ind, int tl, int tr) {
    if (tl == tr) {
      tt[ind].t = 0;
      tt[ind].val[0] = vals[tl];
      tt[ind].val[1] = -1;
      return;
    }
    int tm = (tl + tr) >> 1;
    build(ind << 1, tl, tm);
    build((ind << 1) + 1, tm + 1, tr);
    tt[ind] = combine(tt[ind << 1], tt[(ind << 1) + 1]);
  }
  temp_type get_val(int ind, int tl, int tr, int l, int r) {
    if (tl == l && tr == r) {
      return tt[ind];
    }
    push(ind);
    int tm = (tl + tr) >> 1;
    temp_type result;
    if (r <= tm) {
      result = get_val(ind << 1, tl, tm, l, r);
    } else if (l > tm) {
      result = get_val((ind << 1) + 1, tm + 1, tr, l, r);
    } else {
      result = combine(get_val(ind << 1, tl, tm, l, tm),
                       get_val((ind << 1) + 1, tm + 1, tr, tm + 1, r));
    }
    return result;
  }
  void upd_val(int ind, int tl, int tr, int l, int r) {
    if (tl == l && tr == r) {
      tt[ind].swap();
      return;
    }
    push(ind);
    int tm = (tl + tr) >> 1;
    if (r <= tm) {
      upd_val(ind << 1, tl, tm, l, r);
    } else if (l > tm) {
      upd_val((ind << 1) + 1, tm + 1, tr, l, r);
    } else {
      upd_val(ind << 1, tl, tm, l, tm);
      upd_val((ind << 1) + 1, tm + 1, tr, tm + 1, r);
    }
    tt[ind] = combine(tt[ind << 1], tt[(ind << 1) + 1]);
  }
  void build() { build(1, 0, n - 1); }
  temp_type get_val(int l, int r) { return get_val(1, 0, n - 1, l, r); }
  void upd_val(int l, int r) { upd_val(1, 0, n - 1, l, r); }
};
segment_tree<item> tt[2];
void solve() {
  int n;
  scanf("%d", &n);
  for (int i = (1); i < (int)(n); i++) {
    scanf("%d%d%d", &ee[i].s, &ee[i].to, &ee[i].t);
    g[ee[i].s].push_back(i);
    g[ee[i].to].push_back(i);
  }
  dfs1(0, 1);
  int s = 1;
  for (int i = (1); i <= (int)(n); i++) {
    if (dis[0][s] < dis[0][i]) {
      s = i;
    }
    used[i] = 0;
  }
  dis[0][s] = 0;
  dfs1(0, s);
  int f = 1;
  for (int i = (1); i <= (int)(n); i++) {
    if (dis[0][f] < dis[0][i]) {
      f = i;
    }
    used[i] = 0;
  }
  dfs1(1, f);
  for (int i = (1); i <= (int)(n); i++) {
    used[i] = 0;
  }
  dfs2(0, s);
  for (int i = (1); i <= (int)(n); i++) {
    used[i] = 0;
  }
  dfs2(1, f);
  for (int k = (0); k < (int)(2); k++) {
    tt[k].n = n;
    for (int i = (1); i <= (int)(n); i++) {
      tt[k].vals[tin[k][i]] = dis[k][i];
    }
    tt[k].build();
  }
  for (int i = (1); i < (int)(n); i++) {
    if (ee[i].t) {
      for (int k = (0); k < (int)(2); k++) {
        int l = tin[k][ee_to[k][i]];
        int r = tout[k][ee_to[k][i]];
        tt[k].upd_val(l, r);
      }
    }
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int x;
    scanf("%d", &x);
    for (int k = (0); k < (int)(2); k++) {
      int l = tin[k][ee_to[k][x]];
      int r = tout[k][ee_to[k][x]];
      tt[k].upd_val(l, r);
    }
    int ans =
        max(tt[0].get_val(0, n - 1).val[0], tt[1].get_val(0, n - 1).val[0]);
    printf("%d\n", ans);
  }
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
}