#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char c = getchar();
  int x = 0;
  bool f = 0;
  for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  if (f) x = -x;
  return x;
}
int n, m;
struct edge {
  int to, nxt, w;
} e[1000005 << 1];
int tot = 1, head[1000005];
inline void adde(int u, int v, int w) {
  e[++tot] = (edge){v, head[u], w};
  head[u] = tot;
}
int rt, dis[1000005];
void dfs(int u, int pa) {
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == pa) continue;
    dis[v] = dis[u] + 1, dfs(v, u);
  }
}
int find(int xx = 1) {
  dfs(xx, 0);
  int u = 1;
  for (register int i = (1); i <= (n); ++i)
    if (dis[i] > dis[u]) u = i;
  return dis[u] = 0, dfs(u, 0), u;
}
int dfn[1000005], ed[1000005], que[1000005], w[1000005], idx;
void getdfn(int u, int pa) {
  dfn[u] = ++idx;
  que[idx] = u;
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == pa) continue;
    w[v] = w[u] ^ e[i].w, getdfn(v, u);
  }
  ed[u] = idx;
}
int cnt, val[1000005 << 4], ls[1000005 << 4], rs[1000005 << 4], rt0, rt1;
inline void pushup(int p) { val[p] = max(val[ls[p]], val[rs[p]]); }
void build(int& p, int l, int r, bool fg) {
  p = ++cnt;
  if (l == r) {
    if (fg == w[que[l]]) val[p] = dis[que[l]];
    return;
  }
  int mid = l + r >> 1;
  build(ls[p], l, mid, fg), build(rs[p], mid + 1, r, fg);
  pushup(p);
}
bool in(int l, int r, int ll, int rr) { return ll >= l && rr <= r; }
void mdf(int u, int v, int l, int r, int nl, int nr) {
  int mid = l + r >> 1;
  if (nl <= mid) {
    if (in(nl, nr, l, mid))
      swap(ls[u], ls[v]);
    else
      mdf(ls[u], ls[v], l, mid, nl, nr);
  }
  if (nr > mid) {
    if (in(nl, nr, mid + 1, r))
      swap(rs[u], rs[v]);
    else
      mdf(rs[u], rs[v], mid + 1, r, nl, nr);
  }
  pushup(u), pushup(v);
}
void out(int p, int l, int r) {
  if (l == r) {
    cout << val[p] << ' ';
    return;
  }
  int mid = l + r >> 1;
  out(ls[p], l, mid), out(rs[p], mid + 1, r);
}
int res[1000005];
int idid[1000005];
void work(int rt) {
  w[rt] = 0;
  getdfn(rt, 0);
  for (register int i = (1); i <= (cnt); ++i) ls[i] = rs[i] = val[i] = 0;
  cnt = 0;
  build(rt0, 1, n, 0), build(rt1, 1, n, 1);
  for (register int _ = (1); _ <= (m); ++_) {
    int id = idid[_];
    int u = e[id << 1].to, v = e[id << 1 | 1].to;
    if (dfn[u] < dfn[v]) swap(u, v);
    mdf(rt0, rt1, 1, n, dfn[u], ed[u]);
    res[_] = max(res[_], val[rt0]);
  }
}
signed main() {
  n = read();
  for (register int i = (2); i <= (n); ++i) {
    int u = read(), v = read(), w = read();
    adde(u, v, w), adde(v, u, w);
  }
  m = read();
  for (register int i = (1); i <= (m); ++i) idid[i] = read();
  rt = find();
  work(rt);
  rt = find(rt);
  idx = 0, w[rt] = 0;
  work(rt);
  for (register int i = (1); i <= (m); ++i) cout << res[i] << endl;
  return 0;
}
