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;
namespace io {
const int __SIZE = (1 << 21) + 1;
char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1,
                                           __c, qu[55];
int __f, qr, _eof;
inline void flush() { fwrite(obuf, 1, oS - obuf, stdout), oS = obuf; }
inline void gc(char &x) {
  x = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                   (iS == iT ? EOF : *iS++))
                : *iS++);
}
inline void pc(char x) {
  *oS++ = x;
  if (oS == oT) flush();
}
inline void pstr(const char *s) {
  int __len = strlen(s);
  for (__f = 0; __f < __len; ++__f) pc(s[__f]);
}
inline void gstr(char *s) {
  for (__c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                         (iS == iT ? EOF : *iS++))
                       : *iS++);
       __c < 32 || __c > 126 || __c == ' ';)
    __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                    : *iS++);
  for (; __c > 31 && __c < 127 && __c != ' ';
       ++s, __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                              (iS == iT ? EOF : *iS++))
                            : *iS++))
    *s = __c;
  *s = 0;
}
template <class I>
inline bool gi(I &x) {
  _eof = 0;
  for (__f = 1,
      __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                        (iS == iT ? EOF : *iS++))
                      : *iS++);
       (__c < '0' || __c > '9') && !_eof;
       __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                         (iS == iT ? EOF : *iS++))
                       : *iS++)) {
    if (__c == '-') __f = -1;
    _eof |= __c == EOF;
  }
  for (x = 0; __c <= '9' && __c >= '0' && !_eof;
       __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                         (iS == iT ? EOF : *iS++))
                       : *iS++))
    x = x * 10 + (__c & 15), _eof |= __c == EOF;
  x *= __f;
  return !_eof;
}
template <class I>
inline void print(I x) {
  if (!x) pc('0');
  if (x < 0) pc('-'), x = -x;
  while (x) qu[++qr] = x % 10 + '0', x /= 10;
  while (qr) pc(qu[qr--]);
}
struct Flusher_ {
  ~Flusher_() { flush(); }
} io_flusher_;
}  // namespace io
using io::gc;
using io::gi;
using io::gstr;
using io::pc;
using io::print;
using io::pstr;
using ll = long long;
using pii = pair<int, int>;
const int MOD = 1000000007;
pii dat[500005 << 2];
bool laz[500005 << 2];
void push(int idx, int l, int r) {
  if (!laz[idx] || l == r) return;
  dat[idx * 2] = {dat[idx * 2].second, dat[idx * 2].first};
  laz[idx * 2] = !laz[idx * 2];
  dat[idx * 2 + 1] = {dat[idx * 2 + 1].second, dat[idx * 2 + 1].first};
  laz[idx * 2 + 1] = !laz[idx * 2 + 1];
  laz[idx] = 0;
}
void upd(int idx, int l, int r, int i, pii v) {
  if (!(l <= i && i <= r)) return;
  push(idx, l, r);
  if (l == r) {
    dat[idx] = v;
    return;
  }
  upd(idx * 2, l, (l + r) / 2, i, v);
  upd(idx * 2 + 1, (l + r) / 2 + 1, r, i, v);
  dat[idx] = {max(dat[idx * 2].first, dat[idx * 2 + 1].first),
              max(dat[idx * 2].second, dat[idx * 2 + 1].second)};
}
void tag(int idx, int l, int r, int ql, int qr) {
  if (qr < l || r < ql) return;
  push(idx, l, r);
  if (ql <= l && r <= qr) {
    dat[idx] = {dat[idx].second, dat[idx].first};
    laz[idx] = !laz[idx];
    return;
  }
  tag(idx * 2, l, (l + r) / 2, ql, qr);
  tag(idx * 2 + 1, (l + r) / 2 + 1, r, ql, qr);
  dat[idx] = {max(dat[idx * 2].first, dat[idx * 2 + 1].first),
              max(dat[idx * 2].second, dat[idx * 2 + 1].second)};
}
pii el2[500005];
vector<pii> elist[500005];
pii dfsfar(int u, int f) {
  pii ans = {0, u};
  for (pii &v : elist[u])
    if (v.first != f) ans = max(ans, dfsfar(v.first, u));
  return {ans.first + 1, ans.second};
}
int clck = 1;
int n;
int L[500005], R[500005];
int qr[500005], ans[500005];
void dfs(int u, int f, int dep, int cnt) {
  L[u] = clck++;
  if (cnt % 2 == 0)
    upd(1, 1, n, L[u], {dep, 0});
  else
    upd(1, 1, n, L[u], {0, dep});
  for (pii &v : elist[u])
    if (v.first != f) dfs(v.first, u, dep + 1, cnt + v.second);
  R[u] = clck - 1;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  gi(n);
  for (int i = (0); i < (n - 1); i++) {
    int u, v, w;
    gi(u), gi(v), gi(w);
    el2[i] = {u, v};
    elist[u].push_back({v, w});
    elist[v].push_back({u, w});
  }
  int root = dfsfar(1, -1).second;
  dfs(root, -1, 0, 0);
  int q;
  gi(q);
  for (int i = (0); i < (q); i++) gi(qr[i]);
  for (int i = (0); i < (q); i++) {
    int par = el2[qr[i] - 1].first, ch = el2[qr[i] - 1].second;
    if (R[par] - L[par] < R[ch] - L[ch]) swap(par, ch);
    tag(1, 1, n, L[ch], R[ch]);
    ans[i] = max(ans[i], dat[1].first);
  }
  root = dfsfar(root, -1).second;
  memset(dat, 0, sizeof dat);
  memset(laz, 0, sizeof laz);
  clck = 1;
  dfs(root, -1, 0, 0);
  for (int i = (0); i < (q); i++) {
    int par = el2[qr[i] - 1].first, ch = el2[qr[i] - 1].second;
    if (R[par] - L[par] < R[ch] - L[ch]) swap(par, ch);
    tag(1, 1, n, L[ch], R[ch]);
    ans[i] = max(ans[i], dat[1].first);
    print(ans[i]), pc('\n');
  }
}