#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "inline", "-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
using namespace std;
int n, q, loc, maxv, root[2], cnt[2], l[2][500010], r[2][500010],
    val[2][500010], pos[2][500010], dep[2][500010];
int mx0[2][2000010], mx1[2][2000010], rev[2][2000010];
vector<pair<int, int> > v[500010], e;
inline int getint() {
  int r = 0;
  char c;
  c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') {
    r = r * 10 + c - '0';
    c = getchar();
  }
  return r;
}
inline void dfs(int x, int pr, int dist) {
  if (dist > maxv) {
    maxv = dist;
    loc = x;
  }
  for (int i = 0; i < v[x].size(); i++)
    if (v[x][i].first != pr) {
      dfs(v[x][i].first, x, dist + 1);
    }
}
inline void calc(int id, int x, int pr) {
  l[id][x] = ++cnt[id];
  pos[id][cnt[id]] = x;
  for (int i = 0; i < v[x].size(); i++)
    if (v[x][i].first != pr) {
      val[id][v[x][i].first] = val[id][x] ^ v[x][i].second;
      dep[id][v[x][i].first] = dep[id][x] + 1;
      calc(id, v[x][i].first, x);
    }
  r[id][x] = cnt[id];
}
inline void build(int id, int o, int l, int r) {
  rev[id][o] = 0;
  if (l == r) {
    if (val[id][pos[id][l]] == 0) {
      mx0[id][o] = dep[id][pos[id][l]];
      mx1[id][o] = -1000000007;
    } else {
      mx0[id][o] = -1000000007;
      mx1[id][o] = dep[id][pos[id][l]];
    }
  } else {
    int mid = (l + r) / 2;
    build(id, o * 2, l, mid);
    build(id, o * 2 + 1, mid + 1, r);
    mx0[id][o] = max(mx0[id][o * 2], mx0[id][o * 2 + 1]);
    mx1[id][o] = max(mx1[id][o * 2], mx1[id][o * 2 + 1]);
  }
}
inline void pushdown(int id, int o, int l, int r) {
  int lc = o * 2, rc = o * 2 + 1;
  if (l < r) {
    if (rev[id][o]) {
      swap(mx0[id][lc], mx1[id][lc]);
      rev[id][lc] ^= 1;
      swap(mx0[id][rc], mx1[id][rc]);
      rev[id][rc] ^= 1;
      rev[id][o] = 0;
    }
  }
}
inline void pushup(int id, int o, int l, int r) {
  int lc = o * 2, rc = o * 2 + 1;
  if (l < r) {
    mx0[id][o] = max(mx0[id][lc], mx0[id][rc]);
    mx1[id][o] = max(mx1[id][lc], mx1[id][rc]);
  }
}
inline void update(int id, int o, int l, int r, int xx, int yy) {
  if (r < xx || l > yy) return;
  if (xx <= l && r <= yy) {
    swap(mx0[id][o], mx1[id][o]);
    rev[id][o] ^= 1;
    return;
  }
  pushdown(id, o, l, r);
  int mid = (l + r) / 2;
  update(id, o * 2, l, mid, xx, yy);
  update(id, o * 2 + 1, mid + 1, r, xx, yy);
  pushup(id, o, l, r);
}
signed main() {
  n = getint();
  for (int i = 1; i < n; i++) {
    int x, y, c;
    x = getint();
    y = getint();
    c = getint();
    v[x].push_back(make_pair(y, c));
    v[y].push_back(make_pair(x, c));
    e.push_back(make_pair(x, y));
  }
  loc = 0;
  maxv = 0;
  dfs(1, -1, 0);
  root[0] = loc;
  loc = 0;
  maxv = 0;
  dfs(root[0], -1, 0);
  root[1] = loc;
  calc(0, root[0], -1);
  calc(1, root[1], -1);
  build(0, 1, 1, cnt[0]);
  build(1, 1, 1, cnt[1]);
  q = getint();
  for (int i = 1; i <= q; i++) {
    int x;
    x = getint();
    int xx = e[x - 1].first, yy = e[x - 1].second;
    if (dep[0][xx] < dep[0][yy])
      update(0, 1, 1, cnt[0], l[0][yy], r[0][yy]);
    else
      update(0, 1, 1, cnt[0], l[0][xx], r[0][xx]);
    if (dep[1][xx] < dep[1][yy])
      update(1, 1, 1, cnt[1], l[1][yy], r[1][yy]);
    else
      update(1, 1, 1, cnt[1], l[1][xx], r[1][xx]);
    printf("%d\n", max(mx0[0][1], mx0[1][1]));
  }
  return 0;
}
