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

#pragma GCC optimize ("O3", "unroll-loops")
//#pragma GCC target ("avx2")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define distinct(x) sort(all(x)); x.resize(unique(all(x))-x.begin())
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define CASE(x) int x; cin >> x; while (x--)
#define CASEt(x) int x; cin >> x; for (int tc = 1; tc <= x; ++tc)
using namespace std;
using namespace __gnu_pbds;
namespace {
	const int MOD107 = 1000000007;
	const int MOD998 = 998244353;
	using ll = long long;
	using ull = unsigned long long;
	using pii = pair<int, int>;
	using pll = pair<ll, ll>;
	template <class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
	template <class T> using minheap = priority_queue<T, vector<T>, greater<T>>;
	template <class T> using maxheap = priority_queue<T, vector<T>, less<T>>;
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//	mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
	struct Modular {
	private:
		long long MODVALUE = 0;
		long long val = 0;

		Modular initModular(long long val) const { return Modular(val, MODVALUE); }

	#ifdef LOCAL
		inline void validate() const {
			assert(MODVALUE != 0);
		}

		inline void validate(const Modular& other) const {
			assert(MODVALUE != 0);
			assert(MODVALUE == other.MODVALUE);
			other.validate();
		}
	#else
		inline void validate() const { }
		inline void validate(const Modular& other) const { }
	#endif

	public:
		explicit operator long long() const { return val; }

		template<class T> Modular& operator = (const T& other) { val = other; return *this; }
		template<class T> void setMod(const T& MOD) { MODVALUE = MOD; }

		bool operator == (const Modular& other) { validate(other); return val == other.val; }
		bool operator != (const Modular& other) { return !(*this == other); }
		template<class T> bool operator == (const T& other) { return *this == initModular(other); }
		template<class T> bool operator != (const T& other) { return *this != initModular(other); }
		template<class T> friend bool operator == (const T& other, const Modular& m) { return m.initModular(other) == m; }
		template<class T> friend bool operator != (const T& other, const Modular& m) { return m.initModular(other) != m; }

		bool operator <  (const Modular& other) { validate(other); return val <  other.val; }
		bool operator <= (const Modular& other) { validate(other); return val <= other.val; }
		bool operator >  (const Modular& other) { validate(other); return val >  other.val; }
		bool operator >= (const Modular& other) { validate(other); return val >= other.val; }
		template<class T> bool operator <  (const T& other) { return *this <  initModular(other); }
		template<class T> bool operator <= (const T& other) { return *this <= initModular(other); }
		template<class T> bool operator >  (const T& other) { return *this >  initModular(other); }
		template<class T> bool operator >= (const T& other) { return *this >= initModular(other); }
		template<class T> friend bool operator <  (const T& other, const Modular& m) { return m.initModular(other) <  m; }
		template<class T> friend bool operator <= (const T& other, const Modular& m) { return m.initModular(other) <= m; }
		template<class T> friend bool operator >  (const T& other, const Modular& m) { return m.initModular(other) >  m; }
		template<class T> friend bool operator >= (const T& other, const Modular& m) { return m.initModular(other) >= m; }

		Modular& operator += (const Modular& other) { validate(other); val += other.val; val %= MODVALUE; return *this; }
		Modular  operator +  (const Modular& other) { Modular tmp = *this; return tmp += other; }
		template<class T> Modular& operator += (const T& other) { return *this += initModular(other); }
		template<class T> Modular  operator +  (const T& other) { return *this +  initModular(other); }
//		template<class T> friend Modular operator += (const T& other, const Modular& m) { return m.initModular(other) += m; }
		template<class T> friend Modular operator +  (const T& other, const Modular& m) { return m.initModular(other) +  m; }

		Modular& operator ++()    { return *this += 1; }
		Modular  operator ++(int) { Modular tmp = *this; ++*this; return tmp; }

