#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
struct Node {
  Node *l = 0, *r = 0;
  int lo, hi;
  int mx[2];
  bool lz = 0;
  Node(int _lo, int _hi) : lo(_lo), hi(_hi) { mx[0] = mx[1] = 0; }
  Node(ii v[], int _lo, int _hi) : lo(_lo), hi(_hi) {
    mx[0] = mx[1] = 0;
    if (lo + 1 < hi) {
      int mid = lo + (hi - lo) / 2;
      l = new Node(v, lo, mid);
      r = new Node(v, mid, hi);
      for (int i : {0, 1}) mx[i] = max(l->mx[i], r->mx[i]);
    } else {
      mx[v[lo].first] = v[lo].second;
    }
  }
  void upd() {
    swap(mx[0], mx[1]);
    lz ^= 1;
  }
  void flip(int L, int R) {
    if (R <= lo || hi <= L) return;
    if (L <= lo && hi <= R) {
      upd();
    } else {
      push(), l->flip(L, R), r->flip(L, R);
      for (int i : {0, 1}) mx[i] = max(l->mx[i], r->mx[i]);
    }
  }
  void push() {
    if (lo + 1 < hi and lz) {
      l->upd(), r->upd();
    }
    lz = 0;
  }
};
const int N = 5e5 + 5;
int n, q;
int l[N], r[N], w[N];
vi g[N];
int d1, d2;
int tym;
ii dis[N];
int IN[N], OUT[N];
int EDGE[N];
ii dis_[N];
void dfs(int u, int daddy, int pe) {
  IN[u] = ++tym;
  EDGE[pe] = u;
  for (int i : g[u]) {
    int v = l[i] ^ r[i] ^ u;
    if (v != daddy) {
      dis[v] = {dis[u].first ^ w[i], dis[u].second + 1};
      dfs(v, u, i);
    }
  }
  OUT[u] = tym;
}
int main(int argc, char const *argv[]) {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    scanf("%d %d %d", &l[i], &r[i], &w[i]);
    g[l[i]].emplace_back(i);
    g[r[i]].emplace_back(i);
  }
  dis[1] = {0, 0};
  dfs(1, 0, 0);
  {
    int mx = INT_MIN;
    for (int i = 1; i <= n; ++i) {
      if (dis[i].second > mx) {
        d1 = i;
        mx = dis[i].second;
      }
    }
  }
  42;
  vi in[2], out[2], e[2];
  Node *t[2];
  dis[d1] = {0, 0}, tym = 0;
  dfs(d1, 0, 0);
  for (int i = 1; i <= n; ++i) {
    dis_[IN[i]] = dis[i];
  }
  42;
  t[0] = new Node(dis_, 1, n + 1);
  42;
  in[0] = vi(IN, IN + 1 + n);
  out[0] = vi(OUT, OUT + 1 + n);
  e[0] = vi(EDGE, EDGE + 1 + n);
  {
    int mx = INT_MIN;
    for (int i = 1; i <= n; ++i) {
      if (dis[i].second > mx) {
        d2 = i;
        mx = dis[i].second;
      }
    }
  }
  dis[d2] = {0, 0}, tym = 0;
  dfs(d2, 0, 0);
  for (int i = 1; i <= n; ++i) {
    dis_[IN[i]] = dis[i];
  }
  42;
  t[1] = new Node(dis_, 1, n + 1);
  in[1] = vi(IN, IN + 1 + n);
  out[1] = vi(OUT, OUT + 1 + n);
  e[1] = vi(EDGE, EDGE + 1 + n);
  scanf("%d", &q);
  while (q--) {
    int id;
    scanf("%d", &id);
    42;
    int ans = 0;
    for (int i : {0, 1}) {
      42;
      t[i]->flip(in[i][e[i][id]], out[i][e[i][id]] + 1);
      ans = max(ans, t[i]->mx[0]);
    }
    42;
    42;
    printf("%d\n", ans);
  }
  return 0;
}
