Problem: In the Land of Fire there are n villages and n-1 bidirectional road, and there is a path between any pair of villages by roads. There are only two types of roads: stone ones and sand ones. Since the Land of Fire is constantly renovating, every morning workers choose a single road and flip its type (so it becomes a stone road if it was a sand road and vice versa). Also everyone here loves ramen, that's why every morning a ramen pavilion is set in the middle of every stone road, and at the end of each day all the pavilions are removed.

For each of the following m days, after another road is flipped, Naruto and Jiraiya choose a simple path — that is, a route which starts in a village and ends in a (possibly, the same) village, and doesn't contain any road twice. Since Naruto and Jiraiya also love ramen very much, they buy a single cup of ramen on each stone road and one of them eats it. Since they don't want to offend each other, they only choose routes where they can eat equal number of ramen cups. Since they both like traveling, they choose any longest possible path. After every renovation find the maximal possible length of a path (that is, the number of roads in it) they can follow.

Input

The first line contains the only positive integer n (2 ≤ n ≤ 500 000) standing for the number of villages in the Land of Fire.

Each of the following (n-1) lines contains a description of another road, represented as three positive integers u, v and t (1 ≤ u, v ≤ n, t ∈ \{0,1\}). The first two numbers denote the villages connected by the road, and the third denotes the initial type of the road: 0 for the sand one and 1 for the stone one. Roads are numbered from 1 to (n-1) in the order from the input.

The following line contains a positive integer m (1 ≤ m ≤ 500 000) standing for the number of days Naruto and Jiraiya travel for.

Each of the following m lines contains the single integer id (1 ≤ id ≤ n-1) standing for the index of the road whose type is flipped on the morning of corresponding day.

It is guaranteed that there is a road path between any pair of villages.

Output

Output m lines. In the i-th of them print the only integer denoting the maximal possible length of any valid path on the i-th day.

Example

Input


5
1 2 0
1 3 0
3 5 0
3 4 0
5
3
4
1
3
4


Output


3
2
3
3
2

Note

After the renovation of the 3-rd road the longest path consists of the roads 1, 2 and 4.

After the renovation of the 4-th road one of the longest paths consists of the roads 1 and 2.

After the renovation of the 1-st road one of the longest paths consists of the roads 1, 2 and 3.

After the renovation of the 3-rd road the longest path consists of the roads 1, 2 and 4.

After the renovation of the 4-rd road one of the longest paths consists of the roads 2 and 4.

Solution (in CPP):

Solution:
#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;
}