#include <bits/stdc++.h>
using namespace std;
namespace io {
const int __SIZE = (1 << 21) + 1;
char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1,
                                           __c, qu[55];
int __f, qr, _eof;
inline void flush() { fwrite(obuf, 1, oS - obuf, stdout), oS = obuf; }
inline void gc(char &x) {
  x = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                   (iS == iT ? EOF : *iS++))
                : *iS++);
}
inline void pc(char x) {
  *oS++ = x;
  if (oS == oT) flush();
}
inline void pstr(const char *s) {
  int __len = strlen(s);
  for (__f = 0; __f < __len; ++__f) pc(s[__f]);
}
inline void gstr(char *s) {
  for (__c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                         (iS == iT ? EOF : *iS++))
                       : *iS++);
       __c < 32 || __c > 126 || __c == ' ';)
    __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                    : *iS++);
  for (; __c > 31 && __c < 127 && __c != ' ';
       ++s, __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                              (iS == iT ? EOF : *iS++))
                            : *iS++))
    *s = __c;
  *s = 0;
}
template <class I>
inline bool gi(I &x) {
  _eof = 0;
  for (__f = 1,
      __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                        (iS == iT ? EOF : *iS++))
                      : *iS++);
       (__c < '0' || __c > '9') && !_eof;
       __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                         (iS == iT ? EOF : *iS++))
                       : *iS++)) {
    if (__c == '-') __f = -1;
    _eof |= __c == EOF;
  }
  for (x = 0; __c <= '9' && __c >= '0' && !_eof;
       __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                         (iS == iT ? EOF : *iS++))
                       : *iS++))
    x = x * 10 + (__c & 15), _eof |= __c == EOF;
  x *= __f;
  return !_eof;
}
template <class I>
inline void print(I x) {
  if (!x) pc('0');
  if (x < 0) pc('-'), x = -x;
  while (x) qu[++qr] = x % 10 + '0', x /= 10;
  while (qr) pc(qu[qr--]);
}
struct Flusher_ {
  ~Flusher_() { flush(); }
} io_flusher_;
}  // namespace io
using io::gc;
using io::gi;
using io::gstr;
using io::pc;
using io::print;
using io::pstr;
using ll = long long;
using pii = pair<int, int>;
const int MOD = 1000000007;
pii dat[500005 << 2];
bool laz[500005 << 2];
void push(int idx, int l, int r) {
  if (!laz[idx] || l == r) return;
  dat[idx * 2] = {dat[idx * 2].second, dat[idx * 2].first};
  laz[idx * 2] = !laz[idx * 2];
  dat[idx * 2 + 1] = {dat[idx * 2 + 1].second, dat[idx * 2 + 1].first};
  laz[idx * 2 + 1] = !laz[idx * 2 + 1];
  laz[idx] = 0;
}
void upd(int idx, int l, int r, int i, pii v) {
  if (!(l <= i && i <= r)) return;
  push(idx, l, r);
  if (l == r) {
    dat[idx] = v;
    return;
  }
  upd(idx * 2, l, (l + r) / 2, i, v);
  upd(idx * 2 + 1, (l + r) / 2 + 1, r, i, v);
  dat[idx] = {max(dat[idx * 2].first, dat[idx * 2 + 1].first),
              max(dat[idx * 2].second, dat[idx * 2 + 1].second)};
}
void tag(int idx, int l, int r, int ql, int qr) {
  if (qr < l || r < ql) return;
  push(idx, l, r);
  if (ql <= l && r <= qr) {
    dat[idx] = {dat[idx].second, dat[idx].first};
    laz[idx] = !laz[idx];
    return;
  }
  tag(idx * 2, l, (l + r) / 2, ql, qr);
  tag(idx * 2 + 1, (l + r) / 2 + 1, r, ql, qr);
  dat[idx] = {max(dat[idx * 2].first, dat[idx * 2 + 1].first),
              max(dat[idx * 2].second, dat[idx * 2 + 1].second)};
}
pii el2[500005];
vector<pii> elist[500005];
pii dfsfar(int u, int f) {
  pii ans = {0, u};
  for (pii &v : elist[u])
    if (v.first != f) ans = max(ans, dfsfar(v.first, u));
  return {ans.first + 1, ans.second};
}
int clck = 1;
int n;
int L[500005], R[500005];
int qr[500005], ans[500005];
void dfs(int u, int f, int dep, int cnt) {
  L[u] = clck++;
  if (cnt % 2 == 0)
    upd(1, 1, n, L[u], {dep, 0});
  else
    upd(1, 1, n, L[u], {0, dep});
  for (pii &v : elist[u])
    if (v.first != f) dfs(v.first, u, dep + 1, cnt + v.second);
  R[u] = clck - 1;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  gi(n);
  for (int i = (0); i < (n - 1); i++) {
    int u, v, w;
    gi(u), gi(v), gi(w);
    el2[i] = {u, v};
    elist[u].push_back({v, w});
    elist[v].push_back({u, w});
  }
  int root = dfsfar(1, -1).second;
  dfs(root, -1, 0, 0);
  int q;
  gi(q);
  for (int i = (0); i < (q); i++) gi(qr[i]);
  for (int i = (0); i < (q); i++) {
    int par = el2[qr[i] - 1].first, ch = el2[qr[i] - 1].second;
    if (R[par] - L[par] < R[ch] - L[ch]) swap(par, ch);
    tag(1, 1, n, L[ch], R[ch]);
    ans[i] = max(ans[i], dat[1].first);
  }
  root = dfsfar(root, -1).second;
  memset(dat, 0, sizeof dat);
  memset(laz, 0, sizeof laz);
  clck = 1;
  dfs(root, -1, 0, 0);
  for (int i = (0); i < (q); i++) {
    int par = el2[qr[i] - 1].first, ch = el2[qr[i] - 1].second;
    if (R[par] - L[par] < R[ch] - L[ch]) swap(par, ch);
    tag(1, 1, n, L[ch], R[ch]);
    ans[i] = max(ans[i], dat[1].first);
    print(ans[i]), pc('\n');
  }
}
