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;
int n, q;
vector<vector<pair<int, int> > > graph;
vector<pair<int, int> > edges;
class SegmentTree {
  struct node_t {
    int best[2];
    int lazy;
    node_t() {
      best[0] = 0;
      best[1] = 0;
      lazy = 0;
    }
    node_t operator+(const node_t &other) const {
      node_t ans;
      for (int i = 0; i < 2; i++) {
        ans.best[i] = max(this->best[i], other.best[i]);
      }
      ans.lazy = 0;
      return ans;
    }
    void propag(int lazy) {
      if (lazy) {
        swap(best[0], best[1]);
        this->lazy ^= lazy;
      }
    }
  };
  int n;
  vector<node_t> aint;
  void propag(int nod, int st, int dr) {
    if (st == dr || aint[nod].lazy == 0) {
      return;
    }
    aint[nod * 2].propag(aint[nod].lazy);
    aint[nod * 2 + 1].propag(aint[nod].lazy);
    aint[nod].lazy = 0;
  }
  void build(int nod, int st, int dr, const vector<int> &lvl,
             const vector<int> &tp) {
    if (st == dr) {
      aint[nod].best[tp[st]] = lvl[st];
      aint[nod].best[tp[st] ^ 1] = 0;
      return;
    }
    int mid = (st + dr) / 2;
    build(nod * 2, st, mid, lvl, tp);
    build(nod * 2 + 1, mid + 1, dr, lvl, tp);
    aint[nod] = aint[nod * 2] + aint[nod * 2 + 1];
  }
  void flip(int nod, int st, int dr, int l, int r) {
    propag(nod, st, dr);
    if (dr < l || st > r) {
      return;
    }
    if (l <= st && dr <= r) {
      aint[nod].propag(1);
      return;
    }
    int mid = (st + dr) / 2;
    flip(nod * 2, st, mid, l, r);
    flip(nod * 2 + 1, mid + 1, dr, l, r);
    aint[nod] = aint[nod * 2] + aint[nod * 2 + 1];
  }

 public:
  SegmentTree(int n, const vector<int> &lvl, const vector<int> &tp) {
    this->n = n;
    aint = vector<node_t>(4 * n + 5, node_t());
    build(1, 1, n, lvl, tp);
  }
  SegmentTree() { ; }
  void flip(int l, int r) { flip(1, 1, n, l, r); }
  int query() { return aint[1].best[0]; }
};
class TreeWrapper {
  SegmentTree aint;
  vector<int> lvl;
  vector<int> tp;
  vector<int> l;
  vector<int> r;
  int lst = 0;
  void dfs(int nod, pair<int, int> tata,
           const vector<vector<pair<int, int> > > &graph) {
    l[nod] = ++lst;
    lvl[l[nod]] = 1 + lvl[l[tata.first]];
    tp[l[nod]] = tp[l[tata.first]] ^ tata.second;
    for (auto it : graph[nod]) {
      if (it.first == tata.first) {
        continue;
      }
      dfs(it.first, {nod, it.second}, graph);
    }
    r[nod] = lst;
  }

 public:
  TreeWrapper(int root, const vector<vector<pair<int, int> > > &graph) {
    lst = 0;
    l = vector<int>(graph.size(), 0);
    r = vector<int>(graph.size(), 0);
    lvl = vector<int>(graph.size(), 0);
    tp = vector<int>(graph.size(), 0);
    dfs(root, {0, 0}, graph);
    aint = SegmentTree((int)graph.size() - 1, lvl, tp);
  }
  void flip(pair<int, int> a) {
    if (lvl[l[a.first]] > lvl[l[a.second]]) {
      swap(a.first, a.second);
    }
    aint.flip(l[a.second], r[a.second]);
  }
  int query() { return aint.query(); }
};
pair<int, int> dfs(int nod, int tata) {
  pair<int, int> ans = {0, nod};
  for (auto it : graph[nod]) {
    if (it.first == tata) {
      continue;
    }
    pair<int, int> tmp = dfs(it.first, nod);
    tmp.first++;
    ans = max(ans, tmp);
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  graph = vector<vector<pair<int, int> > >(n + 1, vector<pair<int, int> >());
  edges = vector<pair<int, int> >(n, {0, 0});
  for (int i = 1; i < n; i++) {
    int x, y, t;
    scanf("%d %d %d", &x, &y, &t);
    graph[x].push_back({y, t});
    graph[y].push_back({x, t});
    edges[i] = {x, y};
  }
  int a = dfs(1, 0).second;
  int b = dfs(a, 0).second;
  TreeWrapper fst(a, graph), snd(b, graph);
  scanf("%d", &q);
  while (q--) {
    int id;
    scanf("%d", &id);
    fst.flip(edges[id]);
    snd.flip(edges[id]);
    printf("%d\n", max(fst.query(), snd.query()) - 1);
  }
  return 0;
}