#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > AdjList[500005];
int id[500005];
int A[500005];
int B[500005];
int T[500005];
int ans[500005];
int n, m;
int dist1[500005];
int dist2[500005];
int indx[500005];
int right1[500005];
int inv[500005];
bool visited[500005];
int cnt;
void dfs(int u, int d1, int d2) {
  if (visited[u]) {
    return;
  }
  visited[u] = true;
  dist1[u] = d1;
  dist2[u] = d2;
  indx[u] = cnt;
  inv[cnt] = u;
  cnt++;
  for (pair<int, int> v : AdjList[u]) {
    if (!visited[v.first]) {
      dfs(v.first, d1 + 1, d2 ^ v.second);
    }
  }
  right1[u] = cnt - 1;
}
int findFurthestVertex(int root) {
  for (int i = 1; i <= n; i++) {
    visited[i] = 0;
  }
  cnt = 1;
  dfs(root, 0, 0);
  int maxDist = -1;
  int bestVertex = -1;
  for (int i = 1; i <= n; i++) {
    if (dist1[i] > maxDist) {
      maxDist = dist1[i];
      bestVertex = i;
    }
  }
  return bestVertex;
}
int max0[(1 << 20) + 5];
int max1[(1 << 20) + 5];
int lazyterbalik[(1 << 20) + 5];
void init(int i = 1, int s = 1, int e = n) {
  if (s == e) {
    lazyterbalik[i] = 0;
    if (dist2[inv[s]] == 0) {
      max0[i] = dist1[inv[s]];
      max1[i] = -1;
    } else {
      max1[i] = dist1[inv[s]];
      max0[i] = -1;
    }
    return;
  } else {
    int l = (i << 1);
    int r = (i << 1) | 1;
    int m = (s + e) >> 1;
    init(l, s, m);
    init(r, m + 1, e);
    max0[i] = max(max0[l], max0[r]);
    max1[i] = max(max1[l], max1[r]);
    lazyterbalik[i] = 0;
  }
}
void propagate(int i, int s, int e) {
  if (lazyterbalik[i]) {
    if (s == e) {
      swap(max0[i], max1[i]);
      lazyterbalik[i] = 0;
      return;
    } else {
      int l = (i << 1);
      int r = (i << 1) | 1;
      lazyterbalik[l] ^= 1;
      lazyterbalik[r] ^= 1;
      swap(max0[i], max1[i]);
      lazyterbalik[i] = 0;
      return;
    }
  }
}
void update(int x, int y, int i = 1, int s = 1, int e = n) {
  propagate(i, s, e);
  if (x <= s && e <= y) {
    lazyterbalik[i] ^= 1;
    return;
  } else {
    int l = (i << 1);
    int r = (i << 1) | 1;
    int m = (s + e) >> 1;
    if (x > m) {
      update(x, y, r, m + 1, e);
    } else if (y <= m) {
      update(x, y, l, s, m);
    } else {
      update(x, y, l, s, m);
      update(x, y, r, m + 1, e);
    }
    propagate(l, s, m);
    propagate(r, m + 1, e);
    max0[i] = max(max0[l], max0[r]);
    max1[i] = max(max1[l], max1[r]);
  }
}
int query() {
  propagate(1, 1, n);
  return max0[1];
}
void findAns(int root) {
  findFurthestVertex(root);
  init();
  for (int i = 1; i <= m; i++) {
    int u = A[id[i]];
    int v = B[id[i]];
    if (dist1[u] < dist1[v]) {
      swap(u, v);
    }
    update(indx[u], right1[u]);
    ans[i] = max(ans[i], query());
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d%d", &A[i], &B[i], &T[i]);
    AdjList[A[i]].push_back(pair<int, int>(B[i], T[i]));
    AdjList[B[i]].push_back(pair<int, int>(A[i], T[i]));
  }
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d", &id[i]);
  }
  memset(ans, -1, sizeof(ans));
  int root = findFurthestVertex(1);
  findAns(root);
  int root2 = findFurthestVertex(root);
  findAns(root2);
  for (int i = 1; i <= m; i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
