#include <bits/stdc++.h>
using namespace std;
struct Info {
  int u, type;
};
const int INF = 1e9;
struct segment_tree {
  vector<int> _max1;
  vector<int> _max2;
  vector<int> promise;
  vector<bool> used;
  vector<int> tin;
  vector<int> tout;
  int timer;
  segment_tree(vector<vector<Info> > &g, int _u) {
    timer = 0;
    int n = (1 << 21);
    _max1.resize(n, 0);
    _max2.resize(n, 0);
    used.resize(n, false);
    tin.resize(1 << 20);
    tout.resize(1 << 20);
    dfs1(_u, g, 0, 0);
    promise.resize(n, -INF);
    build();
  }
  void build() {
    int now = (1 << 19) - 2;
    while (now >= 0) {
      promise[now] = 0;
      _max1[now] = max(_max1[now * 2 + 1], _max1[now * 2 + 2]);
      _max2[now] = max(_max2[now * 2 + 1], _max2[now * 2 + 2]);
      now--;
    }
  }
  void dfs1(int v, vector<vector<Info> > &g, int parity, int height) {
    tin[v] = timer++;
    if (parity == 0)
      _max1[(1 << 19) - 1 + tin[v]] = height;
    else
      _max2[(1 << 19) - 1 + tin[v]] = height;
    used[v] = true;
    for (auto [_u, _type] : g[v]) {
      if (!used[_u]) {
        dfs1(_u, g, parity ^ _type, height + 1);
      }
    }
    tout[v] = timer;
  }
  void push(int v) {
    if (promise[v] == 1) {
      promise[v] = 0;
      swap(_max1[2 * v + 1], _max2[2 * v + 1]);
      swap(_max1[2 * v + 2], _max2[2 * v + 2]);
      promise[2 * v + 1] ^= 1;
      promise[2 * v + 2] ^= 1;
    }
  }
  void updute(int v, int l, int r, int lq, int rq) {
    if (lq >= r || l >= rq) {
      return;
    }
    if (l >= lq && r <= rq) {
      promise[v] ^= 1;
      swap(_max1[v], _max2[v]);
      return;
    }
    push(v);
    int m = (l + r) / 2;
    updute(v * 2 + 1, l, m, lq, rq);
    updute(v * 2 + 2, m, r, lq, rq);
    _max1[v] = max(_max1[2 * v + 1], _max1[2 * v + 2]);
    _max2[v] = max(_max2[2 * v + 1], _max2[2 * v + 2]);
  }
  int Answer(int q) {
    updute(0, 0, (1 << 19), tin[q], tout[q]);
    return _max1[0];
  }
  void write(int v, int l, int r) {
    push(v);
    if (l + 1 == r) {
      cout << _max1[v] << ' ' << _max2[v] << '\n';
      return;
    }
    int m = (l + r) / 2;
    write(v * 2 + 1, l, m);
    write(v * 2 + 2, m, r);
  }
};
void dfs(int v, vector<bool> &used, vector<vector<Info> > &g, vector<int> &d) {
  used[v] = true;
  for (auto [_u, _type] : g[v]) {
    if (!used[_u]) {
      d[_u] = d[v] + 1;
      dfs(_u, used, g, d);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<vector<Info> > g(n);
  vector<pair<int, int> > numbers;
  for (int i = 0; i < n - 1; ++i) {
    int _u, _v, _type;
    cin >> _v >> _u >> _type;
    numbers.push_back({_v - 1, _u - 1});
    g[_v - 1].push_back(Info{_u - 1, _type});
    g[_u - 1].push_back(Info{_v - 1, _type});
  }
  vector<bool> used(n, false);
  vector<int> d(n, 0);
  dfs(0, used, g, d);
  int _u = 0;
  for (int i = 0; i < n; ++i) {
    if (d[i] > d[_u]) {
      _u = i;
    }
  }
  used.assign(n, false);
  d.assign(n, 0);
  dfs(_u, used, g, d);
  int _v = 0;
  for (int i = 0; i < n; ++i) {
    if (d[i] > d[_v]) {
      _v = i;
    }
  }
  segment_tree st1(g, _u);
  segment_tree st2(g, _v);
  int m;
  cin >> m;
  for (int i = 0; i < m; ++i) {
    int q, q1, q2;
    cin >> q;
    if (st1.tin[numbers[q - 1].first] > st1.tin[numbers[q - 1].second])
      q1 = numbers[q - 1].first;
    else
      q1 = numbers[q - 1].second;
    if (st2.tin[numbers[q - 1].first] > st2.tin[numbers[q - 1].second])
      q2 = numbers[q - 1].first;
    else
      q2 = numbers[q - 1].second;
    cout << max(st1.Answer(q1), st2.Answer(q2)) << '\n';
  }
}
