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;
const int next_x[8] = {0, 1, -1, 0, 1, 1, -1, -1};
const int next_y[8] = {1, 0, 0, -1, 1, -1, -1, 1};
const int inf = 1e9 + 5;
const long long linf = 1e18 + 5;
const double PI = acos(-1.0);
const int MAXN = 1e6 + 5;
const int N = 4e6 + 5;
const long double eps = 1e-8;
const long double fix = 1e-2;
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;
inline void flush() {
  fwrite(obuf, 1, oS - obuf, stdout);
  oS = obuf;
}
inline void putc(char x) {
  *oS++ = x;
  if (oS == oT) flush();
}
template <typename A>
inline bool read(A &x) {
  for (f = 1, c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                              (iS == iT ? EOF : *iS++))
                            : *iS++);
       c < '0' || c > '9';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    if (c == '-')
      f = -1;
    else if (c == EOF)
      return 0;
  for (x = 0; c <= '9' && c >= '0';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    x = x * 10 + (c & 15);
  x *= f;
  return 1;
}
inline bool read(char &x) {
  while ((x = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                           (iS == iT ? EOF : *iS++))
                        : *iS++)) == ' ' ||
         x == '\n' || x == '\r')
    ;
  return x != EOF;
}
inline bool read(char *x) {
  while ((*x = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                            (iS == iT ? EOF : *iS++))
                         : *iS++)) == '\n' ||
         *x == ' ' || *x == '\r')
    ;
  if (*x == EOF) return 0;
  while (!(*x == '\n' || *x == ' ' || *x == '\r' || *x == EOF))
    *(++x) = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                          (iS == iT ? EOF : *iS++))
                       : *iS++);
  *x = 0;
  return 1;
}
template <typename A, typename... B>
inline bool read(A &x, B &...y) {
  return read(x) && read(y...);
}
template <typename A>
inline bool write(A x) {
  if (!x) putc('0');
  if (x < 0) putc('-'), x = -x;
  while (x) qu[++qr] = x % 10 + '0', x /= 10;
  while (qr) putc(qu[qr--]);
  return 0;
}
inline bool write(char x) {
  putc(x);
  return 0;
}
inline bool write(const char *x) {
  while (*x) {
    putc(*x);
    ++x;
  }
  return 0;
}
inline bool write(char *x) {
  while (*x) {
    putc(*x);
    ++x;
  }
  return 0;
}
template <typename A, typename... B>
inline bool write(A x, B... y) {
  return write(x) || write(y...);
}
struct Flusher_ {
  ~Flusher_() { flush(); }
} io_flusher_;
}  // namespace io
namespace seg {
int mx[MAXN * 4][2], rev[MAXN * 4];
void dorev(int cnt) { rev[cnt] ^= 1, swap(mx[cnt][0], mx[cnt][1]); }
void up(int cnt) {
  for (int k = (0), I = (1) + 1; k < I; ++k)
    mx[cnt][k] = max(mx[(cnt << 1)][k], mx[(cnt << 1 | 1)][k]);
}
void down(int cnt) {
  if (rev[cnt]) dorev((cnt << 1)), dorev((cnt << 1 | 1)), rev[cnt] = 0;
}
void build(int l, int r, int a[], int d[], int cnt) {
  rev[cnt] = 0;
  if (l == r) {
    mx[cnt][a[l]] = d[l], mx[cnt][!a[l]] = 0;
    return;
  }
  build(l, ((l + r) / 2), a, d, (cnt << 1)),
      build(((l + r) / 2) + 1, r, a, d, (cnt << 1 | 1)), up(cnt);
}
void flip(int l, int r, int nl, int nr, int cnt) {
  if (l == nl && r == nr) return dorev(cnt);
  down(cnt);
  if (nr <= ((l + r) / 2))
    flip(l, ((l + r) / 2), nl, nr, (cnt << 1));
  else if (nl > ((l + r) / 2))
    flip(((l + r) / 2) + 1, r, nl, nr, (cnt << 1 | 1));
  else
    flip(l, ((l + r) / 2), nl, ((l + r) / 2), (cnt << 1)),
        flip(((l + r) / 2) + 1, r, ((l + r) / 2) + 1, nr, (cnt << 1 | 1));
  up(cnt);
}
}  // namespace seg
int n, m, tim = 0;
int u[MAXN], v[MAXN], w[MAXN], q[MAXN];
int a[MAXN], d[MAXN], _a[MAXN], _d[MAXN], ans[MAXN], st[MAXN], ed[MAXN],
    node[MAXN];
struct edge {
  int u, v, w, next;
} e[MAXN * 2];
int pre[MAXN], edge_cnt = 0;
void addedge(int u, int v, int w = 0) {
  edge_cnt = edge_cnt + 1, e[edge_cnt].u = u, e[edge_cnt].v = v,
  e[edge_cnt].w = w, e[edge_cnt].next = pre[u], pre[u] = edge_cnt;
};
void dfs(int u, int fa) {
  st[u] = ++tim, node[tim] = u, d[u] = d[fa] + 1;
  for (long long i = pre[u], v = e[i].v, w = e[i].w; i;
       i = e[i].next, v = e[i].v, w = e[i].w)
    if (v != fa) a[v] = a[u] ^ w, dfs(v, u);
  ed[u] = tim;
}
void solve(int root) {
  tim = 0, a[root] = 0, d[0] = -1, dfs(root, 0);
  for (int i = (1), I = (n) + 1; i < I; ++i)
    _a[i] = a[node[i]], _d[i] = d[node[i]];
  seg::build(1, n, _a, _d, 1);
  for (int i = (1), I = (m) + 1; i < I; ++i) {
    int x = d[u[q[i]]] > d[v[q[i]]] ? u[q[i]] : v[q[i]];
    seg::flip(1, n, st[x], ed[x], 1), ans[i] = max(ans[i], seg::mx[1][0]);
  }
}
int find(int u, int fa) {
  int ans = u;
  d[u] = d[fa] + 1;
  for (int i = pre[u], v = e[i].v; i; i = e[i].next, v = e[i].v)
    if (v != fa) {
      int res = find(v, u);
      if (d[res] > d[ans]) ans = res;
    }
  return ans;
}
int work() {
  io::read(n);
  for (int i = (1), I = (n - 1) + 1; i < I; ++i) {
    io::read(u[i]), io::read(v[i]), io::read(w[i]);
    addedge(u[i], v[i], w[i]), addedge(v[i], u[i], w[i]);
  }
  io::read(m);
  for (int i = (1), I = (m) + 1; i < I; ++i) io::read(q[i]);
  int root;
  solve(root = find(1, 0)), solve(find(root, 0));
  for (int i = (1), I = (m) + 1; i < I; ++i) io::write(ans[i]), io::write('\n');
  io::flush();
  return 0;
}
int main() {
  work();
  return 0;
}