#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const double EPS = 1e-9;
const double PI = acos(-1.);
const long long LL_INF = 1e17 + 16;
const int INF = 1e9 + 10;
const long long MOD = 1e9 + 7;
const int MAXN = 5e5 + 5;
struct edge {
  int s, to, t;
  edge() {}
  edge(int _s, int _to, int _t) { s = _s, to = _to, t = _t; }
  int get_to(int from) { return from == s ? to : s; }
} ee[MAXN];
vector<int> g[MAXN];
int used[MAXN];
int dis[2][MAXN];
void dfs1(int ind, int s) {
  used[s] = 1;
  for (int i = (0); i < (int)((int)(g[s]).size()); i++) {
    int to = ee[g[s][i]].get_to(s);
    if (!used[to]) {
      dis[ind][to] = dis[ind][s] + 1;
      dfs1(ind, to);
    }
  }
}
int tin[2][MAXN], tout[2][MAXN], _timer[2];
int ee_to[2][MAXN];
void dfs2(int ind, int s) {
  used[s] = 1;
  tin[ind][s] = tout[ind][s] = _timer[ind]++;
  for (int i = (0); i < (int)((int)(g[s]).size()); i++) {
    int to = ee[g[s][i]].get_to(s);
    if (!used[to]) {
      ee_to[ind][g[s][i]] = to;
      dfs2(ind, to);
      tout[ind][s] = tout[ind][to];
    }
  }
}
struct item {
  int val[2];
  int t;
  item() { val[0] = val[1] = t = 0; }
  void swap() {
    t ^= 1;
    std::swap(val[0], val[1]);
  }
};
template <typename temp_type>
struct segment_tree {
  int n;
  int vals[MAXN];
  temp_type tt[4 * MAXN];
  temp_type combine(const temp_type &v1, const temp_type &v2) {
    temp_type res;
    res.t = 0;
    for (int i = (0); i < (int)(2); i++) {
      res.val[i] = max(v1.val[i], v2.val[i]);
    }
    return res;
  }
  void push(int ind) {
    if (tt[ind].t) {
      tt[ind].swap();
      tt[ind << 1].swap();
      tt[(ind << 1) + 1].swap();
    }
  }
  void build(int ind, int tl, int tr) {
    if (tl == tr) {
      tt[ind].t = 0;
      tt[ind].val[0] = vals[tl];
      tt[ind].val[1] = -1;
      return;
    }
    int tm = (tl + tr) >> 1;
    build(ind << 1, tl, tm);
    build((ind << 1) + 1, tm + 1, tr);
    tt[ind] = combine(tt[ind << 1], tt[(ind << 1) + 1]);
  }
  temp_type get_val(int ind, int tl, int tr, int l, int r) {
    if (tl == l && tr == r) {
      return tt[ind];
    }
    push(ind);
    int tm = (tl + tr) >> 1;
    temp_type result;
    if (r <= tm) {
      result = get_val(ind << 1, tl, tm, l, r);
    } else if (l > tm) {
      result = get_val((ind << 1) + 1, tm + 1, tr, l, r);
    } else {
      result = combine(get_val(ind << 1, tl, tm, l, tm),
                       get_val((ind << 1) + 1, tm + 1, tr, tm + 1, r));
    }
    return result;
  }
  void upd_val(int ind, int tl, int tr, int l, int r) {
    if (tl == l && tr == r) {
      tt[ind].swap();
      return;
    }
    push(ind);
    int tm = (tl + tr) >> 1;
    if (r <= tm) {
      upd_val(ind << 1, tl, tm, l, r);
    } else if (l > tm) {
      upd_val((ind << 1) + 1, tm + 1, tr, l, r);
    } else {
      upd_val(ind << 1, tl, tm, l, tm);
      upd_val((ind << 1) + 1, tm + 1, tr, tm + 1, r);
    }
    tt[ind] = combine(tt[ind << 1], tt[(ind << 1) + 1]);
  }
  void build() { build(1, 0, n - 1); }
  temp_type get_val(int l, int r) { return get_val(1, 0, n - 1, l, r); }
  void upd_val(int l, int r) { upd_val(1, 0, n - 1, l, r); }
};
segment_tree<item> tt[2];
void solve() {
  int n;
  scanf("%d", &n);
  for (int i = (1); i < (int)(n); i++) {
    scanf("%d%d%d", &ee[i].s, &ee[i].to, &ee[i].t);
    g[ee[i].s].push_back(i);
    g[ee[i].to].push_back(i);
  }
  dfs1(0, 1);
  int s = 1;
  for (int i = (1); i <= (int)(n); i++) {
    if (dis[0][s] < dis[0][i]) {
      s = i;
    }
    used[i] = 0;
  }
  dis[0][s] = 0;
  dfs1(0, s);
  int f = 1;
  for (int i = (1); i <= (int)(n); i++) {
    if (dis[0][f] < dis[0][i]) {
      f = i;
    }
    used[i] = 0;
  }
  dfs1(1, f);
  for (int i = (1); i <= (int)(n); i++) {
    used[i] = 0;
  }
  dfs2(0, s);
  for (int i = (1); i <= (int)(n); i++) {
    used[i] = 0;
  }
  dfs2(1, f);
  for (int k = (0); k < (int)(2); k++) {
    tt[k].n = n;
    for (int i = (1); i <= (int)(n); i++) {
      tt[k].vals[tin[k][i]] = dis[k][i];
    }
    tt[k].build();
  }
  for (int i = (1); i < (int)(n); i++) {
    if (ee[i].t) {
      for (int k = (0); k < (int)(2); k++) {
        int l = tin[k][ee_to[k][i]];
        int r = tout[k][ee_to[k][i]];
        tt[k].upd_val(l, r);
      }
    }
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int x;
    scanf("%d", &x);
    for (int k = (0); k < (int)(2); k++) {
      int l = tin[k][ee_to[k][x]];
      int r = tout[k][ee_to[k][x]];
      tt[k].upd_val(l, r);
    }
    int ans =
        max(tt[0].get_val(0, n - 1).val[0], tt[1].get_val(0, n - 1).val[0]);
    printf("%d\n", ans);
  }
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
}
