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.
10
5 7 0
2 10 1
1 5 0
6 8 0
4 9 1
2 5 1
10 8 0
2 3 1
4 2 1
10
9
9
9
5
2
5
7
2
3
2
 5
2 4 0
5 2 0
1 3 1
1 2 1
5
3
3
4
1
1
 20
9 11 0
1 5 0
1 14 0
5 17 0
14 3 0
16 6 0
9 2 0
6 4 0
11 10 0
12 7 0
8 18 0
13 1 0
18 11 0
8 6 0
5 10 0
5 15 0
2 20 0
19 17 0
7 17 0
20
9
11
11
14
14
5
5
10
10
4
4
18
17
18
17
17
8
8
15
17
 2
2 1 1
10
1
1
1
1
1
1
1
1
1
1

5
5
5
5
5
4
5
4
5
5
 2
3
2
3
2
 7
9
7
9
7
9
7
9
7
9
7
8
8
8
7
8
9
8
9
9
 1
0
1
0
1
0
1
0
1
0


#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename U> using ordered_map = tree<T, U, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<str> vstr;

#define FOR(i,j,k,in) for(int i=(j); i < (k);i+=in)
#define FORD(i,j,k,in) for(int i=(j); i >=(k);i-=in)
#define REP(i,b) FOR(i,0,b,1)
#define REPD(i,b) FORD(i,b,0,1)
#define pb push_back 
#define mp make_pair
#define ff first
#define ss second
#define all(x) begin(x), end(x)
#define rsz resize 
#define MANY_TESTS int tcase; cin >> tcase; while(tcase--)
	
const double EPS = 1e-9;
const int MOD = 1e9+7; // 998244353;
const ll INFF = 1e18;
const int INF = 1e9;
const ld PI = acos((ld)-1);
const vi dy = {1, 0, -1, 0, -1, 1, 1, -1};
const vi dx = {0, 1, 0, -1, -1, 1, -1, 1};

#ifdef DEBUG
#define DBG if(1)
#else
#define DBG if(0)
#endif

#define dbg(x) cout << "(" << #x << " : " << x << ")" << endl;
// ostreams
template <class T, class U>
ostream& operator<<(ostream& out, const pair<T, U> &par) {out << "[" << par.first << ";" << par.second << "]"; return out;}
template <class T>
ostream& operator<<(ostream& out, const set<T> &cont) { out << "{"; for( const auto &x:cont) out << x << ", "; out << "}"; return out; }
template <class T, class U>
ostream& operator<<(ostream& out, const map<T, U> &cont) {out << "{"; for( const auto &x:cont) out << x << ", "; out << "}"; return out; }
template<class T>
ostream& operator<<(ostream& out, const vector<T> &v){ out << "[";  REP(i, v.size()) out << v[i] << ", ";  out << "]"; return out;}
// istreams
template<class T>
istream& operator>>(istream& in, vector<T> &v){ for(auto &x : v) in >> x; return in; }
template<class T, class U>
istream& operator>>(istream& in, pair<T, U> &p){ in >> p.ff >> p.ss; return in; }
//searches
template<typename T, typename U>
T bsl(T lo, T hi, U f){ hi++; T mid; while(lo < hi){ mid = (lo + hi)/2; f(mid) ? hi = mid : lo = mid+1; } return lo; }
template<typename U>
double bsld(double lo, double hi, U f, double p = 1e-9){ int r = 3 + (int)log2((hi - lo)/p); double mid; while(r--){ mid = (lo + hi)/2; f(mid) ? hi = mid : lo = mid; } return (lo + hi)/2; }
template<typename T, typename U>
T bsh(T lo, T hi, U f){ lo--; T mid; while(lo < hi){ mid = (lo + hi + 1)/2; f(mid) ? lo = mid : hi = mid-1; } return lo; }
template<typename U>
double bshd(double lo, double hi, U f, double p = 1e-9){ int r = 3+(int)log2((hi - lo)/p); double mid; while(r--){ mid = (lo + hi)/2; f(mid) ? lo = mid : hi = mid; } return (lo + hi)/2; }
// some more utility functions
template<typename T>
pair<T, int> get_min(vector<T> &v){ typename vector<T> :: iterator it = min_element(v.begin(), v.end()); return mp(*it, it - v.begin());}
template<typename T>
pair<T, int> get_max(vector<T> &v){ typename vector<T> :: iterator it = max_element(v.begin(), v.end()); return mp(*it, it - v.begin());}        
template<typename T> bool ckmin(T& a, const T& b){return b < a ? a = b , true : false;}
template<typename T> bool ckmax(T& a, const T& b){return b > a ? a = b, true : false;}


