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("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
using namespace std;
template <typename T>
void uin(T &a, T b) {
  if (b < a) {
    a = b;
  }
}
template <typename T>
void uax(T &a, T b) {
  if (b > a) {
    a = b;
  }
}
const int N = 500 * 1000 + 228;
int left1[N], right1[N];
int left2[N], right2[N];
int h1[N], h2[N];
int parity1[N], parity2[N];
int inv1[N], inv2[N];
struct ST {
  struct node {
    int mx0;
    int mx1;
    int mod;
    int l, r;
    node() {
      mx0 = mx1 = 0;
      l = r = mod = 0;
    }
  };
  vector<node> d;
  bool kekos;
  void recalc(int v) {
    pair<int, int> l_mx = gets(v << 1);
    pair<int, int> r_mx = gets(v << 1 | 1);
    d[v].mx0 = max(l_mx.first, r_mx.first);
    d[v].mx1 = max(l_mx.second, r_mx.second);
  };
  void build(int l, int r, int v = 1) {
    d[v].l = l;
    d[v].r = r;
    if (l == r) {
      int i = l;
      if (kekos == 0) {
        if (parity1[inv1[l]] == 0) {
          d[v].mx0 = h1[inv1[l]];
        } else {
          d[v].mx1 = h1[inv1[l]];
        }
      } else {
        if (parity2[inv2[l]] == 0) {
          d[v].mx0 = h2[inv2[l]];
        } else {
          d[v].mx1 = h2[inv2[l]];
        }
      }
    } else {
      int m = (l + r) >> 1;
      build(l, m, v << 1);
      build(m + 1, r, v << 1 | 1);
      recalc(v);
    }
  }
  ST() { d.clear(); }
  ST(int _n, bool kekoz) {
    kekos = kekoz;
    int ss = 1;
    while (ss < _n) ss <<= 1;
    ss <<= 1;
    d.resize(ss + 1, node());
    build(1, _n);
  }
  pair<int, int> gets(int v) {
    if (d[v].mod == 0) {
      return {d[v].mx0, d[v].mx1};
    }
    return {d[v].mx1, d[v].mx0};
  }
  void push(int v) {
    d[v << 1].mod ^= d[v].mod;
    d[v << 1 | 1].mod ^= d[v].mod;
    d[v].mod = 0;
    recalc(v);
  }
  void inverse(int l, int r, int v = 1) {
    if (l > r || d[v].l > r || d[v].r < l) return;
    if (l <= d[v].l && d[v].r <= r) {
      d[v].mod ^= 1;
    } else {
      push(v);
      inverse(l, r, v << 1);
      inverse(l, r, v << 1 | 1);
      recalc(v);
    }
  }
  int get0(int l, int r, int v = 1) { return gets(1).first; }
  int get1(int l, int r, int v = 1) { return gets(1).second; }
};
int n, m;
vector<pair<int, int> > g[N];
int id[N];
int ans[N];
int dist[N];
void dfs(int v, int par = -1) {
  if (par == -1)
    dist[v] = 0;
  else
    dist[v] = dist[par] + 1;
  for (pair<int, int> go : g[v]) {
    int to = go.first;
    int w = go.second;
    if (to != par) {
      dfs(to, v);
    }
  }
}
int A = 0, B = 0;
int timer = 0;
void dfs1(int v, int parity = 0, int par = -1) {
  left1[v] = ++timer;
  if (par == -1)
    h1[v] = 0;
  else
    h1[v] = h1[par] + 1;
  parity1[v] = parity;
  for (pair<int, int> go : g[v]) {
    int to = go.first;
    int w = go.second;
    if (to != par) {
      dfs1(to, parity ^ w, v);
    }
  }
  right1[v] = timer;
}
void dfs2(int v, int parity = 0, int par = -1) {
  left2[v] = ++timer;
  if (par == -1)
    h2[v] = 0;
  else
    h2[v] = h2[par] + 1;
  parity2[v] = parity;
  for (pair<int, int> go : g[v]) {
    int to = go.first;
    int w = go.second;
    if (to != par) {
      dfs2(to, parity ^ w, v);
    }
  }
  right2[v] = timer;
}
vector<pair<int, int> > edges;
void proceed() {
  dfs(1);
  A = 0;
  for (int i = 1; i <= n; ++i) {
    if (dist[i] > dist[A]) A = i;
  }
  dfs(A);
  B = 0;
  for (int i = 1; i <= n; ++i) {
    if (dist[i] > dist[B]) B = i;
  }
  dfs1(A);
  timer = 0;
  dfs2(B);
  for (int v = 1; v <= n; ++v) {
    inv1[left1[v]] = v;
    inv2[left2[v]] = v;
  }
  ST st1 = ST(n, 0);
  ST st2 = ST(n, 1);
  for (int i = 0; i < m; ++i) {
    pair<int, int> e = edges[id[i] - 1];
    int u = e.first, v = e.second;
    if (h1[u] > h1[v]) swap(u, v);
    st1.inverse(left1[v], right1[v]);
    if (h2[u] > h2[v]) swap(u, v);
    st2.inverse(left2[v], right2[v]);
    ans[i] = max(st1.get0(1, n), st2.get0(1, n));
  }
}
signed main() {
  ios_base::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;
    g[u].emplace_back(v, t);
    g[v].emplace_back(u, t);
    edges.emplace_back(u, v);
  }
  cin >> m;
  for (int i = 0; i < m; ++i) {
    cin >> id[i];
  }
  proceed();
  for (int i = 0; i < m; ++i) {
    cout << ans[i] << '\n';
  }
  return 0;
}