#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int n, q, ans[N];
bool w[N];
int b[N], de[N], de2[N];
int tot, rev[N], pl[N], pr[N];
pair<int, int> edge[N];
vector<pair<int, int> > e[N];
pair<int, int> d;
struct tree {
  int a[N << 2][2];
  bool tag[N << 2];
  void clear() {
    memset(a, 0, sizeof(a));
    memset(tag, 0, sizeof(tag));
  }
  void up(int now) {
    a[now][0] = max(a[(now << 1)][0], a[(now << 1 | 1)][0]);
    a[now][1] = max(a[(now << 1)][1], a[(now << 1 | 1)][1]);
  }
  void update(int now) {
    tag[now] ^= 1;
    swap(a[now][0], a[now][1]);
  }
  void down(int now) {
    if (!tag[now]) return;
    update((now << 1)), update((now << 1 | 1));
    tag[now] = 0;
  }
  void build(int now, int l, int r) {
    if (l == r) return (void)(a[now][0] = de[rev[l]]);
    build((now << 1), l, ((l + r) >> 1));
    build((now << 1 | 1), ((l + r) >> 1) + 1, r);
    up(now);
  }
  void change(int now, int l, int r, int s, int t) {
    if (s <= l && r <= t) return update(now);
    down(now);
    if (s <= ((l + r) >> 1)) change((now << 1), l, ((l + r) >> 1), s, t);
    if (t > ((l + r) >> 1)) change((now << 1 | 1), ((l + r) >> 1) + 1, r, s, t);
    up(now);
  }
  int ask() { return a[1][0]; }
} T;
void dfs(int u, int fa) {
  de[u] = de[fa] + 1;
  if (de[u] > de[d.first]) d.first = u;
  for (int i = 0; i < e[u].size(); i++) {
    int v = e[u][i].first;
    if (v == fa) continue;
    dfs(v, u);
  }
}
void dfs2(int u, int fa) {
  pl[u] = ++tot;
  rev[tot] = u;
  for (int i = 0; i < e[u].size(); i++) {
    int v = e[u][i].first, id = e[u][i].second;
    if (v == fa) continue;
    de[v] = de[u] + 1;
    de2[v] = de2[u] + w[id];
    dfs2(v, u);
  }
  pr[u] = tot;
}
void solve(int rt) {
  tot = 0;
  memset(de, 0, sizeof(de));
  memset(de2, 0, sizeof(de2));
  dfs2(rt, 0);
  T.clear();
  T.build(1, 1, n);
  for (int i = 1; i < n; i++) {
    if (!w[i]) continue;
    int u =
        de[edge[i].first] > de[edge[i].second] ? edge[i].first : edge[i].second;
    T.change(1, 1, n, pl[u], pr[u]);
  }
  for (int i = 1; i <= q; i++) {
    int u = de[edge[b[i]].first] > de[edge[b[i]].second] ? edge[b[i]].first
                                                         : edge[b[i]].second;
    T.change(1, 1, n, pl[u], pr[u]);
    ans[i] = max(T.ask(), ans[i]);
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    edge[i] = make_pair(u, v);
    e[u].push_back({v, i});
    e[v].push_back({u, i});
    cin >> w[i];
  }
  cin >> q;
  for (int i = 1; i <= q; i++) cin >> b[i];
  dfs(1, 0);
  swap(d.first, d.second);
  dfs(d.second, 0);
  solve(d.first);
  solve(d.second);
  for (int i = 1; i <= q; i++) cout << ans[i] << endl;
  return 0;
}
