#include <bits/stdc++.h>
using namespace std;
template <class node>
struct link_cut_tree {
  void link(node* u, node* v) {
    access(v);
    access(u);
    set_link(v, u, 0);
    v->update();
  }
  void access(node* u) {
    for (node *v = u, *pre = NULL; v; v = v->p) {
      v->splay();
      if (pre) v->update_vsub(pre, false);
      if (v->ch[1]) v->update_vsub(v->ch[1], true);
      v->ch[1] = pre;
      v->update();
      pre = v;
    }
    u->splay();
    assert(!u->ch[1]);
  }
  node* operator[](int i) { return &data[i]; }
  int operator[](node* i) { return i - &data[0]; }
  vector<node> data;
  link_cut_tree(int n) : data(n) {}
};
template <typename pnode>
struct splay_tree {
  pnode ch[2], p;
  splay_tree() { ch[0] = ch[1] = p = NULL; }
  virtual void update() {}
  virtual void push() {}
  int dir() {
    if (!p) return -2;
    if (p->ch[0] == this) return 0;
    if (p->ch[1] == this) return 1;
    return -1;
  }
  bool is_root() { return dir() < 0; }
  friend void set_link(pnode u, pnode v, int d) {
    if (v) v->p = u;
    if (d >= 0) u->ch[d] = v;
  }
  void rotate() {
    assert(!is_root());
    int x = dir();
    pnode g = p;
    set_link(g->p, static_cast<pnode>(this), g->dir());
    set_link(g, ch[x ^ 1], x);
    set_link(static_cast<pnode>(this), g, x ^ 1);
    g->update();
  }
  void splay() {
    while (!is_root() && !p->is_root()) {
      p->p->push(), p->push(), push();
      dir() == p->dir() ? p->rotate() : rotate();
      rotate();
    }
    if (!is_root()) p->push(), push(), rotate();
    push();
    update();
  }
};
const int inf = -1e8;
const array<int, 4> ainf = {0, inf, 0, inf};
struct node : splay_tree<node*> {
  bool val, len, sval;
  int slen;
  int x;
  array<int, 4> pp;
  priority_queue<int> vx, dvx;
  array<priority_queue<int>, 2> vp, dvp;
  node() : splay_tree() {
    val = len = sval = 0;
    slen = x = 0;
    pp = ainf;
  }
  template <typename T>
  void fix(priority_queue<T>& p, priority_queue<T>& d) {
    while (!d.empty() && p.top() == d.top()) p.pop(), d.pop();
  }
  void update() override {
    splay_tree::update();
    x = 0;
    sval = val;
    slen = len;
    array<int, 4> up = ainf, dw = ainf;
    array<int, 2> v1 = {0, inf}, v2 = v1;
    bool upsval = val;
    int upslen = len;
    bool dwsval = val;
    int dwslen = len;
    if (ch[0]) {
      x = max(x, ch[0]->x);
      up = ch[0]->pp;
      sval ^= ch[0]->sval;
      slen += ch[0]->slen;
      upsval ^= ch[0]->sval;
      upslen += ch[0]->slen;
    }
    if (ch[1]) {
      x = max(x, ch[1]->x);
      dw = ch[1]->pp;
      sval ^= ch[1]->sval;
      slen += ch[1]->slen;
      dwsval ^= ch[1]->sval;
      dwslen += ch[1]->slen;
    }
    if (!vx.empty()) {
      x = max(x, vx.top());
    }
    if (!vp[0].empty()) {
      v1[0] = vp[0].top();
      v1[1] = vp[1].top();
      if (!val) {
        vp[0].pop();
        vp[1].pop();
        fix(vp[0], dvp[0]);
        fix(vp[1], dvp[1]);
        if (!vp[0].empty()) {
          v2[0] = vp[0].top();
          v2[1] = vp[1].top();
        }
        vp[0].push(v1[0]);
        vp[1].push(v1[1]);
      }
    }
    pp[0] = up[0], pp[1] = up[1];
    pp[2] = dw[2], pp[3] = dw[3];
    for (int i = 0; i < 2; ++i) {
      x = max(x, len + max({up[2 + i] + dw[i ^ val], up[2 + i] + v1[i ^ val],
                            dw[i] + v1[i ^ val], v1[i] + v2[i ^ val]}));
      pp[i ^ upsval] = max(pp[i ^ upsval], upslen + max(dw[i], v1[i]));
      pp[2 + (i ^ dwsval)] =
          max(pp[2 + (i ^ dwsval)], dwslen + max(up[2 + i], v1[i]));
    }
  }
  void update_vsub(node* v, bool add) {
    if (add) {
      vx.push(v->x);
      vp[0].push(v->pp[0]);
      vp[1].push(v->pp[1]);
    } else {
      dvx.push(v->x);
      dvp[0].push(v->pp[0]);
      dvp[1].push(v->pp[1]);
      fix(vx, dvx);
      fix(vp[0], dvp[0]);
      fix(vp[1], dvp[1]);
    }
  }
};
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n;
  cin >> n;
  link_cut_tree<node> lct(2 * n);
  vector<vector<tuple<int, bool, int>>> adj(n);
  for (int i = 1, u, v, w; i < n; ++i) {
    cin >> u >> v >> w;
    --u, --v;
    adj[u].push_back({v, w, i});
    adj[v].push_back({u, w, i});
  }
  function<void(int, int)> dfs = [&](int u, int p) {
    for (auto [v, w, i] : adj[u])
      if (v != p) {
        dfs(v, u);
        lct[n + i]->val = w;
        lct[n + i]->len = true;
        lct[n + i]->update();
        lct.link(lct[u], lct[n + i]);
        lct.link(lct[n + i], lct[v]);
      }
  };
  dfs(0, -1);
  int q;
  cin >> q;
  for (int i = 0, u; i < q; ++i) {
    cin >> u;
    lct.access(lct[n + u]);
    lct[n + u]->val ^= 1;
    lct[n + u]->update();
    cout << lct[n + u]->x << "\n";
  }
  return 0;
}
