#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5, maxm = 1e6 + 5;
int mx[maxn << 2][2][2], fz[maxn << 2][2];
int color[maxn][2], cen[maxn][2], dis[maxn], DFS[maxn][2], EFS[maxn][2], t[2];
inline void push_up(int rt) {
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 2; j++)
      mx[rt][i][j] = max(mx[rt << 1][i][j], mx[rt << 1 | 1][i][j]);
}
inline void push_down(int rt, int l, int r) {
  if (fz[rt][1]) {
    swap(mx[rt << 1][1][0], mx[rt << 1][1][1]);
    swap(mx[rt << 1 | 1][1][0], mx[rt << 1 | 1][1][1]);
    fz[rt << 1][1] ^= 1, fz[rt << 1 | 1][1] ^= 1;
    fz[rt][1] = 0;
  }
  if (fz[rt][0]) {
    swap(mx[rt << 1][0][0], mx[rt << 1][0][1]);
    swap(mx[rt << 1 | 1][0][0], mx[rt << 1 | 1][0][1]);
    fz[rt << 1][0] ^= 1, fz[rt << 1 | 1][0] ^= 1;
    fz[rt][0] = 0;
  }
}
void build(int rt, int l, int r) {
  if (l == r) {
    mx[rt][1][color[l][1]] = cen[l][1];
    mx[rt][0][color[l][0]] = cen[l][0];
    return;
  }
  int m = (l + r) >> 1;
  build(rt << 1, l, m);
  build(rt << 1 | 1, m + 1, r);
  push_up(rt);
}
void update(int rt, int l, int r, int L, int R, int v) {
  if (L <= l && r <= R) {
    swap(mx[rt][v][0], mx[rt][v][1]);
    fz[rt][v] ^= 1;
    return;
  }
  push_down(rt, l, r);
  int m = (l + r) >> 1;
  if (L <= m) update(rt << 1, l, m, L, R, v);
  if (m < R) update(rt << 1 | 1, m + 1, r, L, R, v);
  push_up(rt);
}
int query(int rt, int l, int r, int L, int R) {
  if (L <= l && r <= R) return max(mx[rt][1][0], mx[rt][0][0]);
  push_down(rt, l, r);
  int m = (l + r) >> 1;
  if (L <= m)
    ;
  if (m < R)
    ;
  return 0;
}
int head[maxn], nume;
struct edge {
  int v, w, c, next;
} e[maxm];
inline void init_edge() {
  memset(head, -1, sizeof head);
  nume = 0;
}
inline void add_edge(int u, int v, int w = 0, int c = 0) {
  e[nume].v = v;
  e[nume].w = w;
  e[nume].c = c;
  e[nume].next = head[u];
  head[u] = nume++;
}
int a = 1, b = 1;
void dfs(int u, int f) {
  for (int i = head[u]; ~i; i = e[i].next) {
    int v = e[i].v;
    if (v != f) {
      dis[v] = dis[u] + 1;
      dfs(v, u);
    }
  }
}
void ddfs(int u, int f, int cl) {
  DFS[u][cl] = ++t[cl];
  for (int i = head[u]; ~i; i = e[i].next) {
    int v = e[i].v, w = e[i].w;
    if (v != f) {
      cen[t[cl] + 1][cl] = cen[DFS[u][cl]][cl] + 1;
      color[t[cl] + 1][cl] = color[DFS[u][cl]][cl] ^ w;
      ddfs(v, u, cl);
    }
  }
  EFS[u][cl] = t[cl];
}
int n, u[maxn], v[maxn], w[maxn];
int m, x;
int main() {
  init_edge();
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d%d", &u[i], &v[i], &w[i]);
    add_edge(u[i], v[i], w[i]);
    add_edge(v[i], u[i], w[i]);
  }
  dis[1] = 0;
  dfs(1, 0);
  for (int i = 1; i <= n; i++) {
    if (dis[i] > dis[a]) a = i;
  }
  dis[a] = 0;
  dfs(a, 0);
  for (int i = 1; i <= n; i++) {
    if (dis[i] > dis[b]) b = i;
  }
  ddfs(a, 0, 0);
  ddfs(b, 0, 1);
  build(1, 1, n);
  scanf("%d", &m);
  while (m--) {
    scanf("%d", &x);
    for (int i = 0; i <= 1; i++) {
      if (DFS[u[x]][i] < DFS[v[x]][i])
        update(1, 1, n, DFS[v[x]][i], EFS[v[x]][i], i);
      else
        update(1, 1, n, DFS[u[x]][i], EFS[u[x]][i], i);
    }
    printf("%d\n", max(mx[1][0][0], mx[1][1][0]));
  }
}