struct node{
    ll odd = 0; ll ev = 0;
    bool odd_is = false; bool ev_is = true;
    bool flag = false;
    void apply(int l, int r){
        swap(odd, ev); swap(odd_is, ev_is);
        flag = true;
    }
};
struct segtree{
    node comb(node const &a, node const &b){
        node res;
        if(a.odd_is && b.odd_is){
            res.odd_is = true; res.odd = max(a.odd, b.odd);
        }
        else if(a.odd_is){
            res.odd_is = true;
            res.odd = a.odd;
        }
        else if(b.odd_is){
            res.odd_is = true;
            res.odd = a.odd;
        }
        else{
            res.odd_is = false;
            res.odd = 0;
        }
        if(a.ev_is && b.ev_is){
            res.ev_is = true; res.ev = max(a.ev, b.ev);
        }
        else if(a.ev_is){
            res.ev_is = true; res.ev = a.ev;
        }
        else if(b.ev_is){
            res.ev_is = true; res.ev = b.ev;
        }
        else{
            res.ev_is = false;
            res.ev= 0;
        }
        res.flag = false;
        return res;
    } 
    void push(int l, int r, int v){
        if(!tree[v].flag) return;
        tree[v<<1].flag = true;
        tree[v<<1|1].flag = true;
        swap(tree[v<<1].odd, tree[v<<1].ev); swap(tree[v<<1].odd_is, tree[v<<1].ev_is);
        swap(tree[v<<1|1].odd, tree[v<<1|1].ev); swap(tree[v<<1|1].odd_is, tree[v<<1|1].ev_is);
        tree[v].flag = false;
    }
    int sz;
    vector<node> tree; 
    segtree(int _sz){ // tree is resized to default values set in node
        sz = 1; while(sz < _sz) sz<<=1;
        tree.resize(2*sz); 
    } 
    void build(vector<node> &init){
        for(int i = 0; i < sz; ++i) 
            if(i < init.size())
                tree[i+sz] = init[i];
        for(int i = sz-1; i > 0; --i)
            tree[i] = comb(tree[i<<1], tree[i<<1|1]);
    } 
    node query(int l, int r){return query0(l, r, 0, sz, 1);} 
    node query0(int l, int r, int beg, int end, int v){ 
        if(beg >= l && end <= r)
            return tree[v];
        push(beg, end, v);
        int mid = (beg + end) >> 1;
        node res;
        if(beg >= r || mid <= l) res = query0(l, r, mid, end, v<<1|1); //[beg, mid]
        else if(mid >= r || end <= l) res = query0(l, r, beg, mid, v<<1);
        else res = comb(query0(l, r, beg, mid, v<<1), query0(l, r, mid, end, v<<1|1));
        return res;
    } 
    template<typename... T>
    void upd(int l, int r, T ...args){upd0(l, r, 0, sz, 1, args...);}
    template<typename... T>
    void upd0(int l, int r, int beg, int end, int v, T ...args){
        if(beg >= r || end <= l)
            return;
        if(beg >= l && end <= r){
            tree[v].apply(beg, end, args...);
            return;
        }
        push(beg, end, v);
        int mid = (beg + end) >> 1;
        upd0(l, r, beg, mid, v<<1, args...);
        upd0(l, r, mid, end, v<<1|1, args...);
        tree[v] = comb(tree[v<<1], tree[v<<1|1]);
    } 
};

