#include <bits/stdc++.h>
using namespace std;
inline int readint() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
int _tmp[20];
int _tn;
inline void printint(int x) {
  int f = 1;
  if (x == 0) {
    puts("0");
    return;
  }
  if (x < 0) {
    f = -1;
    x = -x;
  }
  _tn = 0;
  while (x) {
    _tmp[++_tn] = x % 10;
    x /= 10;
  }
  if (f == -1) putchar('-');
  for (int i = _tn; i >= 1; i--) putchar('0' + _tmp[i]);
  puts("");
}
inline void chmax(int &x, int y) { x = max(x, y); }
const int N = 5e5 + 5;
const int INF = 123456789;
int n, m, t = 1, q;
int X[N], Y[N], Z[N], p[N], B[N], E[N], d[N], poi[N * 2];
vector<int> nei[N];
void dfs(int x) {
  B[x] = E[x] = ++m;
  poi[m] = x;
  for (int i = 0; i < int(nei[x].size()); i++) {
    int to = nei[x][i];
    if (to != p[x]) {
      p[to] = x;
      d[to] = d[x] + 1;
      dfs(to);
      E[x] = ++m;
      poi[m] = x;
    }
  }
}
int lson[N * 4];
int rson[N * 4];
int val1[2][N * 4];
int val2[N * 4];
int val3[2][N * 4];
int val4[2][N * 4];
int val5[2][N * 4];
int tag[N * 4];
void update(int pos) {
  for (int i = 0; i < 2; i++) {
    val1[i][pos] = max(val1[i][lson[pos]], val1[i][rson[pos]]);
    val3[i][pos] = max(val3[i][lson[pos]], val3[i][rson[pos]]);
    val4[i][pos] = max(val4[i][lson[pos]], val4[i][rson[pos]]);
    val5[i][pos] = max(val5[i][lson[pos]], val5[i][rson[pos]]);
  }
  val2[pos] = max(val2[lson[pos]], val2[rson[pos]]);
  for (int i = 0; i < 2; i++) {
    if (val1[i][lson[pos]] != -INF && val2[rson[pos]] != -INF)
      chmax(val3[i][pos], val1[i][lson[pos]] + val2[rson[pos]]);
    if (val2[lson[pos]] != -INF && val1[i][rson[pos]] != -INF)
      chmax(val4[i][pos], val2[lson[pos]] + val1[i][rson[pos]]);
  }
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 2; j++) {
      if (val1[i][lson[pos]] != -INF && val4[i][rson[pos]] != -INF)
        chmax(val5[i ^ j][pos], val1[i][lson[pos]] + val4[i][rson[pos]]);
      if (val3[i][lson[pos]] != -INF && val1[i][rson[pos]] != -INF)
        chmax(val5[i ^ j][pos], val3[i][lson[pos]] + val1[i][rson[pos]]);
    }
}
void flip(int pos) {
  tag[pos] ^= 1;
  swap(val1[0][pos], val1[1][pos]);
  swap(val3[0][pos], val3[1][pos]);
  swap(val4[0][pos], val4[1][pos]);
}
void pushdown(int pos) {
  if (tag[pos]) {
    flip(lson[pos]);
    flip(rson[pos]);
    tag[pos] = 0;
  }
}
void build(int pos, int x, int y) {
  for (int i = 0; i < 2; i++)
    val1[i][pos] = val3[i][pos] = val4[i][pos] = val5[i][pos] = -INF;
  val2[pos] = -INF;
  if (x == y) {
    val1[0][pos] = d[poi[x]];
    val2[pos] = -2 * d[poi[x]];
    val3[0][pos] = val4[0][pos] = -d[poi[x]];
    val5[0][pos] = 0;
    return;
  }
  int mid = (x + y) >> 1;
  lson[pos] = ++t;
  rson[pos] = ++t;
  build(lson[pos], x, mid);
  build(rson[pos], mid + 1, y);
  update(pos);
}
void modify(int pos, int x, int y, int l, int r) {
  if (x >= l && y <= r) {
    flip(pos);
    return;
  }
  if (x > r || y < l) return;
  pushdown(pos);
  int mid = (x + y) >> 1;
  modify(lson[pos], x, mid, l, r);
  modify(rson[pos], mid + 1, y, l, r);
  update(pos);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d%d", X + i, Y + i, Z + i);
    nei[X[i]].push_back(Y[i]);
    nei[Y[i]].push_back(X[i]);
  }
  p[1] = 1;
  dfs(1);
  build(1, 1, m);
  for (int i = 1; i < n; i++)
    if (Z[i]) {
      int x = X[i], y = Y[i];
      if (p[y] == x) swap(x, y);
      modify(1, 1, m, B[x], E[x]);
    }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int id;
    scanf("%d", &id);
    int x = X[id], y = Y[id];
    if (p[y] == x) swap(x, y);
    modify(1, 1, m, B[x], E[x]);
    printf("%d\n", val5[0][1]);
  }
  return 0;
}
