#include <bits/stdc++.h>
using namespace std;
const int N = 555555;
const int M = 1111111;
const int MOD = 998244353;
const int intINF = 1e9;
const long long llINF = 2e18;
const double pi = acos(-1.0);
const int inv2 = 5e8 + 4;
int read() {
  int v = 0, f = 1;
  char c = getchar();
  while (c < 48 || 57 < c) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();
  return v * f;
}
long long readll() {
  long long v = 0, f = 1;
  char c = getchar();
  while (c < 48 || 57 < c) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();
  return v * f;
}
unsigned long long readull() {
  long long v = 0, f = 1;
  char c = getchar();
  while (c < 48 || 57 < c) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();
  return v * f;
}
void predo() {}
int head[N], vet[M], len[M], nxt[M], tot, n;
void add(int a, int b, int c) {
  nxt[++tot] = head[a];
  vet[tot] = b;
  len[tot] = c;
  head[a] = tot;
}
struct edge {
  int x, y;
} E[M];
void init() {
  n = read();
  for (int i = (int)1; i <= (int)n - 1; i++) {
    int x = read(), y = read(), z = read();
    add(x, y, z);
    add(y, x, z);
    E[i].x = x;
    E[i].y = y;
  }
}
int st[N], ed[N], dis[N], dep[N], id[N], tim;
void dfs(int u, int fa) {
  st[u] = ++tim;
  id[tim] = u;
  int e = head[u];
  while (e) {
    int v = vet[e];
    if (v != fa) {
      dep[v] = dep[u] + 1;
      dis[v] = dis[u] ^ len[e];
      dfs(v, u);
    }
    e = nxt[e];
  }
  ed[u] = tim;
}
int ST[N][2], ED[N][2], d[N][2], dep1[N], dep2[N], r1, r2;
struct seg_tree {
  struct node {
    int s[2], tag;
  } t[N << 2];
  void pushup(int p) {
    t[p].s[0] = max(t[p << 1].s[0], t[p << 1 | 1].s[0]);
    t[p].s[1] = max(t[p << 1].s[1], t[p << 1 | 1].s[1]);
  }
  void pushdown(int p) {
    if (t[p].tag) {
      swap(t[p << 1].s[0], t[p << 1].s[1]);
      swap(t[p << 1 | 1].s[0], t[p << 1 | 1].s[1]);
      t[p << 1].tag ^= 1;
      t[p << 1 | 1].tag ^= 1;
      t[p].tag = 0;
    }
  }
  void update(int l, int r, int x, int y, int p) {
    if (x <= l && r <= y) {
      swap(t[p].s[0], t[p].s[1]);
      t[p].tag ^= 1;
      return;
    }
    pushdown(p);
    int mid = (l + r) >> 1;
    if (x <= mid) update(l, mid, x, y, p << 1);
    if (y > mid) update(mid + 1, r, x, y, p << 1 | 1);
    pushup(p);
  }
} T1, T2;
int id1[N], id2[N];
void build1(int l, int r, int p) {
  T1.t[p].s[0] = T1.t[p].s[1] = 0;
  T1.t[p].tag = 0;
  if (l == r) {
    if (id1[l]) T1.t[p].s[d[id1[l]][0]] = dep1[id1[l]];
    return;
  }
  int mid = (l + r) >> 1;
  build1(l, mid, p << 1);
  build1(mid + 1, r, p << 1 | 1);
  T1.pushup(p);
}
void build2(int l, int r, int p) {
  T2.t[p].s[0] = T2.t[p].s[1] = 0;
  T2.t[p].tag = 0;
  if (l == r) {
    if (id2[l]) T2.t[p].s[d[id2[l]][1]] = dep2[id2[l]];
    return;
  }
  int mid = (l + r) >> 1;
  build2(l, mid, p << 1);
  build2(mid + 1, r, p << 1 | 1);
  T2.pushup(p);
}
void solve() {
  tim = 0;
  dis[1] = dep[1] = 0;
  dfs(1, 0);
  int r1 = 1;
  for (int i = (int)1; i <= (int)n; i++) {
    if (dep[i] > dep[r1]) r1 = i;
  }
  tim = 0;
  dis[r1] = dep[r1] = 0;
  dfs(r1, 0);
  int r2 = 1;
  for (int i = (int)1; i <= (int)n; i++) {
    if (dep[i] > dep[r2]) r2 = i;
  }
  for (int i = (int)1; i <= (int)n; i++) {
    ST[i][0] = st[i];
    ED[i][0] = ed[i];
    d[i][0] = dis[i];
    dep1[i] = dep[i];
    id1[i] = id[i];
  }
  tim = 0;
  dis[r2] = dep[r2] = 0;
  dfs(r2, 0);
  for (int i = (int)1; i <= (int)n; i++) {
    ST[i][1] = st[i];
    ED[i][1] = ed[i];
    d[i][1] = dis[i];
    dep2[i] = dep[i];
    id2[i] = id[i];
  }
  build1(1, n, 1);
  build2(1, n, 1);
  int q = read();
  while (q--) {
    int id = read();
    int x = E[id].x, y = E[id].y;
    int u;
    if (dep1[x] > dep1[y])
      u = x;
    else
      u = y;
    T1.update(1, n, ST[u][0], ED[u][0], 1);
    if (dep2[x] > dep2[y])
      u = x;
    else
      u = y;
    T2.update(1, n, ST[u][1], ED[u][1], 1);
    int ans = 0;
    ans = max(ans, T1.t[1].s[0]);
    ans = max(ans, T2.t[1].s[0]);
    printf("%d\n", ans);
  }
}
int main() {
  predo();
  int cas = 1;
  while (cas--) {
    init();
    solve();
  }
  return 0;
}