template<typename T>
struct edge{
    int src;
    int dest;
    T cost;
};
template<typename T>
class graph{
    public: 
    vector<edge<T>> edges;
    vector<vector<int>> adj;
    int n;
    graph(){};
    graph(int _n){
        n = _n;
        adj.resize(n);
    }
};

template<typename T>
class undigraph : public graph<T>{
    public:
        using graph<T>::edges;
        using graph<T>::adj;
        using graph<T>::n;
        undigraph() : graph<T>(){};
        undigraph(int _n) : graph<T>(_n){};

        int add_edge(int src, int dest, T cost = 1){
            int id = edges.size();
            edges.push_back({src, dest, cost});
            adj[src].push_back(id);
            adj[dest].push_back(id);
            return id;
        }
};
int main(){
 	ios_base::sync_with_stdio(false);
 	cin.tie(NULL); cout.tie(NULL);
	int n; cin >> n;
    undigraph<int> g(n);
    vector<int> e_id;
    REP(i, n-1){
        int a, b, t;
        cin >> a >> b >> t;
        if(t) e_id.pb(i);
        a--; b--; 
        g.add_edge(a, b, 0);
    }
    int max_dist = -1;
    int di = -1;
    function<void(int, int, int)> diam = [&](int v, int p, int d){
        if(d > max_dist){
            max_dist = d;
            di = v;
        }
        for(int id : g.adj[v]){
            auto e = g.edges[id];
            int other = e.src ^ e.dest ^ v;
            if(other == p) continue;
            diam(other, v, d+1);
        }
    };
    diam(0, -1, 0);
    int fd = di;
    max_dist = -1; di = -1;
    diam(fd, 0, 0);
    int sd = di;
    vi dist(n), in(n), out(n), trav;
    int t = -1;
    function<void(int, int, int)> dfs = [&](int v,int p, int d){
        ++t;
        in[v] = t;
        dist[v] = d;
        trav.pb(v);
        for(int id : g.adj[v]){
            auto e = g.edges[id];
            int other = e.src ^ e.dest ^ v;
            if(other == p) continue;
            dfs(other, v, d+1);
        }
        out[v] = t;
    };
    dfs(sd, -1, 0);
    vi dist2 = dist;
    vi in2 = in;
    vi out2 = out;
    vi trav2 = trav;
    trav.clear();
    t = -1;
    dfs(fd, -1, 0);
    vector<node> init1(n);
    vector<node> init2(n);
    REP(i, n){
        node frs; frs.ev = dist[trav[i]];   
        node sec; sec.ev = dist2[trav2[i]]; 
        init1[i] = frs;
        init2[i] = sec; 
    } 
    segtree st1(n); st1.build(init1);
    segtree st2(n); st2.build(init2);
    /* auto printout = [&](segtree &st){ */
    /*     REP(i, n){ */
    /*         auto no = st.query(i, i+1); */
    /*         cout << no.ev << " "; */
    /*     } */
    /*     cout << endl; */
    /* }; */
    for(auto i : e_id){
        auto e = g.edges[i];
        if(dist[e.src] < dist[e.dest]) swap(e.src, e.dest);
        st1.upd(in[e.src], out[e.src]+1);
        if(dist2[e.src] < dist2[e.dest]) swap(e.src, e.dest);
        st2.upd(in2[e.src], out2[e.src]+1);
    } 
    int m; cin >> m;
    while(m--){
        int i; cin >> i;
        i--;
        auto e = g.edges[i];
        if(dist[e.src] < dist[e.dest]) swap(e.src, e.dest);
        st1.upd(in[e.src], out[e.src]+1);
        if(dist2[e.src] < dist2[e.dest]) swap(e.src, e.dest);
        st2.upd(in2[e.src], out2[e.src]+1); 
        auto no1 = st1.query(0, n);
        auto no2 = st2.query(0, n);
        /* dbg(mp(no1.ev, no2.ev)) */
        /* dbg(mp(no1.odd, no2.odd)) */
        cout << max(no1.ev, no2.ev) << "\n";
    }
	
    return 0;
}
