#include <bits/stdc++.h>
struct MI {
 private:
  char bb[1 << 14];
  FILE *f;
  char *bs, *be;
  char e;
  bool o, l;

 public:
  MI() : f(stdin), bs(0), be(0) {}
  inline char get() {
    if (o) {
      o = 0;
      return e;
    }
    if (bs == be) be = (bs = bb) + fread(bb, 1, sizeof(bb), f);
    if (bs == be) {
      l = 1;
      return -1;
    };
    return *bs++;
  }
  inline void unget(char c) {
    o = 1;
    e = c;
  }
  template <class T>
  inline T read() {
    T r;
    *this > r;
    return r;
  }
  template <class T>
  inline MI &operator>(T &);
};
template <class T>
struct Q {
  const static bool U = T(-1) >= T(0);
  inline void operator()(MI &t, T &r) const {
    r = 0;
    char c;
    bool y = 0;
    if (U)
      for (;;) {
        c = t.get();
        if (c == -1) goto E;
        if (isdigit(c)) break;
      }
    else
      for (;;) {
        c = t.get();
        if (c == -1) goto E;
        if (c == '-') {
          c = t.get();
          if (isdigit(c)) {
            y = 1;
            break;
          };
        } else if (isdigit(c))
          break;
        ;
      };
    for (;;) {
      if (c == -1) goto E;
      if (isdigit(c))
        r = r * 10 + (c ^ 48);
      else
        break;
      c = t.get();
    }
    t.unget(c);
  E:;
    if (y) r = -r;
  }
};
template <>
struct Q<char> {};
template <class T>
inline MI &MI::operator>(T &t) {
  Q<T>()(*this, t);
  return *this;
}
template <class T>
std::ostream &operator<(std::ostream &out, const T &t) {
  return out << t;
}
using std::cout;
MI cin;
const int $n = 500005;
const int $t = 1048600;
template <typename T>
inline bool gmax(T &a, const T &b) {
  return a < b && (a = b, true);
}
int n, fa[$n], mx[$n], se[$n], dep[$n], es[$n][2], t1, t2, dia;
std::vector<std::pair<int, bool>> outs[$n];
bool val[$n];
void dfs(int x) {
  mx[x] = x;
  dep[x] = dep[fa[x]] + 1;
  for (auto [v, w] : outs[x]) {
    if (v == fa[x]) continue;
    fa[v] = x;
    val[v] = val[x] ^ w;
    dfs(v);
    if (dep[mx[v]] >= dep[mx[x]]) {
      se[x] = mx[x];
      mx[x] = mx[v];
    } else if (dep[mx[v]] > dep[se[x]])
      se[x] = mx[v];
  }
  if (se[x] && gmax(dia, dep[mx[x]] + dep[se[x]] - dep[x] * 2)) {
    t1 = mx[x];
    t2 = se[x];
  }
}
struct {
  int rt, fa[$n], dfn[$n], dt, siz[$n], dep[$n], seq[$n];
  int mx[$t][2], ll, rr;
  bool rv[$t];
  inline void upd(int x) {
    std::swap(mx[x][0], mx[x][1]);
    rv[x] ^= 1;
  }
  inline void pd(int x) {
    if (!rv[x]) return;
    upd((x << 1));
    upd(((x << 1) | 1));
    rv[x] = 0;
  }
  inline void pu(int x) {
    mx[x][0] = std::max(mx[(x << 1)][0], mx[((x << 1) | 1)][0]);
    mx[x][1] = std::max(mx[(x << 1)][1], mx[((x << 1) | 1)][1]);
  }
  void build(int x = 1, int l = 1, int r = n) {
    if (l == r) return (void)(mx[x][val[seq[l]]] = dep[seq[l]] - 1);
    const int mid = (l + r) >> 1;
    build((x << 1), l, mid);
    build(((x << 1) | 1), mid + 1, r);
    pu(x);
  }
  void $update(int x, int l, int r) {
    if (ll <= l && r <= rr) return upd(x);
    const int mid = (l + r) >> 1;
    pd(x);
    if (ll <= mid) $update((x << 1), l, mid);
    if (mid < rr) $update(((x << 1) | 1), mid + 1, r);
    pu(x);
  }
  inline void update(int l, int r) {
    ll = l;
    rr = r;
    $update(1, 1, n);
  }
  void dfs(int x) {
    seq[dfn[x] = ++dt] = x;
    siz[x] = 1;
    dep[x] = dep[fa[x]] + 1;
    for (auto [v, w] : outs[x]) {
      if (v == fa[x]) continue;
      fa[v] = x;
      dfs(v);
      siz[x] += siz[v];
    }
  }
  inline void init(int rt) {
    this->rt = rt;
    dfs(rt);
    build();
  }
  inline int flip(int x, int y) {
    if (fa[y] == x) std::swap(x, y);
    assert(fa[x] == y);
    update(dfn[x], dfn[x] + siz[x] - 1);
    return mx[1][val[rt]];
  }
} A, B;
int main() {
  cin > n;
  for (int i = 1; i < n; ++i) {
    const int x = es[i][0] = (cin.read<int>()),
              y = es[i][1] = (cin.read<int>()), w = (cin.read<int>());
    outs[x].emplace_back(y, w);
    outs[y].emplace_back(x, w);
  }
  dfs(1);
  A.init(t1);
  B.init(t2);
  for (int T = (cin.read<int>()); T; --T) {
    const int id = (cin.read<int>()), x = es[id][0], y = es[id][1];
    cout < std::max(A.flip(x, y), B.flip(x, y)) < ('\n');
  }
}
