#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
pair<int, int> edges[maxn];
vector<pair<int, int>> g[maxn];
int n, m;
int opt[maxn];
int dep[maxn];
int dfs(int o, int p) {
  dep[o] = dep[p] + 1;
  int res = o;
  for (auto u : g[o])
    if (u.first != p) {
      int tmp = dfs(u.first, o);
      if (dep[res] < dep[tmp]) res = tmp;
    }
  return res;
}
int dfn[maxn], efn[maxn], rdfn[maxn], col[maxn], tot;
void dfs1(int o, int p, int s) {
  dfn[o] = ++tot;
  rdfn[tot] = o;
  col[o] = s;
  for (auto u : g[o])
    if (u.first != p) {
      dfs1(u.first, o, s ^ u.second);
    }
  efn[o] = tot;
}
int seg[maxn << 2][2];
int flip[maxn << 2];
int get_val(int v, int d) { return seg[v][d ^ flip[v]]; }
void pushdown(int v) {
  if (flip[v]) {
    swap(seg[v][0], seg[v][1]);
    flip[v << 1] ^= 1;
    flip[v << 1 | 1] ^= 1;
    flip[v] = 0;
  }
}
void pushup(int v) {
  seg[v][0] = max(get_val(v << 1, 0), get_val(v << 1 | 1, 0));
  seg[v][1] = max(get_val(v << 1, 1), get_val(v << 1 | 1, 1));
}
void build(int l, int r, int v) {
  seg[v][0] = seg[v][1] = 0;
  flip[v] = 0;
  if (l == r) {
    seg[v][col[rdfn[l]]] = dep[rdfn[l]];
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, v << 1);
  build(mid + 1, r, v << 1 | 1);
  pushup(v);
}
void update(int l, int r, int v, int ql, int qr) {
  if (ql <= l && r <= qr) {
    flip[v] ^= 1;
    return;
  }
  pushdown(v);
  int mid = (l + r) >> 1;
  if (ql <= mid) update(l, mid, v << 1, ql, qr);
  if (qr > mid) update(mid + 1, r, v << 1 | 1, ql, qr);
  pushup(v);
}
void solve(int root, int* ans) {
  tot = 0;
  dfs(root, 0);
  dfs1(root, 0, 0);
  build(1, n, 1);
  for (int i = 1; i <= m; ++i) {
    int x = opt[i];
    int l = max(dfn[edges[x].first], dfn[edges[x].second]);
    int r = min(efn[edges[x].first], efn[edges[x].second]);
    update(1, n, 1, l, r);
    ans[i] = get_val(1, 0);
  }
}
int ans1[maxn], ans2[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    edges[i] = make_pair(a, b);
    g[a].push_back({b, c});
    g[b].push_back({a, c});
  }
  int root1 = dfs(1, 0);
  int root2 = dfs(root1, 0);
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) scanf("%d", &opt[i]);
  solve(root1, ans1);
  solve(root2, ans2);
  for (int i = 1; i <= m; ++i) printf("%d\n", max(ans1[i], ans2[i]) - 1);
  return 0;
}