		Modular  operator -  () const { return initModular(-val); }
		Modular& operator -= (const Modular& other) { validate(other); val -= other.val; val += MODVALUE; val %= MODVALUE; return *this;}
		Modular  operator -  (const Modular& other) { Modular tmp = *this; return tmp -= other; }
		template<class T> Modular& operator -= (const T& other) { return *this -= initModular(other); }
		template<class T> Modular  operator -  (const T& other) { return *this -  initModular(other); }
//		template<class T> friend Modular operator -= (const T& other, const Modular& m) { return m.initModular(other) -= m; }
		template<class T> friend Modular operator -  (const T& other, const Modular& m) { return m.initModular(other) -  m; }

		Modular& operator --()    { return *this -= 1; }
		Modular  operator --(int) { Modular tmp = *this; --*this; return tmp; }

		Modular& operator *= (const Modular& other) { validate(other); val *= other.val; val %= MODVALUE; val += MODVALUE; val %= MODVALUE; return *this; }
		Modular  operator *  (const Modular& other) { Modular tmp = *this; return tmp *= other; }
		template<class T> Modular& operator *= (const T& other) { return *this *= initModular(other); }
		template<class T> Modular  operator *  (const T& other) { return *this *  initModular(other); }
//		template<class T> friend Modular operator *= (const T& other, const Modular& m) { return m.initModular(other) *= m; }
		template<class T> friend Modular operator *  (const T& other, const Modular& m) { return m.initModular(other) *  m; }

		Modular pow(long long power) const {
			Modular m = *this, ans = initModular(1);
			while (power) {
				if (power & 1) ans *= m;
				m *= m;
				power >>= 1;
			}
			return ans;
		}
		Modular pow(const Modular& other) const { return pow(other.val); }
		Modular inv() const { return pow(MODVALUE-2); }

		Modular& operator /= (const Modular& other) { val *= other.inv().val; val %= MODVALUE; return *this; }
		Modular  operator /  (const Modular& other) { Modular tmp = *this; return tmp /= other; }
		template<class T> Modular& operator /= (const T& other) { return *this /= initModular(other); }
		template<class T> Modular  operator /  (const T& other) { return *this /  initModular(other); }
//		template<class T> friend Modular operator /= (const T& other, const Modular& m) { return m.initModular(other) /= m; }
		template<class T> friend Modular operator /  (const T& other, const Modular& m) { return m.initModular(other) /  m; }

		friend istream& operator >> (istream& in, Modular& m) { in >> m.val; m.val %= m.MODVALUE; m.val += m.MODVALUE; m.val %= m.MODVALUE; return in; }
		friend ostream& operator << (ostream& out, const Modular& m) { return out << m.val; }

		Modular() { val = 0; MODVALUE = 0; }
		Modular(long long val, long long MOD) : MODVALUE(MOD), val((val % MOD + MOD) % MOD) { }
	};
	using Mint = Modular;
	inline ll pow(ll b, ll p, ll mod) {
		b %= mod;
		ll ans = 1;
		for (; p > 0; p >>= 1) {
			if (p&1) {ans *= b; ans %= mod;}
			b *= b;
			b %= mod;
		}
		return ans;
	}
	inline ll max(ll a, int b) { return (a > b ? a : b); }
	inline ll max(int a, ll b) { return (a > b ? a : b); }
	inline ll min(ll a, int b) { return (a < b ? a : b); }
	inline ll min(int a, ll b) { return (a < b ? a : b); }
	template <class T> inline bool chkmin(T&x, const T& y) { return x > y ? x = y, 1 : 0; }
	template <class T> inline bool chkmax(T&x, const T& y) { return x < y ? x = y, 1 : 0; }
}
namespace IO {
	template<class T> inline void _R(T &x) {cin >> x;}
	template<class T1, class T2> inline void _R(pair<T1,T2> &x) {_R(x.first); _R(x.second);}
	template<class T> inline void _R(vector<T> &x) {for (auto& i : x) _R(i);}
	template<class T> inline void _R(deque<T> &x) {for (auto& i : x) _R(i);}
	inline void R() {}
	template<class T1, class... T2> inline void R(T1 &x, T2 &...y) { _R(x); R(y...);}

