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>
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');
  }
}