#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int read(void) {
  int x = 0;
  register char ch = getchar();
  while (ch < 48) ch = getchar();
  while (ch > 47) x = x * 10 + ch - 48, ch = getchar();
  return x;
}
constexpr int Maxn = 5e5 + 5;
constexpr int LOG = 20;
int n, q;
struct Edge {
  int to, w, nxt, id;
} e[Maxn << 1];
int head[Maxn], tot_edge;
void add_edge(int u, int v, int w) {
  e[++tot_edge] = (Edge){v, w, head[u]};
  head[u] = tot_edge;
}
int dfn[Maxn], ed[Maxn], dfn_time, dfn_id[Maxn];
int sz[Maxn], dep[Maxn];
int xord[Maxn], e_son[Maxn];
int fad[Maxn << 1], fa_time, fdfn[Maxn];
int ST[Maxn << 1][LOG + 1], lg[Maxn << 1];
void dfs(int u, int fa, int depth) {
  sz[u] = 1;
  dep[u] = depth;
  dfn[u] = ++dfn_time;
  dfn_id[dfn_time] = u;
  fdfn[u] = ++fa_time;
  fad[fa_time] = u;
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].to, w = e[i].w;
    if (v == fa) continue;
    xord[v] = xord[u] ^ w;
    dfs(v, u, depth + 1);
    sz[u] += sz[v];
    e_son[(i + 1) >> 1] = v;
    fad[++fa_time] = u;
  }
  ed[u] = dfn[u] + sz[u] - 1;
}
inline int min_dep(int x, int y) { return (dep[x] < dep[y]) ? x : y; }
int get_lca(int x, int y) {
  if (x == y) return x;
  int l = fdfn[x], r = fdfn[y];
  if (l > r) swap(l, r);
  int k = lg[r - l + 1];
  return min_dep(ST[l][k], ST[r - (1 << k) + 1][k]);
}
int get_dist(int x, int y) { return dep[x] + dep[y] - 2 * dep[get_lca(x, y)]; }
struct diam {
  int x, y, d;
  diam() : x(0), y(0), d(0) {}
  diam(int x, int y) : x(x), y(y) { d = (x == y) ? 0 : get_dist(x, y); }
  diam(int x, int y, int d) : x(x), y(y), d(d) {}
  diam(const diam &da) : x(da.x), y(da.y), d(da.d) {}
  friend bool operator<(const diam &x, const diam &y) { return x.d < y.d; }
  friend diam operator+(const diam &x, const diam &y) {
    if (!x.x) return y;
    if (!y.x) return x;
    diam res = max(x, y);
    res = max(res, max(diam(x.x, y.x), diam(x.x, y.y)));
    res = max(res, max(diam(x.y, y.x), diam(x.y, y.y)));
    return res;
  }
};
diam tr[Maxn << 2][2];
bool rev[Maxn << 2];
void pushup(int p) {
  tr[p][0] = tr[(p << 1)][0] + tr[((p << 1) | 1)][0];
  tr[p][1] = tr[(p << 1)][1] + tr[((p << 1) | 1)][1];
}
void build(int p, int l, int r) {
  rev[p] = false;
  if (l == r) {
    int x = dfn_id[l];
    int y = xord[x];
    tr[p][y] = diam(x, x);
    tr[p][y ^ 1] = diam();
    return;
  }
  int mid = (l + r) >> 1;
  build((p << 1), l, mid);
  build(((p << 1) | 1), mid + 1, r);
  pushup(p);
}
void apply(int p) {
  swap(tr[p][0], tr[p][1]);
  rev[p] ^= 1;
}
void pushdown(int p, int l, int r) {
  if (rev[p]) {
    if (l != r) {
      apply((p << 1));
      apply(((p << 1) | 1));
    }
    rev[p] = false;
  }
}
void modify(int p, int l, int r, int L, int R) {
  if (L > r || l > R) return;
  if (L <= l && r <= R) return apply(p);
  pushdown(p, l, r);
  int mid = (l + r) >> 1;
  modify((p << 1), l, mid, L, R);
  modify(((p << 1) | 1), mid + 1, r, L, R);
  pushup(p);
}
int main() {
  n = read();
  for (int i = 1; i < n; ++i) {
    int u, v, w;
    u = read(), v = read(), w = read();
    add_edge(u, v, w);
    add_edge(v, u, w);
  }
  xord[1] = 0;
  dfn_time = fa_time = 0;
  dfs(1, 0, 1);
  int szf = fa_time;
  lg[0] = -1;
  for (int i = 1; i <= szf; ++i) {
    ST[i][0] = fad[i];
    lg[i] = lg[i >> 1] + 1;
  }
  for (int j = 1; j <= LOG; ++j) {
    for (int i = 1; i + (1 << j) - 1 <= szf; ++i) {
      ST[i][j] = min_dep(ST[i][j - 1], ST[i + (1 << (j - 1))][j - 1]);
    }
  }
  build(1, 1, n);
  q = read();
  while (q--) {
    int x = read();
    int u = e_son[x];
    modify(1, 1, n, dfn[u], ed[u]);
    printf("%d\n", max(tr[1][0], tr[1][1]).d);
  }
  return 0;
}