	template<class T> inline void _W(const T& x);
	template<class T1, class T2> inline void _W(const pair<T1,T2>& p);
	template<class... T> inline void _W(const vector<T...>& x);
	template<class... T> inline void _W(const deque<T...>& x);
	template<class... T> inline void _W(const forward_list<T...>& x);
	template<class... T> inline void _W(const list<T...>& x);
	template<class... T> inline void _W(const set<T...>& x);
	template<class... T> inline void _W(const multiset<T...>& x);
	template<class... T> inline void _W(const unordered_set<T...>& x);
	template<class... T> inline void _W(const unordered_multiset<T...>& x);
	template<class... T> inline void _W(const map<T...>& x);
	template<class... T> inline void _W(const multimap<T...>& x);
	template<class... T> inline void _W(const unordered_map<T...>& x);
	template<class... T> inline void _W(const unordered_multimap<T...>& x);

	template<class T> inline void _W(const ordered_set<T>& x);

	template<class Container> inline void printContainer(const Container& x) { bool isFirst = 1; for (auto i : x) { if (!isFirst) cout << ' '; isFirst = 0; _W(i); } }

	template<class T> inline void _W(const T& x) {cout << x;}
	template<class T1, class T2> inline void _W(const pair<T1,T2>& p) {_W(p.first); _W(' '); _W(p.second);}
	template<class... T> inline void _W(const vector<T...>& x) { printContainer(x); }
	template<class... T> inline void _W(const deque<T...>& x) { printContainer(x); }
	template<class... T> inline void _W(const forward_list<T...>& x) { printContainer(x); }
	template<class... T> inline void _W(const list<T...>& x) { printContainer(x); }
	template<class... T> inline void _W(const set<T...>& x) { printContainer(x); }
	template<class... T> inline void _W(const multiset<T...>& x) { printContainer(x); }
	template<class... T> inline void _W(const unordered_set<T...>& x) { printContainer(x); }
	template<class... T> inline void _W(const unordered_multiset<T...>& x) { printContainer(x); }
	template<class... T> inline void _W(const map<T...>& x) { printContainer(x); }
	template<class... T> inline void _W(const multimap<T...>& x) { printContainer(x); }
	template<class... T> inline void _W(const unordered_map<T...>& x) { printContainer(x); }
	template<class... T> inline void _W(const unordered_multimap<T...>& x) { printContainer(x); }

	template<class T> inline void _W(const ordered_set<T>& x) { printContainer(x); }

 	inline void W() {cout << '\n';}
	template<class T> inline void W(const T &x) {_W(x); W();}
	template<class T1, class... T2> inline void W(const T1 &x, const T2 &...y) { _W(x); _W(' '); W(y...);}
} using namespace IO;
namespace outputFormat{
	inline string Case(int tc) {return "Case #" + to_string(tc) + ':';}
	inline string YN(bool b) {return b ? "Yes" : "No";}
} using namespace outputFormat;
namespace std {
    template <class T1, class T2> struct hash<pair<T1,T2>> {
    	std::size_t operator()(pair<T1,T2> _) const {
        	return hash<T1>{}(_.first) ^ hash<T2>{}(_.second);
    	}
    };
}
const Mint ZERO = Mint(0, MOD998);


const int IMP = -1e8;
struct Segtree {
	struct Node {
		int dep;
		int wdep;
		int tag = 0;

		vector<vector<int>> dp = vector<vector<int>>(5, vector<int>(2, IMP));

