#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long long MOD = 998244353;
const long double PI = acosl(-1.0);
const long double E = 1e-15;
mt19937_64 rnd(time(0));
int n, m, k, T, in1[1100001], in2[1100001], out1[1100001], out2[1100001];
pair<int, int> zn[500001];
vector<int> c[500001], z1, z2;
long long binpow(long long h, long long r, long long md) {
  long long l = 1;
  while (r) {
    if (r & 1) l *= h, l %= md;
    h *= h;
    h %= md;
    r /= 2;
  }
  return l;
}
struct segment_tree {
  pair<int, int> d[5000001];
  bool leaf[5000001], tt[5000001];
  void push(int h) {
    if (tt[h] && !leaf[h]) {
      tt[h * 2] ^= tt[h];
      swap(d[h * 2].first, d[h * 2].second);
      tt[h * 2 + 1] ^= tt[h];
      swap(d[h * 2 + 1].first, d[h * 2 + 1].second);
    }
    tt[h] = 0;
  }
  void build(int h, int l, int r, vector<int>& v) {
    if (l == r) {
      leaf[h] = 1;
      d[h] = make_pair(v[l], 0);
      return;
    }
    int w = (l + r) / 2;
    build(h * 2, l, w, v);
    build(h * 2 + 1, w + 1, r, v);
    d[h].first = max(d[h * 2].first, d[h * 2 + 1].first);
    d[h].second = max(d[h * 2].second, d[h * 2 + 1].second);
  }
  void update(int h, int l, int r, int x, int y) {
    if (x > y) return;
    push(h);
    if (l == x && y == r) {
      tt[h] = 1;
      swap(d[h].first, d[h].second);
      push(h);
      return;
    }
    int w = (l + r) / 2;
    update(h * 2, l, w, x, min(y, w));
    update(h * 2 + 1, w + 1, r, max(x, w + 1), y);
    d[h].first = max(d[h * 2].first, d[h * 2 + 1].first);
    d[h].second = max(d[h * 2].second, d[h * 2 + 1].second);
  }
};
segment_tree g1, g2;
long long mx, p1, p2;
void dfs(int h, int p = -1) {
  pair<int, int> o1 = make_pair(0, h), o2 = make_pair(0, h);
  for (int i = 0; i < c[h].size(); i++)
    if (c[h][i] != p) {
      dfs(c[h][i], h);
      if (zn[c[h][i]].first + 1 > o1.first)
        swap(o1, o2), o1 = zn[c[h][i]], o1.first++;
      else if (zn[c[h][i]].first + 1 > o2.first)
        o2 = zn[c[h][i]], o2.first++;
    }
  if (o1.first + o2.first > mx)
    mx = o1.first + o2.first, p1 = o1.second, p2 = o2.second;
  zn[h] = o1;
}
void dfs1(int h, int k = 0, int p = -1) {
  in1[h] = z1.size();
  z1.push_back(k);
  for (int i = 0; i < c[h].size(); i++)
    if (c[h][i] != p) {
      dfs1(c[h][i], k + 1, h);
    }
  out1[h] = z1.size();
  z1.push_back(k);
}
void dfs2(int h, int k = 0, int p = -1) {
  in2[h] = z2.size();
  z2.push_back(k);
  for (int i = 0; i < c[h].size(); i++)
    if (c[h][i] != p) {
      dfs2(c[h][i], k + 1, h);
    }
  out2[h] = z2.size();
  z2.push_back(k);
}
void solve() {
  cin >> n;
  long long tt = 0;
  vector<pair<int, int> > v, zpr;
  for (int i = 1; i < n; i++) {
    long long x, y, z;
    cin >> x >> y >> z;
    c[x].push_back(y);
    c[y].push_back(x);
    v.push_back(make_pair(x, y));
    if (z) zpr.push_back(make_pair(x, y));
    tt = z;
  }
  if (n == 2) {
    long long q;
    cin >> q;
    for (int i = 0; i < q; i++) {
      long long x;
      cin >> x;
      tt ^= 1;
      cout << (tt ? 0 : 1) << "\n";
    }
    exit(0);
  }
  dfs(1);
  dfs1(p1);
  dfs2(p2);
  g1.build(1, 0, z1.size() - 1, z1);
  g2.build(1, 0, z2.size() - 1, z2);
  for (int i = 0; i < zpr.size(); i++) {
    int x = zpr[i].first, y = zpr[i].second;
    if (in1[x] > in1[y]) swap(x, y);
    g1.update(1, 0, z1.size() - 1, in1[y], out1[y]);
    if (in2[x] > in2[y]) swap(x, y);
    g2.update(1, 0, z2.size() - 1, in2[y], out2[y]);
  }
  long long q;
  cin >> q;
  while (q--) {
    long long h;
    cin >> h;
    h--;
    int x = v[h].first, y = v[h].second;
    if (in1[x] > in1[y]) swap(x, y);
    g1.update(1, 0, z1.size() - 1, in1[y], out1[y]);
    if (in2[x] > in2[y]) swap(x, y);
    g2.update(1, 0, z2.size() - 1, in2[y], out2[y]);
    cout << max(g1.d[1].first, g2.d[1].first) << "\n";
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
