#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long n;
vector<vector<pair<long long, long long>>> g;
long long far(long long v) {
  vector<long long> d(n + 1, -1);
  d[v] = 0;
  queue<long long> q;
  q.push(v);
  while (!q.empty()) {
    long long s = q.front();
    q.pop();
    for (auto x : g[s]) {
      long long u = x.first;
      if (d[u] == -1) {
        d[u] = d[s] + 1;
        q.push(u);
      }
    }
  }
  long long id = 1;
  for (long long i = 2; i <= n; ++i) {
    if (d[i] > d[id]) id = i;
  }
  return id;
}
void dfs(long long v, long long p, vector<long long>& tin,
         vector<long long>& tout, vector<long long>& d, vector<long long>& h,
         vector<long long>& e, long long& timer) {
  tin[v] = timer++;
  e.push_back(v);
  for (auto x : g[v]) {
    long long u = x.first, w = x.second;
    if (u == p) continue;
    d[u] = (d[v] + w) % 2;
    h[u] = h[v] + 1;
    dfs(u, v, tin, tout, d, h, e, timer);
  }
  tout[v] = timer;
}
struct segtree {
  long long size;
  vector<vector<long long>> tree;
  vector<long long> modify;
  segtree(long long n) {
    size = 1;
    while (size < n) size <<= 1;
    tree.resize(2 * size - 1, vector<long long>(2));
    modify.resize(2 * size - 1);
  }
  void get(long long v) {
    tree[v][0] = max(tree[2 * v + 1][0], tree[2 * v + 2][0]);
    tree[v][1] = max(tree[2 * v + 1][1], tree[2 * v + 2][1]);
  }
  void push(long long v) {
    if (modify[v]) {
      modify[2 * v + 1] ^= 1;
      modify[2 * v + 2] ^= 1;
      swap(tree[2 * v + 1][0], tree[2 * v + 1][1]);
      swap(tree[2 * v + 2][0], tree[2 * v + 2][1]);
    }
    modify[v] = 0;
  }
  void upd(long long v, long long lx, long long rx, long long l, long long h,
           long long d) {
    if (lx + 1 == rx) {
      tree[v][d] = h;
      return;
    }
    long long m = (lx + rx) / 2;
    if (l < m)
      upd(2 * v + 1, lx, m, l, h, d);
    else
      upd(2 * v + 2, m, rx, l, h, d);
    get(v);
  }
  void upd(long long l, long long h, long long d) { upd(0, 0, size, l, h, d); }
  void rev(long long v, long long lx, long long rx, long long l, long long r) {
    if (l <= lx and rx <= r) {
      modify[v] ^= 1;
      swap(tree[v][0], tree[v][1]);
      return;
    }
    if (rx <= l or r <= lx) {
      return;
    }
    push(v);
    long long m = (lx + rx) / 2;
    rev(2 * v + 1, lx, m, l, r);
    rev(2 * v + 2, m, rx, l, r);
    get(v);
  }
  void rev(long long l, long long r) { rev(0, 0, size, l, r); }
  long long ans() { return tree[0][0]; }
};
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  g.resize(n + 1);
  vector<vector<long long>> edges;
  for (long long i = 0, u, v, w; i < n - 1; ++i) {
    cin >> u >> v >> w;
    g[u].push_back({v, w});
    g[v].push_back({u, w});
    edges.push_back({u, v});
  }
  long long S = far(1), T = far(S);
  vector<long long> tin1(n + 1), tin2(n + 1), h1(n + 1), h2(n + 1),
      tout1(n + 1), tout2(n + 1), d1(n + 1), d2(n + 1), e1, e2;
  long long timer = 0;
  dfs(S, -1, tin1, tout1, d1, h1, e1, timer);
  timer = 0;
  dfs(T, -1, tin2, tout2, d2, h2, e2, timer);
  segtree ST1(n), ST2(n);
  for (long long i = 0; i < n; ++i) {
    ST1.upd(i, h1[e1[i]], d1[e1[i]]);
    ST2.upd(i, h2[e2[i]], d2[e2[i]]);
  }
  long long q;
  cin >> q;
  while (q-- > 0) {
    long long id;
    cin >> id;
    id--;
    long long u = edges[id][0], v = edges[id][1];
    if (h1[u] > h1[v])
      ST1.rev(tin1[u], tout1[u]);
    else
      ST1.rev(tin1[v], tout1[v]);
    if (h2[u] > h2[v])
      ST2.rev(tin2[u], tout2[u]);
    else
      ST2.rev(tin2[v], tout2[v]);
    cout << max(ST1.ans(), ST2.ans()) << '\n';
  }
  return 0;
}
