#include <bits/stdc++.h>
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
using namespace std;
template <typename T>
void uin(T &a, T b) {
  if (b < a) {
    a = b;
  }
}
template <typename T>
void uax(T &a, T b) {
  if (b > a) {
    a = b;
  }
}
const int N = 500 * 1000 + 228;
int left1[N], right1[N];
int left2[N], right2[N];
int h1[N], h2[N];
int parity1[N], parity2[N];
int inv1[N], inv2[N];
struct ST {
  struct node {
    int mx0;
    int mx1;
    int mod;
    int l, r;
    node() {
      mx0 = mx1 = 0;
      l = r = mod = 0;
    }
  };
  vector<node> d;
  bool kekos;
  void recalc(int v) {
    pair<int, int> l_mx = gets(v << 1);
    pair<int, int> r_mx = gets(v << 1 | 1);
    d[v].mx0 = max(l_mx.first, r_mx.first);
    d[v].mx1 = max(l_mx.second, r_mx.second);
  };
  void build(int l, int r, int v = 1) {
    d[v].l = l;
    d[v].r = r;
    if (l == r) {
      int i = l;
      if (kekos == 0) {
        if (parity1[inv1[l]] == 0) {
          d[v].mx0 = h1[inv1[l]];
        } else {
          d[v].mx1 = h1[inv1[l]];
        }
      } else {
        if (parity2[inv2[l]] == 0) {
          d[v].mx0 = h2[inv2[l]];
        } else {
          d[v].mx1 = h2[inv2[l]];
        }
      }
    } else {
      int m = (l + r) >> 1;
      build(l, m, v << 1);
      build(m + 1, r, v << 1 | 1);
      recalc(v);
    }
  }
  ST() { d.clear(); }
  ST(int _n, bool kekoz) {
    kekos = kekoz;
    int ss = 1;
    while (ss < _n) ss <<= 1;
    ss <<= 1;
    d.resize(ss + 1, node());
    build(1, _n);
  }
  pair<int, int> gets(int v) {
    if (d[v].mod == 0) {
      return {d[v].mx0, d[v].mx1};
    }
    return {d[v].mx1, d[v].mx0};
  }
  void push(int v) {
    d[v << 1].mod ^= d[v].mod;
    d[v << 1 | 1].mod ^= d[v].mod;
    d[v].mod = 0;
    recalc(v);
  }
  void inverse(int l, int r, int v = 1) {
    if (l > r || d[v].l > r || d[v].r < l) return;
    if (l <= d[v].l && d[v].r <= r) {
      d[v].mod ^= 1;
    } else {
      push(v);
      inverse(l, r, v << 1);
      inverse(l, r, v << 1 | 1);
      recalc(v);
    }
  }
  int get0(int l, int r, int v = 1) { return gets(1).first; }
  int get1(int l, int r, int v = 1) { return gets(1).second; }
};
int n, m;
vector<pair<int, int> > g[N];
int id[N];
int ans[N];
int dist[N];
void dfs(int v, int par = -1) {
  if (par == -1)
    dist[v] = 0;
  else
    dist[v] = dist[par] + 1;
  for (pair<int, int> go : g[v]) {
    int to = go.first;
    int w = go.second;
    if (to != par) {
      dfs(to, v);
    }
  }
}
int A = 0, B = 0;
int timer = 0;
void dfs1(int v, int parity = 0, int par = -1) {
  left1[v] = ++timer;
  if (par == -1)
    h1[v] = 0;
  else
    h1[v] = h1[par] + 1;
  parity1[v] = parity;
  for (pair<int, int> go : g[v]) {
    int to = go.first;
    int w = go.second;
    if (to != par) {
      dfs1(to, parity ^ w, v);
    }
  }
  right1[v] = timer;
}
void dfs2(int v, int parity = 0, int par = -1) {
  left2[v] = ++timer;
  if (par == -1)
    h2[v] = 0;
  else
    h2[v] = h2[par] + 1;
  parity2[v] = parity;
  for (pair<int, int> go : g[v]) {
    int to = go.first;
    int w = go.second;
    if (to != par) {
      dfs2(to, parity ^ w, v);
    }
  }
  right2[v] = timer;
}
vector<pair<int, int> > edges;
void proceed() {
  dfs(1);
  A = 0;
  for (int i = 1; i <= n; ++i) {
    if (dist[i] > dist[A]) A = i;
  }
  dfs(A);
  B = 0;
  for (int i = 1; i <= n; ++i) {
    if (dist[i] > dist[B]) B = i;
  }
  dfs1(A);
  timer = 0;
  dfs2(B);
  for (int v = 1; v <= n; ++v) {
    inv1[left1[v]] = v;
    inv2[left2[v]] = v;
  }
  ST st1 = ST(n, 0);
  ST st2 = ST(n, 1);
  for (int i = 0; i < m; ++i) {
    pair<int, int> e = edges[id[i] - 1];
    int u = e.first, v = e.second;
    if (h1[u] > h1[v]) swap(u, v);
    st1.inverse(left1[v], right1[v]);
    if (h2[u] > h2[v]) swap(u, v);
    st2.inverse(left2[v], right2[v]);
    ans[i] = max(st1.get0(1, n), st2.get0(1, n));
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int u, v, t;
    cin >> u >> v >> t;
    g[u].emplace_back(v, t);
    g[v].emplace_back(u, t);
    edges.emplace_back(u, v);
  }
  cin >> m;
  for (int i = 0; i < m; ++i) {
    cin >> id[i];
  }
  proceed();
  for (int i = 0; i < m; ++i) {
    cout << ans[i] << '\n';
  }
  return 0;
}
