#include <bits/stdc++.h>
using namespace std;
const long long maxn = 5e5;
vector<pair<long long, long long>> g[maxn];
long long v1 = 0;
long long v2 = 0;
vector<pair<pair<long long, long long>, long long>> t1(maxn * 4);
vector<pair<pair<long long, long long>, long long>> t2(maxn * 4);
vector<long long> pp1;
vector<pair<pair<long long, long long>, long long>> op1(maxn);
vector<long long> pp2;
vector<pair<pair<long long, long long>, long long>> op2(maxn);
long long n;
long long dist[maxn];
void push(vector<pair<pair<long long, long long>, long long>> &t, long long v) {
  if (t[v].second == 1) {
    t[v].second = 0;
    t[v * 2].second ^= 1;
    swap(t[v * 2].first.first, t[v * 2].first.second);
    t[v * 2 + 1].second ^= 1;
    swap(t[v * 2 + 1].first.first, t[v * 2 + 1].first.second);
  }
}
void upd(vector<pair<pair<long long, long long>, long long>> &t, long long v,
         long long tl, long long tr, long long pos, long long dist,
         long long T) {
  if (tl == tr) {
    if (T == 0) {
      t[v].first.first = dist;
      t[v].first.second = 0;
    } else {
      t[v].first.first = 0;
      t[v].first.second = dist;
    }
    return;
  }
  long long tm = (tl + tr) / 2;
  if (pos <= tm) {
    upd(t, v * 2, tl, tm, pos, dist, T);
  } else {
    upd(t, v * 2 + 1, tm + 1, tr, pos, dist, T);
  }
  t[v].first.first = max(t[v * 2].first.first, t[v * 2 + 1].first.first);
  t[v].first.second = max(t[v * 2].first.second, t[v * 2 + 1].first.second);
}
void update(vector<pair<pair<long long, long long>, long long>> &t, long long v,
            long long tl, long long tr, long long l, long long r) {
  if (tl > r || tr < l) return;
  if (l <= tl && tr <= r) {
    swap(t[v].first.first, t[v].first.second);
    t[v].second ^= 1;
    return;
  }
  push(t, v);
  long long tm = (tl + tr) / 2;
  update(t, v * 2, tl, tm, l, r);
  update(t, v * 2 + 1, tm + 1, tr, l, r);
  t[v].first.first = max(t[v * 2].first.first, t[v * 2 + 1].first.first);
  t[v].first.second = max(t[v * 2].first.second, t[v * 2 + 1].first.second);
}
long long get(vector<pair<pair<long long, long long>, long long>> &t,
              long long v, long long tl, long long tr, long long l,
              long long r) {
  if (tl > r || tr < l) return 0;
  if (l <= tl && tr <= r) {
    if (t[v].second == 1) {
      return t[v].first.second;
    } else
      return t[v].first.first;
  }
  push(t, v);
  long long tm = (tl + tr) / 2;
  return max(get(t, v * 2, tl, tm, l, r), get(t, v * 2 + 1, tm + 1, tr, l, r));
}
void dfs(vector<pair<pair<long long, long long>, long long>> &t,
         vector<long long> &pp,
         vector<pair<pair<long long, long long>, long long>> &op, long long v,
         long long p, long long sum, long long H) {
  upd(t, 1, 0, n - 1, pp.size(), H, sum % 2);
  op[v].first.first = pp.size();
  op[v].second = H;
  pp.push_back(v);
  for (long long i = 0; i < g[v].size(); ++i) {
    long long to = g[v][i].first;
    if (to == p) continue;
    dfs(t, pp, op, to, v, sum + g[v][i].second, H + 1);
  }
  op[v].first.second = pp.size() - 1;
}
void jupaS(long long v, long long p) {
  for (long long i = 0; i < g[v].size(); ++i) {
    long long to = g[v][i].first;
    if (to == p) continue;
    dist[to] = dist[v] + 1;
    jupaS(to, v);
  }
}
signed main() {
  cin.tie();
  cout.tie();
  ios_base::sync_with_stdio(false);
  cin >> n;
  vector<pair<long long, long long>> y;
  for (long long i = 0; i < n - 1; ++i) {
    long long a, b, t;
    cin >> a >> b >> t;
    a--;
    b--;
    y.push_back({a, b});
    g[a].push_back({b, t});
    g[b].push_back({a, t});
  }
  jupaS(0, -1);
  long long mx = 0;
  for (long long k = 0; k < n; ++k) {
    if (dist[mx] < dist[k]) mx = k;
  }
  v1 = mx;
  dist[v1] = 0;
  jupaS(v1, -1);
  mx = 0;
  for (long long k = 0; k < n; ++k) {
    if (dist[mx] < dist[k]) mx = k;
  }
  v2 = mx;
  dfs(t1, pp1, op1, v1, -1, 0, 0);
  dfs(t2, pp2, op2, v2, -1, 0, 0);
  long long q;
  cin >> q;
  for (long long j = 0; j < q; ++j) {
    long long id;
    cin >> id;
    id--;
    long long a = y[id].first;
    long long b = y[id].second;
    if (op1[a].second > op1[b].second) swap(a, b);
    update(t1, 1, 0, n - 1, op1[b].first.first, op1[b].first.second);
    if (op2[a].second > op2[b].second) swap(a, b);
    update(t2, 1, 0, n - 1, op2[b].first.first, op2[b].first.second);
    long long mx = get(t1, 1, 0, n - 1, 0, n - 1);
    long long mx1 = get(t2, 1, 0, n - 1, 0, n - 1);
    cout << max(mx, mx1) << "\n";
  }
}