		Node merge(const Node& other) {
			Node ans;

			ans.dp[1][0] = max(dp[1][0], other.dp[1][0]);
			for (int i = 0; i < 2; i++) {
				ans.dp[0][i] = max(dp[0][i], other.dp[0][i]);
				ans.dp[2][i] = max({dp[2][i], other.dp[2][i], dp[0][i] + other.dp[1][0]});
				ans.dp[3][i] = max({dp[3][i], other.dp[3][i], dp[1][0] + other.dp[0][i]});
				ans.dp[4][i] = max({dp[4][i], other.dp[4][i], dp[2][i] + other.dp[0][i], dp[0][i] + other.dp[3][i]});
			}

			return ans;
		}

		void lazy() {
			if (tag) {
				for (int i = 0; i < 5; i++) {
					if (i == 1) continue;
					swap(dp[i][0], dp[i][1]);
				}
				tag = 0;
			}
		}
	};
	
	const int N;
	vector<Node> tree;
	
	void init(int id, int dep, int wdep) {
		id += N;
		tree[id].dep = dep;
		tree[id].wdep = wdep;
		
		tree[id].dp[0][wdep] = dep;
		tree[id].dp[1][0] = -2 * dep;
		tree[id].dp[2][wdep] = -dep;
		tree[id].dp[3][wdep] = -dep;
		tree[id].dp[4][wdep] = 0;
	}
	
	void build() {
		for (int i = N - 1; i >= 1; i--)
			tree[i] = tree[i << 1].merge(tree[i << 1 ^ 1]);
	}
	
	void upd(int id, int l, int r, int ql, int qr) {
		if (ql <= l && r <= qr) {
			tree[id].tag ^= 1;
			tree[id].lazy();
			return;
		}
		
		int mid = l + r >> 1;
		if (ql <= mid)
			upd(id << 1, l, mid, ql, qr);
			
		if (qr > mid)
			upd(id << 1 ^ 1, mid + 1, r, ql, qr);
			
		tree[id] = tree[id << 1].merge(tree[id << 1 ^ 1]);
	}
	
	Segtree(int sz) : N(sz) {
		tree.resize(N << 1);
	}
};

int main() {
	int n; R(n);
	vector<vector<pii>> g(n + 1);
	vector<pii> e(n - 1);
	vector<int> w(n - 1);

	for (int i = 0; i < n - 1; i++) {
		int u,v,t; R(u,v,t);
		g[u].pb({v, i});
		g[v].pb({u, i});
		e[i] = {u, v};
		w[i] = t;
	}
	
	vector<int> dep(n + 1), wdep(n + 1);
	function<void(int, int, int)> dfs1 = [&](int u, int p, int pe) {
		dep[u] = p == -1 ? 0 : dep[p] + 1;
		wdep[u] = p == -1 ? 0 : wdep[p] ^ w[pe];
		if (pe != -1 && e[pe].F == u)
			swap(e[pe].F, e[pe].S);
		
		for (auto& e : g[u]) {
			if (e.F != p) {
				dfs1(e.F, u, e.S);
			}
		}
	};
	
	dfs1(1, -1, -1);
	
	vector<int> in(n + 1), out(n + 1);
	vector<int> euler;
	function<void(int, int)> dfs_euler = [&](int u, int p) {
		in[u] = (int)euler.size();
		euler.pb(u);
		
		for (auto& e : g[u]) {
			if (e.F != p) {
				dfs_euler(e.F, u);
				euler.pb(u);
			}
		}
		
		out[u] = (int)euler.size() - 1;
	};
	
	dfs_euler(1, -1);
	assert((int)euler.size() == 2 * n - 1);
	
	Segtree st(524288);
	for (int i = 0; i < (int)euler.size(); i++)
		st.init(i, dep[euler[i]], wdep[euler[i]]);
		
	st.build();
	
	CASE(m) {
		int id; R(id);
		int root = e[--id].S;
		
		st.upd(1, 0, 524287, in[root], out[root]);
		W(max(st.tree[1].dp[4][0], st.tree[1].dp[4][1]));
	}
	
	return 0;
}

static auto __init__ = [](){
#ifndef LOCAL
	ios::sync_with_stdio(false);
	cin.tie(0);
#endif
	cout << fixed << setprecision(10);
	return 42;
}();
