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>
#pragma optimize("SEX_ON_THE_BEACH")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
using ll = long long int;
using ull = unsigned long long int;
using dd = double;
using ldd = long double;
namespace someUsefull {
template <typename T1, typename T2>
inline void checkMin(T1& a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void checkMax(T1& a, T2 b) {
  if (a < b) a = b;
}
const int _bitfunctions_size_ = 16;
const int _bitfunctions_mask_ = (1 << _bitfunctions_size_) - 1;
char* _bits_count_;
inline void _build_bits_count_() {
  _bits_count_ = new char[1 << _bitfunctions_size_];
  for (int i = 1; i < (1 << _bitfunctions_size_); ++i) {
    _bits_count_[i] = _bits_count_[i >> 1];
    if (i & 1) ++_bits_count_[i];
  }
}
template <typename T1 = char, typename T2 = int>
inline T1 popcnt(T2 x) {
  T1 ans = 0;
  while (x) {
    ans += _bits_count_[x & _bitfunctions_mask_];
    x >>= _bitfunctions_size_;
  }
  return ans;
}
}  // namespace someUsefull
namespace operators {
template <typename T1, typename T2>
std::istream& operator>>(std::istream& in, std::pair<T1, T2>& x) {
  in >> x.first >> x.second;
  return in;
}
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& out, std::pair<T1, T2> x) {
  out << x.first << " " << x.second;
  return out;
}
template <typename T1>
std::istream& operator>>(std::istream& in, std::vector<T1>& x) {
  for (auto& i : x) in >> i;
  return in;
}
template <typename T1>
std::ostream& operator<<(std::ostream& out, std::vector<T1>& x) {
  for (auto& i : x) out << i << " ";
  return out;
}
}  // namespace operators
using namespace std;
using namespace operators;
using namespace someUsefull;
vector<vector<int>> gr;
vector<pair<int, int>> ed;
vector<int> d;
void dfs(int v, int _d = 0, int p = -1) {
  d[v] = _d;
  for (int to : gr[v]) {
    if (to != p) dfs(to, _d + 1, v);
  }
}
struct Tree {
  const int _size = 1 << 19;
  int n, t;
  vector<pair<int, int>> tree;
  vector<int> upd;
  vector<int> d;
  vector<int> pre;
  vector<int> tin, tout, tos;
  void dfs(int v, int _d = 0, int p = -1) {
    d[v] = _d;
    pre[v] = p;
    tin[v] = tos.size();
    tos.push_back(v);
    for (int to : gr[v]) {
      if (to != p) dfs(to, _d + 1, v);
    }
    tout[v] = tos.size();
  }
  pair<int, int> merge(pair<int, int> a, pair<int, int> b) {
    return {max(a.first, b.first), max(a.second, b.second)};
  }
  Tree(int v) {
    tree.resize(_size << 1, {0, 0});
    upd.resize(_size << 1, 0);
    n = gr.size();
    t = 0;
    d.resize(n);
    tin.resize(n);
    tout.resize(n);
    pre.resize(n);
    0;
    ;
    dfs(v);
    0;
    ;
    for (int i = 0; i < n; ++i) tree[_size + i].first = d[tos[i]];
    for (int i = _size - 1; i > 0; --i)
      tree[i] = merge(tree[i << 1], tree[i << 1 | 1]);
  }
  void change(int v) {
    upd[v] ^= 1;
    swap(tree[v].first, tree[v].second);
  }
  void push(int v) {
    if (!upd[v]) return;
    change(v << 1);
    change(v << 1 | 1);
    upd[v] = 0;
  }
  void update(int v, int l, int r, int fl, int fr) {
    if (r <= l || r <= fl || fr <= l) return;
    if (fl <= l && r <= fr) {
      change(v);
      return;
    }
    push(v);
    update(v << 1, l, (r + l) >> 1, fl, fr);
    update(v << 1 | 1, (r + l) >> 1, r, fl, fr);
    tree[v] = merge(tree[v << 1], tree[v << 1 | 1]);
  }
  int add(int a, int b) {
    if (pre[a] != b) swap(a, b);
    update(1, 0, _size, tin[a], tout[a]);
    return tree[1].first;
  }
};
void solve(int test) {
  int n;
  cin >> n;
  gr.resize(n);
  vector<int> type(n - 1);
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b >> type[i];
    --a;
    --b;
    ed.push_back({a, b});
    gr[a].push_back(b);
    gr[b].push_back(a);
  }
  d.resize(n);
  d.assign(n, -1);
  dfs(0);
  int v = 0;
  for (int i = 0; i < n; ++i)
    if (d[v] < d[i]) v = i;
  dfs(v);
  int L = v;
  int R = 0;
  for (int i = 0; i < n; ++i)
    if (d[R] < d[i]) R = i;
  0;
  ;
  0;
  ;
  Tree LT(L), RT(R);
  0;
  ;
  for (int i = 0; i < n - 1; ++i) {
    if (type[i])
      LT.add(ed[i].first, ed[i].second), RT.add(ed[i].first, ed[i].second);
  }
  int m;
  cin >> m;
  for (int i = 0; i < m; ++i) {
    int x;
    cin >> x;
    --x;
    int ans = 0;
    checkMax(ans, LT.add(ed[x].first, ed[x].second));
    checkMax(ans, RT.add(ed[x].first, ed[x].second));
    cout << ans << '\n';
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  _build_bits_count_();
  cout << setprecision(12) << fixed;
  int t = 1;
  for (int i = 0; i < t; ++i) {
    0;
    ;
    solve(i + 1);
  }
  return 0;
}