#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() {
  scanf("%d", &n);
  for (int i = (1), I = (n - 1) + 1; i < I; ++i) {
    scanf("%d%d%d", &u[i], &v[i], &w[i]);
    addedge(u[i], v[i], w[i]), addedge(v[i], u[i], w[i]);
  }
  scanf("%d", &m);
  for (int i = (1), I = (m) + 1; i < I; ++i) scanf("%d", &q[i]);
  int root;
  solve(root = find(1, 0)), solve(find(root, 0));
  for (int i = (1), I = (m) + 1; i < I; ++i) printf("%d\n", ans[i]);
  return 0;
}
int main() {
  work();
  return 0;
}
