#include <bits/stdc++.h>
using namespace std;
template <typename TH>
void _dbg(const char* sdbg, TH h) {
  cerr << sdbg << "=" << h << "\n";
}
template <typename TH, typename... TA>
void _dbg(const char* sdbg, TH h, TA... t) {
  while (*sdbg != ',') {
    cerr << *sdbg++;
  }
  cerr << "=" << h << ",";
  _dbg(sdbg + 1, t...);
}
template <class C>
void mini(C& a4, C b4) {
  a4 = min(a4, b4);
}
template <class C>
void maxi(C& a4, C b4) {
  a4 = max(a4, b4);
}
template <class T1, class T2>
ostream& operator<<(ostream& out, pair<T1, T2> pair) {
  return out << "(" << pair.first << ", " << pair.second << ")";
}
template <class A, class B, class C>
struct Triple {
  A first;
  B second;
  C third;
  bool operator<(const Triple& t) const {
    if (first != t.first) return first < t.first;
    if (second != t.second) return second < t.second;
    return third < t.third;
  }
};
template <class T>
void ResizeVec(T&, vector<long long>) {}
template <class T>
void ResizeVec(vector<T>& vec, vector<long long> sz) {
  vec.resize(sz[0]);
  sz.erase(sz.begin());
  if (sz.empty()) {
    return;
  }
  for (T& v : vec) {
    ResizeVec(v, sz);
  }
}
template <class A, class B, class C>
ostream& operator<<(ostream& out, Triple<A, B, C> t) {
  return out << "(" << t.first << ", " << t.second << ", " << t.third << ")";
}
template <class T>
ostream& operator<<(ostream& out, vector<T> vec) {
  out << "(";
  for (auto& v : vec) out << v << ", ";
  return out << ")";
}
template <class T>
ostream& operator<<(ostream& out, set<T> vec) {
  out << "(";
  for (auto& v : vec) out << v << ", ";
  return out << ")";
}
template <class L, class R>
ostream& operator<<(ostream& out, map<L, R> vec) {
  out << "(";
  for (auto& v : vec) out << v << ", ";
  return out << ")";
}
struct Edge {
  long long to, id;
};
const long long N = 1e6 + 5;
vector<Edge> slo[N];
long long ktory;
long long vis[N];
long long pre[N][3];
long long sz[N][3];
long long dep[N][3];
const long long M = 1 << 20;
long long d;
void Dfs(long long v, long long id) {
  vis[v] = id;
  sz[v][id] = 1;
  d++;
  pre[v][id] = d;
  for (auto e : slo[v]) {
    long long nei = e.to;
    if (vis[nei] == id) {
      continue;
    }
    dep[nei][id] = 1 + dep[v][id];
    Dfs(nei, id);
    sz[v][id] += sz[nei][id];
  }
}
struct Node {
  long long ma0, ma1, to_push;
  Node() {
    ma0 = -N, ma1 = -N;
    to_push = 0;
  }
};
struct Drz {
  vector<Node> drz;
  Drz() { drz.resize(2 * M + 5); }
  Node& operator[](long long a) { return drz[a]; }
  void Touch(long long v) {
    if (drz[v].to_push) {
      for (long long son = (2 * v); son <= (2 * v + 1); ++son) {
        drz[son].to_push ^= 1;
        swap(drz[son].ma0, drz[son].ma1);
      }
    }
    drz[v].to_push = 0;
  }
  void Flip(long long bl, long long br, long long l, long long r, long long v) {
    if (l > br || r < bl) {
      return;
    }
    if (l <= bl && br <= r) {
      drz[v].to_push ^= 1;
      swap(drz[v].ma0, drz[v].ma1);
      return;
    }
    Touch(v);
    long long m = (bl + br) / 2;
    Flip(bl, m, l, r, 2 * v);
    Flip(m + 1, br, l, r, 2 * v + 1);
    drz[v].ma0 = max(drz[2 * v].ma0, drz[2 * v + 1].ma0);
    drz[v].ma1 = max(drz[2 * v].ma1, drz[2 * v + 1].ma1);
  }
};
Drz drz[3];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  if (0) cout << fixed << setprecision(10);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<pair<long long, long long> > to_change;
  vector<pair<long long, long long> > es;
  for (long long i = (1); i <= (n - 1); ++i) {
    long long a, b, c;
    cin >> a >> b >> c;
    es.push_back({a, b});
    slo[a].push_back({b, i});
    slo[b].push_back({a, i});
    if (c) {
      to_change.push_back({a, b});
    }
  }
  for (long long i = (1); i <= (n); ++i) {
    vis[i] = -1;
  }
  d = 0;
  Dfs(1, 0);
  long long sr1 = 1;
  for (long long i = (1); i <= (n); ++i) {
    if (dep[i][0] > dep[sr1][0]) {
      sr1 = i;
    }
  }
  d = 0;
  Dfs(sr1, 1);
  long long sr2 = 1;
  for (long long i = (1); i <= (n); ++i) {
    if (dep[i][1] > dep[sr2][1]) {
      sr2 = i;
    }
  }
  d = 0;
  Dfs(sr2, 2);
  (sr1, sr2);
  for (long long wh = (1); wh <= (2); ++wh) {
    for (long long v = (1); v <= (n); ++v) {
      drz[wh][M - 1 + pre[v][wh]].ma0 = dep[v][wh];
    }
    for (long long i = (M - 1); i >= (1); --i) {
      drz[wh][i].ma0 = max(drz[wh][2 * i].ma0, drz[wh][2 * i + 1].ma0);
    }
  }
  function<void(long long, long long)> Change = [&](long long a, long long b) {
    for (long long wh = (1); wh <= (2); ++wh) {
      if (dep[b][wh] > dep[a][wh]) {
        swap(a, b);
      }
      drz[wh].Flip(1, M, pre[a][wh], pre[a][wh] + sz[a][wh] - 1, 1);
    }
  };
  for (auto ch : to_change) {
    Change(ch.first, ch.second);
  }
  long long m;
  cin >> m;
  for (long long i = (1); i <= (m); ++i) {
    long long id;
    cin >> id;
    long long a = es[id - 1].first;
    long long b = es[id - 1].second;
    Change(a, b);
    (a, b);
    (drz[1][1].ma0, drz[2][1].ma0);
    cout << max(drz[1][1].ma0, drz[2][1].ma0) << "\n";
  }
  return 0;
}
