#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 10;
const int MAXM = 4e6 + 10;
const long long MOD = 1e9 + 7;
const long long INF = 0x3f3f3f3f;
const unsigned long long BASE = 233;
const int base = 5;
mt19937_64 mt(time(0));
char rubbish[110];
bool GETDATA;
inline long long read() {
  long long x = 0, f = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = -1;
  } while (ch < '0' || ch > '9');
  do {
    x = x * 10 + ch - 48;
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return x * f;
}
inline void write(long long x, char con = '\n') {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10, 0);
  putchar(x % 10 + '0');
  if (con) {
    printf("%c", con);
  }
}
long long N, M, K, Q;
pair<int, int> a[MAXN];
int con[MAXN];
vector<int> es[MAXN];
bool vis[MAXN];
struct SegmentTree {
  int b[MAXN];
  int depth[MAXN];
  pair<int, int> idx[MAXN];
  int ord[MAXN];
  pair<int, int> seg[MAXN << 2];
  int lz[MAXN << 2];
  int cnt;
  int root;
  void dfs(int u, int fa, int floor) {
    int v;
    depth[u] = floor;
    idx[u].first = ++cnt;
    ord[cnt] = u;
    for (int i : es[u]) {
      v = a[i].first == u ? a[i].second : a[i].first;
      if (v == fa) {
        continue;
      }
      b[v] = con[i] ? (b[u] ^ 1) : b[u];
      dfs(v, u, floor + 1);
    }
    idx[u].second = cnt;
  }
  void pushup(int o) {
    seg[o].first = max(seg[(o << 1)].first, seg[(o << 1 | 1)].first);
    seg[o].second = max(seg[(o << 1)].second, seg[(o << 1 | 1)].second);
  }
  void pushdown(int o) {
    if (lz[o]) {
      swap(seg[(o << 1)].first, seg[(o << 1)].second);
      swap(seg[(o << 1 | 1)].first, seg[(o << 1 | 1)].second);
      lz[(o << 1)] ^= 1;
      lz[(o << 1 | 1)] ^= 1;
      lz[o] ^= 1;
    }
  }
  void build(int o, int l, int r) {
    lz[o] = 0;
    if (l == r) {
      seg[o].first = b[ord[l]] ? 0 : depth[ord[l]];
      seg[o].second = b[ord[l]] ? depth[ord[l]] : 0;
      return;
    }
    int m = l + r >> 1;
    build((o << 1), l, m);
    build((o << 1 | 1), m + 1, r);
    pushup(o);
  }
  void updata(int o, int l, int r, int x, int y) {
    if (x <= l && r <= y) {
      lz[o] ^= 1;
      swap(seg[o].first, seg[o].second);
      return;
    }
    int m = l + r >> 1;
    pushdown(o);
    if (x <= m) {
      updata((o << 1), l, m, x, y);
    }
    if (m < y) {
      updata((o << 1 | 1), m + 1, r, x, y);
    }
    pushup(o);
  }
  void seg_init(int _root) {
    cnt = 0;
    root = _root;
    b[root] = 0;
    dfs(root, root, 0);
    build(1, 1, cnt);
  }
  int query(int now) {
    now = depth[a[now].first] > depth[a[now].second] ? a[now].first
                                                     : a[now].second;
    updata(1, 1, N, idx[now].first, idx[now].second);
    return seg[1].first;
  }
} A, B;
int Find(int x) {
  queue<pair<int, int> > q;
  pair<int, int> now;
  int u, v;
  for (int i = 1; i <= N; i++) {
    vis[i] = false;
  }
  while (!q.empty()) {
    q.pop();
  }
  q.push(pair<int, int>(x, 0));
  while (!q.empty()) {
    now = q.front();
    q.pop();
    u = now.first;
    vis[u] = true;
    now.second++;
    for (int i : es[u]) {
      v = a[i].first == u ? a[i].second : a[i].first;
      if (vis[v]) {
        continue;
      }
      now.first = v;
      q.push(now);
    }
  }
  return u;
}
void init() {
  for (int i = 1; i <= N; i++) {
    es[i].clear();
  }
}
void solve() {
  long long ans = 0;
  int now;
  N = read();
  init();
  for (int i = 1; i < N; i++) {
    a[i] = pair<int, int>{read(), read()};
    con[i] = read();
    es[a[i].first].push_back(i);
    es[a[i].second].push_back(i);
  }
  now = Find(1);
  A.seg_init(now);
  now = Find(now);
  B.seg_init(now);
  M = read();
  while (M--) {
    now = read();
    write(max(A.query(now), B.query(now)));
  }
}
int main() {
  int T;
  T = 1;
  for (int t = 1; t <= T; t++) {
    GETDATA = false;
    solve();
  }
  return 0;
}
