#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
inline int read() {
  int x = 0, f = 1, c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  return f == 1 ? x : -x;
}
const int N = 5e5 + 4;
struct edge {
  int v, w, nxt;
} e[N << 1];
int first[N], cnt = 1;
inline void addedge(int u, int v, int w) {
  e[++cnt] = (edge){v, w, first[u]};
  first[u] = cnt;
}
int n, Q, tim, siz[N], dep[N], son[N], top[N], idx[N], dfn[N], fa[N], dis[N],
    iw[N];
void dfs_1(int x) {
  siz[x] = 1;
  idx[dfn[x] = ++tim] = x;
  for (int i = first[x], v; i; i = e[i].nxt) {
    v = e[i].v;
    if (v == fa[x]) continue;
    fa[v] = x;
    dep[v] = dep[x] + 1;
    dis[v] = dis[x] ^ e[i].w;
    iw[i >> 1] = v;
    dfs_1(v);
    siz[x] += siz[v];
    if (siz[v] > siz[son[x]]) son[x] = v;
  }
}
int mn[N << 1][20], lg[N << 1], st[N];
void dfs_2(int x) {
  mn[st[x] = ++tim][0] = x;
  for (int i = first[x], v; i; i = e[i].nxt) {
    v = e[i].v;
    if (v == fa[x]) continue;
    dfs_2(v);
    mn[++tim][0] = x;
  }
}
inline int cmp(int x, int y) { return dep[x] < dep[y] ? x : y; }
inline void prepare() {
  tim = 0;
  dfs_2(1);
  for (int i = 2; i <= tim; i++) lg[i] = lg[i >> 1] + 1;
  for (int j = 1; j <= lg[tim]; j++)
    for (int i = 1, r = 1 << j; r <= tim; i++, r++)
      mn[i][j] = cmp(mn[i][j - 1], mn[i + (1 << j - 1)][j - 1]);
}
inline int getlca(int x, int y) {
  x = st[x];
  y = st[y];
  if (x > y) x ^= y ^= x ^= y;
  int k = lg[y - x + 1];
  return cmp(mn[x][k], mn[y - (1 << k) + 1][k]);
}
struct node {
  int p1, p2, w;
  node() {}
  node(int x, int y, int v) : p1(x), p2(y), w(v) {}
};
inline bool upd(int &x, int v) {
  if (x < v) {
    x = v;
    return 1;
  }
  return 0;
}
inline int distan(int x, int y) {
  return (!x || !y) ? -1 : dep[x] + dep[y] - dep[getlca(x, y)] * 2;
}
inline node operator+(const node &a, const node &b) {
  node ret = a.w > b.w ? a : b;
  if (upd(ret.w, distan(a.p1, b.p1))) {
    ret.p1 = a.p1;
    ret.p2 = b.p1;
  }
  if (upd(ret.w, distan(a.p1, b.p2))) {
    ret.p1 = a.p1;
    ret.p2 = b.p2;
  }
  if (upd(ret.w, distan(a.p2, b.p1))) {
    ret.p1 = a.p2;
    ret.p2 = b.p1;
  }
  if (upd(ret.w, distan(a.p2, b.p2))) {
    ret.p1 = a.p2;
    ret.p2 = b.p2;
  }
  return ret;
}
namespace seg {
node t[N << 2][2];
int lz[N << 2];
inline void pushup(int p) {
  t[p][0] = t[(p << 1)][0] + t[(p << 1 | 1)][0];
  t[p][1] = t[(p << 1)][1] + t[(p << 1 | 1)][1];
}
inline void pushnow(int p) {
  swap(t[p][0], t[p][1]);
  lz[p] ^= 1;
}
inline void pushdown(int p) {
  if (!lz[p]) return;
  pushnow((p << 1));
  pushnow((p << 1 | 1));
  lz[p] ^= 1;
}
void build(int p, int l, int r) {
  if (l == r) {
    t[p][dis[idx[r]]].p1 = t[p][dis[idx[r]]].p2 = idx[r];
    t[p][dis[idx[r]] ^ 1].w = -1;
    return;
  }
  build((p << 1), l, ((l + r) >> 1));
  build((p << 1 | 1), ((l + r) >> 1) + 1, r);
  pushup(p);
}
void modify(int p, int l, int r, int ql, int qr) {
  if (ql <= l && r <= qr) {
    pushnow(p);
    return;
  }
  pushdown(p);
  if (ql <= ((l + r) >> 1)) modify((p << 1), l, ((l + r) >> 1), ql, qr);
  if (((l + r) >> 1) < qr) modify((p << 1 | 1), ((l + r) >> 1) + 1, r, ql, qr);
  pushup(p);
}
}  // namespace seg
int main() {
  n = read();
  for (int i = 1, u, v, w; i < n; i++) {
    u = read();
    v = read();
    w = read();
    addedge(u, v, w);
    addedge(v, u, w);
  }
  dfs_1(1);
  prepare();
  seg::build(1, 1, n);
  for (int Q = read(), x; Q--;) {
    x = iw[read()];
    seg::modify(1, 1, n, dfn[x], dfn[x] + siz[x] - 1);
    cout << max(seg::t[1][0].w, seg::t[1][1].w) << "\n";
  }
  return (0 - 0);
}
