#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(229);
inline void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
struct info {
  long long m0 = 0, m1 = -1;
  info() {}
  info(long long a, long long b) : m0(a), m1(b) {}
  void reverse() { swap(m0, m1); }
};
info operator+(const info &a, const info &b) {
  return info(max(a.m0, b.m0), max(a.m1, b.m1));
}
struct segtree {
  segtree *l = nullptr, *r = nullptr;
  long long lb, rb;
  info val;
  long long need = 0;
  void pull() {
    if (lb + 1 < rb) {
      val = l->val + r->val;
    }
  }
  segtree() {}
  segtree(long long L, long long R, const vector<long long> &vals,
          const vector<long long> &d) {
    lb = L, rb = R;
    if (lb + 1 == rb) {
      if (vals[lb] == 0) {
        val = info(d[lb], -1);
      } else {
        val = info(-1, d[lb]);
      }
    } else {
      long long m = (lb + rb) / 2;
      l = new segtree(lb, m, vals, d);
      r = new segtree(m, rb, vals, d);
      pull();
    }
  }
  void push() {
    if (!need) return;
    val.reverse();
    if (lb + 1 < rb) {
      l->need ^= 1;
      r->need ^= 1;
    }
    need = 0;
  }
  void reverse(long long L, long long R) {
    push();
    if (L >= rb || lb >= R) return;
    if (L <= lb && R >= rb) {
      need ^= 1;
      push();
      return;
    }
    l->reverse(L, R);
    r->reverse(L, R);
    pull();
  }
  long long get() {
    push();
    return val.m0;
  }
};
vector<vector<long long> > g;
vector<vector<pair<long long, long long> > > fullgraph;
vector<long long> d, d1;
vector<long long> eiler, eiler1;
vector<long long> tin, tin1, tout, tout1;
vector<long long> vals, vals1;
void dfs0(long long v, long long p = -1) {
  for (auto u : g[v]) {
    if (u == p) continue;
    d[u] = d[v] + 1;
    dfs0(u, v);
  }
}
void dfs1(long long v, long long p = -1) {
  tin[v] = (long long)eiler.size();
  eiler.push_back(v);
  for (auto u : g[v]) {
    if (u == p) continue;
    d[u] = d[v] + 1;
    dfs1(u, v);
  }
  tout[v] = (long long)eiler.size();
}
void dfs11(long long v, long long p = -1) {
  tin1[v] = (long long)eiler1.size();
  eiler1.push_back(v);
  for (auto u : g[v]) {
    if (u == p) continue;
    d1[u] = d1[v] + 1;
    dfs11(u, v);
  }
  tout1[v] = (long long)eiler1.size();
}
pair<long long, long long> diameter(long long n) {
  d.assign(n, 0);
  eiler.clear();
  dfs0(0);
  long long root = 0;
  for (long long i = 0; i < n; ++i) {
    if (d[root] < d[i]) root = i;
  }
  tin.assign(n, 0);
  tout.assign(n, 0);
  d.assign(n, 0);
  dfs1(root);
  long long root1 = 0;
  for (long long i = 0; i < n; ++i) {
    if (d[root1] < d[i]) root1 = i;
  }
  eiler1.clear();
  d1.assign(n, 0);
  tin1.assign(n, 0);
  tout1.assign(n, 0);
  dfs11(root1);
  return {root, root1};
}
void fulldfs(long long v, long long p = -1) {
  for (auto u : fullgraph[v]) {
    if (u.first == p) continue;
    vals[u.first] = (vals[v] + u.second) % 2;
    fulldfs(u.first, v);
  }
}
void fulldfs1(long long v, long long p = -1) {
  for (auto u : fullgraph[v]) {
    if (u.first == p) continue;
    vals1[u.first] = (vals1[v] + u.second) % 2;
    fulldfs1(u.first, v);
  }
}
void solve() {
  long long n;
  cin >> n;
  g.assign(n, vector<long long>(0));
  vector<pair<long long, long long> > e(n - 1);
  fullgraph.assign(n, vector<pair<long long, long long> >(0));
  for (long long i = 0; i < n - 1; ++i) {
    long long a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
    fullgraph[a].push_back({b, c});
    fullgraph[b].push_back({a, c});
    e[i] = {a, b};
  }
  vector<pair<long long, long long> > e1 = e;
  pair<long long, long long> roots = diameter(n);
  long long root = roots.first, root1 = roots.second;
  vals.assign(n, 0);
  vals1.assign(n, 0);
  fulldfs(root);
  fulldfs1(root1);
  for (long long i = 0; i < n - 1; ++i) {
    if (d[e[i].first] > d[e[i].second]) {
      swap(e[i].first, e[i].second);
    }
    if (d1[e1[i].first] > d1[e1[i].second]) {
      swap(e1[i].first, e1[i].second);
    }
  }
  vector<long long> newvals(n, 0);
  vector<long long> newdepths(n, 0);
  for (long long i = 0; i < n; ++i) {
    newvals[i] = vals[eiler[i]];
    newdepths[i] = d[eiler[i]];
  }
  vector<long long> newvals1(n, 0);
  vector<long long> newdepths1(n, 0);
  for (long long i = 0; i < n; ++i) {
    newvals1[i] = vals1[eiler1[i]];
    newdepths1[i] = d1[eiler1[i]];
  }
  segtree *tree = new segtree(0, n, newvals, newdepths);
  segtree *tree1 = new segtree(0, n, newvals1, newdepths1);
  long long m;
  cin >> m;
  while (m--) {
    long long index;
    cin >> index;
    index--;
    long long vertex = e[index].second;
    long long vertex1 = e1[index].second;
    long long l = tin[vertex], r = tout[vertex];
    long long l1 = tin1[vertex1], r1 = tout1[vertex1];
    tree->reverse(l, r);
    tree1->reverse(l1, r1);
    cout << max(tree->get(), tree1->get()) << '\n';
  }
}
signed main() {
  fastio();
  long long T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
