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;
constexpr int maxn = 5e5 + 100, inf = 0x7fffffff;
struct IO {
 private:
  static constexpr int ibufsiz = 1 << 20;
  char ibuf[ibufsiz + 1], *inow = ibuf, *ied = ibuf;
  static constexpr int obufsiz = 1 << 20;
  char obuf[obufsiz + 1], *onow = obuf;
  const char *oed = obuf + obufsiz;

 public:
  char getchar() {
    if (inow == ied) {
      ied = ibuf + sizeof(char) * fread(ibuf, sizeof(char), ibufsiz, stdin);
      *ied = '\0';
      inow = ibuf;
    }
    return *inow++;
  }
  template <typename T>
  void read(T &x) {
    static bool flg;
    flg = 0;
    x = 0;
    char c = getchar();
    while (!isdigit(c)) flg = c == '-' ? 1 : flg, c = getchar();
    while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
    if (flg) x = -x;
  }
  template <typename T, typename... Y>
  void read(T &x, Y &...X) {
    read(x);
    read(X...);
  }
  int readi() {
    static int res;
    read(res);
    return res;
  }
  long long readll() {
    static long long res;
    read(res);
    return res;
  }
  void flush() {
    fwrite(obuf, sizeof(char), onow - obuf, stdout);
    fflush(stdout);
    onow = obuf;
  }
  void putchar(const char c) {
    *onow++ = c;
    if (onow == oed) {
      fwrite(obuf, sizeof(char), obufsiz, stdout);
      onow = obuf;
    }
  }
  template <typename T>
  void write(T x, const char split = '\0') {
    static unsigned char buf[32];
    if (x < 0) putchar('-'), x = -x;
    int p = 0;
    do {
      buf[++p] = x % 10;
      x /= 10;
    } while (x);
    for (int i = p; i >= 1; i--) putchar(buf[i] + '0');
    if (split != '\0') putchar(split);
  }
  void puts(char const *str, const char split = '\n') {
    while (*str) putchar(*(str++));
    putchar(split);
  }
  void lf() { putchar('\n'); }
  ~IO() { fwrite(obuf, sizeof(char), onow - obuf, stdout); }
} io;
int n;
vector<pair<int, int>> edges;
struct seg {
  static constexpr int maxn = ::maxn << 2;
  int mx[maxn][2], rev[maxn];
  void pushup(const int x) {
    mx[x][0] = max(mx[(x << 1)][0], mx[(x << 1 | 1)][0]);
    mx[x][1] = max(mx[(x << 1)][1], mx[(x << 1 | 1)][1]);
  }
  void pushdown(const int x) {
    if (!rev[x]) return;
    rev[(x << 1)] ^= 1, rev[(x << 1 | 1)] ^= 1;
    swap(mx[(x << 1)][0], mx[(x << 1)][1]);
    swap(mx[(x << 1 | 1)][0], mx[(x << 1 | 1)][1]);
    rev[x] ^= 1;
  }
  void build(const int col[], const int val[], const int rnk[], const int l = 1,
             const int r = n, const int x = 1) {
    if (l == r) {
      mx[x][col[rnk[l]]] = val[rnk[l]];
      return;
    }
    const int mid = (l + r) >> 1;
    build(col, val, rnk, l, mid, (x << 1));
    build(col, val, rnk, mid + 1, r, (x << 1 | 1));
    pushup(x);
  }
  void modify(const int a, const int b, const int l = 1, const int r = n,
              const int x = 1) {
    if (a <= l && b >= r) {
      rev[x] ^= 1;
      swap(mx[x][0], mx[x][1]);
      return;
    }
    pushdown(x);
    const int mid = (l + r) >> 1;
    if (a <= mid) modify(a, b, l, mid, (x << 1));
    if (b >= mid + 1) modify(a, b, mid + 1, r, (x << 1 | 1));
    pushup(x);
  }
} sa, sb;
namespace treea {
int siz[maxn], dfn[maxn], rnk[maxn], dep[maxn], col[maxn];
}
namespace treeb {
int siz[maxn], dfn[maxn], rnk[maxn], dep[maxn], col[maxn];
}
namespace graph {
vector<pair<int, int>> G[maxn];
void addedge(const int u, const int v, const int d) { G[u].emplace_back(v, d); }
int dis[maxn];
void dfs(const int u, const int faz = -1) {
  for (auto [v, d] : G[u]) {
    if (v == faz) continue;
    dis[v] = dis[u] + 1;
    dfs(v, u);
  }
}
int dfs_tot;
void dfs2(int siz[], int dfn[], int rnk[], int dep[], int col[], const int u,
          const int faz = -1) {
  dfs_tot++;
  siz[u] = 1;
  dfn[u] = dfs_tot;
  rnk[dfs_tot] = u;
  for (auto [v, d] : G[u]) {
    if (v == faz) continue;
    dep[v] = dep[u] + 1;
    col[v] = col[u] ^ d;
    dfs2(siz, dfn, rnk, dep, col, v, u);
    siz[u] += siz[v];
  }
}
}  // namespace graph
void init() {
  graph::dfs(1);
  const int dia_a =
      max_element(graph::dis + 1, graph::dis + 1 + n) - graph::dis;
  graph::dis[dia_a] = 0;
  graph::dfs(dia_a);
  const int dia_b =
      max_element(graph::dis + 1, graph::dis + 1 + n) - graph::dis;
  graph::dfs2(treea::siz, treea::dfn, treea::rnk, treea::dep, treea::col,
              dia_a);
  graph::dfs_tot = 0;
  graph::dfs2(treeb::siz, treeb::dfn, treeb::rnk, treeb::dep, treeb::col,
              dia_b);
  sa.build(treea::col, treea::dep, treea::rnk);
  sb.build(treeb::col, treeb::dep, treeb::rnk);
}
int main() {
  io.read(n);
  for (int u, v, d, i = 1; i < n; i++)
    io.read(u, v, d), graph::addedge(u, v, d), graph::addedge(v, u, d),
        edges.emplace_back(u, v);
  init();
  int q = io.readi();
  while (q--) {
    const int x = io.readi();
    const auto [u, v] = edges[x - 1];
    if (treea::dep[u] > treea::dep[v])
      sa.modify(treea::dfn[u], treea::dfn[u] + treea::siz[u] - 1);
    else
      sa.modify(treea::dfn[v], treea::dfn[v] + treea::siz[v] - 1);
    if (treeb::dep[u] > treeb::dep[v])
      sb.modify(treeb::dfn[u], treeb::dfn[u] + treeb::siz[u] - 1);
    else
      sb.modify(treeb::dfn[v], treeb::dfn[v] + treeb::siz[v] - 1);
    io.write(max(sa.mx[1][0], sb.mx[1][0]), '\n');
  }
  return 0;
}