#include <bits/stdc++.h>
using namespace std;
void read(int &x) {
  static char c;
  int f = 0;
  while (!isdigit(c = getchar()))
    if (c == '-') f = 1;
  x = c ^ 48;
  while (isdigit(c = getchar())) x = (x * 10) + (c ^ 48);
  if (f) x = -x;
}
void read(long long &x) {
  static char c;
  int f = 0;
  while (!isdigit(c = getchar()))
    if (c == '-') f = 1;
  x = c ^ 48;
  while (isdigit(c = getchar())) x = (x * 10) + (c ^ 48);
}
void read(unsigned int &x) {
  static char c;
  while (!isdigit(c = getchar()))
    ;
  x = c ^ 48;
  while (isdigit(c = getchar())) x = (x * 10) + (c ^ 48);
}
void read(unsigned long long &x) {
  static char c;
  while (!isdigit(c = getchar()))
    ;
  x = c ^ 48;
  while (isdigit(c = getchar())) x = (x * 10) + (c ^ 48);
}
void chkmax(int &x, int y) {
  if (y > x) x = y;
}
void chkmin(int &x, int y) {
  if (y < x) x = y;
}
void chkmax(long long &x, long long y) {
  if (y > x) x = y;
}
void chkmin(long long &x, long long y) {
  if (y < x) x = y;
}
void chkmax(unsigned int &x, unsigned int y) {
  if (y > x) x = y;
}
void chkmin(unsigned int &x, unsigned int y) {
  if (y < x) x = y;
}
void chkmax(unsigned long long &x, unsigned long long y) {
  if (y > x) x = y;
}
void chkmin(unsigned long long &x, unsigned long long y) {
  if (y < x) x = y;
}
const int N = 5e5 + 10;
int n, q;
struct Link {
  int u, v, w;
} L[N];
struct Edge {
  int v, nxt, w;
} ed[N << 1];
int head[N], cnt;
void adde(int u, int v, int w) {
  ed[++cnt] = (Edge){v, head[u], w}, head[u] = cnt;
}
void add(int u, int v, int w) { adde(u, v, w), adde(v, u, w); }
int siz[N], dep[N], col[N];
int Dfn[N], seg[N], Dtot;
int Eul[N << 1], Beg[N], Etot;
void Build(int now, int fa) {
  siz[now] = 1, dep[now] = dep[fa] + 1;
  Dfn[now] = ++Dtot, seg[Dtot] = now, Beg[now] = ++Etot, Eul[Etot] = dep[now];
  for (int i = head[now]; i; i = ed[i].nxt) {
    int v = ed[i].v;
    if (v == fa) continue;
    col[v] = col[now] ^ ed[i].w;
    Build(v, now), siz[now] += siz[v];
    Eul[++Etot] = dep[now];
  }
}
int _log2[N << 1], ST[22][N << 1];
void Init() {
  const int _n = 2 * n - 1;
  for (int i = 2; i <= _n; ++i) _log2[i] = _log2[i >> 1] + 1;
  for (int i = 1; i <= _n; ++i) ST[0][i] = Eul[i];
  for (int B = 1; B <= _log2[_n]; ++B)
    for (int i = 1; i + (1 << B) - 1 <= _n; ++i)
      ST[B][i] = min(ST[B - 1][i], ST[B - 1][i + (1 << (B - 1))]);
}
int Getmin(int l, int r) {
  int k = _log2[r - l + 1];
  return min(ST[k][l], ST[k][r - (1 << k) + 1]);
}
int Dist(int u, int v) {
  if (Beg[u] > Beg[v]) swap(u, v);
  return dep[u] + dep[v] - 2 * Getmin(Beg[u], Beg[v]);
}
struct Node {
  pair<int, int> pr[2];
  int dis[2];
  int tag;
} t[N << 2];
void Pushdown(int now) {
  const int ls = now << 1, rs = now << 1 | 1;
  if (t[now].tag)
    swap(t[ls].pr[0], t[ls].pr[1]), swap(t[ls].dis[0], t[ls].dis[1]),
        swap(t[rs].pr[0], t[rs].pr[1]), swap(t[rs].dis[0], t[rs].dis[1]),
        t[ls].tag ^= 1, t[rs].tag ^= 1, t[now].tag = 0;
}
void Update(int now) {
  const int ls = now << 1, rs = now << 1 | 1;
  auto Check = [](int now, int C, int u, int v) -> void {
    if (!(u && v)) return;
    int dis = Dist(u, v);
    if (dis >= t[now].dis[C])
      t[now].pr[C] = make_pair(u, v), t[now].dis[C] = dis;
  };
  for (int C : {0, 1}) {
    t[now].pr[C] = make_pair(0, 0), t[now].dis[C] = 0;
    Check(now, C, t[ls].pr[C].first, t[ls].pr[C].second);
    Check(now, C, t[rs].pr[C].first, t[rs].pr[C].second);
    Check(now, C, t[ls].pr[C].first, t[rs].pr[C].first);
    Check(now, C, t[ls].pr[C].first, t[rs].pr[C].second);
    Check(now, C, t[ls].pr[C].second, t[rs].pr[C].first);
    Check(now, C, t[ls].pr[C].second, t[rs].pr[C].second);
  }
}
void Build(int now, int l, int r) {
  if (l == r) return t[now].pr[col[seg[l]]] = make_pair(seg[l], seg[l]), void();
  const int ls = now << 1, rs = now << 1 | 1, mid = (l + r) >> 1;
  Build(ls, l, mid), Build(rs, mid + 1, r), Update(now);
}
void Modify(int now, int l, int r, int x, int y) {
  if (l >= x && r <= y) {
    swap(t[now].pr[0], t[now].pr[1]);
    swap(t[now].dis[0], t[now].dis[1]);
    t[now].tag ^= 1;
    return;
  }
  Pushdown(now);
  const int ls = now << 1, rs = now << 1 | 1, mid = (l + r) >> 1;
  if (mid >= x) Modify(ls, l, mid, x, y);
  if (mid < y) Modify(rs, mid + 1, r, x, y);
  Update(now);
}
void Work() {
  read(n);
  for (int i = 1; i < n; ++i)
    read(L[i].u), read(L[i].v), read(L[i].w), add(L[i].u, L[i].v, L[i].w);
  Build(1, 0), Init(), Build(1, 1, n);
  for (int i = 1; i < n; ++i)
    if (Dfn[L[i].u] < Dfn[L[i].v]) swap(L[i].u, L[i].v);
  read(q);
  while (q--) {
    int id;
    read(id);
    Modify(1, 1, n, Dfn[L[id].u], Dfn[L[id].u] + siz[L[id].u] - 1);
    printf("%d\n", max(t[1].dis[0], t[1].dis[1]));
  }
}
int main() { Work(); }
