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>
istream &operator>>(istream &in, pair<T1, T2> &a) {
  in >> a.first >> a.second;
  return in;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &out, pair<T1, T2> a) {
  out << a.first << " " << a.second;
  return out;
}
template <typename T, typename T1>
T amax(T &a, T1 b) {
  if (b > a) a = b;
  return a;
}
template <typename T, typename T1>
T amin(T &a, T1 b) {
  if (b < a) a = b;
  return a;
}
const long long INF = 1e18;
const int32_t M = 1e9 + 7;
const int32_t MM = 998244353;
const long long N = 5e5 + 5;
const int32_t maxn = N;
template <typename NODE, typename UPDATE>
struct segtree {
  bool built = false, lazy[4 * maxn];
  NODE zero = NODE(), t[4 * maxn];
  UPDATE noop = UPDATE(), upds[4 * maxn];
  int32_t tl[4 * maxn], tr[4 * maxn];
  inline void pushdown(int32_t v) {
    if (lazy[v]) {
      apply(v * 2, upds[v]);
      apply(v * 2 + 1, upds[v]);
      lazy[v] = 0;
      upds[v] = noop;
    }
  }
  inline void apply(int32_t v, UPDATE &val) {
    if (tl[v] != tr[v]) {
      lazy[v] = 1;
      upds[v].combine(val, tl[v], tr[v]);
    }
    val.apply(t[v], tl[v], tr[v]);
  }
  template <typename T>
  void build(T a, int32_t v, int32_t l, int32_t r) {
    tl[v] = l;
    tr[v] = r;
    if (l == r) {
      t[v] = a[l];
      return;
    } else {
      int32_t tm = (l + r) / 2;
      build(a, v * 2, l, tm);
      build(a, v * 2 + 1, tm + 1, r);
      t[v].merge(t[v * 2], t[v * 2 + 1]);
    }
  }
  NODE query(int32_t v, long long l, long long r) {
    if (l > tr[v] || r < tl[v]) return zero;
    if (l <= tl[v] && tr[v] <= r) {
      return t[v];
    }
    pushdown(v);
    NODE a, b, ans;
    a = query(v * 2, l, r);
    b = query(v * 2 + 1, l, r);
    ans.merge(a, b);
    return ans;
  }
  void rupd(int32_t v, long long l, long long r, UPDATE &val) {
    if (l > tr[v] || r < tl[v]) return;
    if (l <= tl[v] && tr[v] <= r) {
      apply(v, val);
      return;
    }
    pushdown(v);
    rupd(v * 2, l, r, val);
    rupd(v * 2 + 1, l, r, val);
    t[v].merge(t[v * 2], t[v * 2 + 1]);
  }
  template <typename T>
  long long descent_right(long long l, T x, int32_t v, NODE &prev) {
    if (l > tr[v]) return len;
    if (l <= tl[v]) {
      NODE cur;
      cur.merge(prev, t[v]);
      if (!cur.check(x)) {
        swap(prev, cur);
        return len;
      }
      if (tl[v] == tr[v]) {
        return tr[v];
      }
    }
    pushdown(v);
    long long ans = descent_right(l, x, v * 2, prev);
    if (ans != len) return ans;
    return descent_right(l, x, v * 2 + 1, prev);
  }
  template <typename T>
  long long descent_left(long long r, T x, int32_t v, NODE &prev) {
    if (r < tl[v]) return -1;
    if (r >= tr[v]) {
      NODE cur;
      cur.merge(t[v], prev);
      if (!cur.check(x)) {
        swap(cur, prev);
        return -1;
      }
      if (tl[v] == tr[v]) {
        return tl[v];
      }
    }
    pushdown(v);
    long long ans = descent_left(r, x, v * 2 + 1, prev);
    if (ans != -1) return ans;
    return descent_left(r, x, v * 2, prev);
  }
  long long len = maxn;
  void clear() {
    fill(t, t + 4 * len, zero);
    fill(lazy, lazy + 4 * len, false);
    fill(upds, upds + 4 * len, noop);
  }
  template <typename T>
  void build(T a) {
    build(a, 1, 0, len - 1);
    built = true;
  }
  template <typename T>
  long long descent_right(long long l, T x) {
    NODE prev = zero;
    return descent_right(l, x, 1, prev);
  }
  template <typename T>
  long long descent_left(long long r, T x) {
    NODE prev = zero;
    return descent_left(r, x, 1, prev);
  }
  NODE query(long long l, long long r) {
    if (!built) build(t);
    return query(1, l, r);
  }
  void rupd(long long l, long long r, UPDATE val) {
    if (!built) build(t);
    rupd(1, l, r, val);
  }
};
struct node1 {
  long long e = 0, o = 0;
  node1() {}
  node1(long long val) { e = val; }
  void merge(node1 &l, node1 &r) {
    e = max(l.e, r.e);
    o = max(l.o, r.o);
  }
  bool check(long long x) { return false; }
};
struct update1 {
  long long v = 0;
  update1() {}
  update1(long long val) { v = val; }
  void combine(update1 &other, int32_t tl, int32_t tr) { v ^= other.v; }
  void apply(node1 &x, int32_t tl, int32_t tr) {
    if (v) {
      swap(x.e, x.o);
    }
  }
};
segtree<node1, update1> t;
long long n, m;
pair<long long, long long> edgs[N];
vector<long long> f, q;
long long tim;
long long st[N], et[N], dep[N], ev[N];
vector<pair<long long, long long> > v[N];
void dfs(long long z, long long p = 0, long long d = 0) {
  st[z] = tim++;
  dep[st[z]] = d;
  for (pair<long long, long long> x : v[z]) {
    if (x.first == p) continue;
    ev[x.second] = x.first;
    dfs(x.first, z, d + 1);
  }
  et[z] = tim - 1;
}
pair<long long, long long> auxdfs(long long z, long long p = 0,
                                  long long d = 0) {
  pair<long long, long long> ret = {d, z};
  for (pair<long long, long long> x : v[z]) {
    if (x.first == p) continue;
    pair<long long, long long> tmp = auxdfs(x.first, z, d + 1);
    amax(ret, tmp);
  }
  return ret;
}
long long ans[N];
void solve() {
  cin >> n;
  for (long long i = 1; i < n; i++) {
    long long x, y, z;
    cin >> x >> y >> z;
    edgs[i] = {x, y};
    v[x].push_back({y, i});
    v[y].push_back({x, i});
    if (z) f.push_back(i);
  }
  cin >> m;
  for (long long i = 0; i < m; i++) {
    long long x;
    cin >> x;
    q.push_back(x);
  }
  long long root = 1;
  for (long long zz = 0; zz < 2; zz++) {
    root = auxdfs(root).second;
    tim = 0;
    dfs(root);
    t.clear();
    t.build(dep);
    for (long long x : f) {
      long long y = ev[x];
      t.rupd(st[y], et[y], 1);
    }
    for (long long i = 0; i < m; i++) {
      long long x = q[i];
      long long y = ev[x];
      t.rupd(st[y], et[y], 1);
      amax(ans[i], t.query(st[root], et[root]).e);
    }
  }
  for (long long i = 0; i < m; i++) {
    cout << ans[i] << "\n";
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) solve();
  return 0;
}