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

import java.io.*;
import java.util.*;

public class D {
	FastScanner in;
	PrintWriter out;
	boolean systemIO = true;

	public class Pair implements Comparable<Pair> {
		long x;
		long y;

		public Pair(long x, long y) {
			this.x = x;
			this.y = y;
		}

		@Override
		public int compareTo(Pair o) {
			if (x > o.x) {
				return 1;
			}
			if (x < o.x) {
				return -1;
			}
			if (y > o.y) {
				return 1;
			}
			if (y < o.y) {
				return -1;
			}
			return 0;
		}

	}

	public class Fenvik {
		int[] sum;

		public Fenvik(int n) {
			sum = new int[n];
		}

		public void add(int x, int d) {
			for (int i = x; i < sum.length; i = (i | (i + 1))) {
				sum[i] += d;
			}
		}

		public int sum(int r) {
			int ans = 0;
			for (int i = r; i >= 0; i = (i & (i + 1)) - 1) {
				ans += sum[i];
			}
			return ans;
		}

		public int sum(int l, int r) {
			if (l > r) {
				return 0;
			}
			return sum(r) - sum(l - 1);
		}
	}

	public long gcd(long x, long y) {
		if (y == 0) {
			return x;
		}
		if (x == 0) {
			return y;
		}
		return gcd(y, x % y);
	}

	public long[][] pow(long[][] x, long p) {
		if (p == 0) {
			long[][] ans = new long[x.length][x.length];
			for (int i = 0; i < ans.length; i++) {
				ans[i][i] = 1;
			}
			return ans;
		}
		long[][] t = pow(x, p / 2);
		t = multiply(t, t);
		if (p % 2 == 1) {
			t = multiply(t, x);
		}
		return t;
	}

	public long[][] multiply(long[][] a, long[][] b) {
		long[][] ans = new long[a.length][b[0].length];
		for (int i = 0; i < ans.length; i++) {
			for (int j = 0; j < ans[0].length; j++) {
				for (int k = 0; k < b.length; k++) {
					ans[i][j] += a[i][k] * b[k][j];
					ans[i][j] %= mod;
				}
			}
		}
		return ans;
	}

	public long pow(long x, long p) {
		if (p == 0) {
			return 1;
		}
		long t = pow(x, p / 2);
		t *= t;
		t %= mod;
		if (p % 2 == 1) {
			t *= x;
			t %= mod;
		}
		return t;
	}

	public long modInv(long x) {
		return pow(x, mod - 2);
	}

	long mod = 1000000007;

	public class VectorInt {
		long x;
		long y;

		public VectorInt(long x, long y) {
			this.x = x;
			this.y = y;
		}

		public VectorInt subtract(VectorInt v) {
			return new VectorInt(x - v.x, y - v.y);
		}

		public double norm() {
			return Math.sqrt(x * x + y * y);
		}
	}

	public class VectorDouble {
		double x;
		double y;

		public VectorDouble(double x, double y) {
			this.x = x;
			this.y = y;
		}

		public VectorDouble(VectorInt v) {
			x = v.x;
			y = v.y;
		}

		public String toString() {
			return x + " " + y;
		}

		public VectorDouble add(VectorDouble v) {
			return new VectorDouble(x + v.x, y + v.y);
		}

		public VectorDouble subtract(VectorDouble v) {
			return new VectorDouble(x - v.x, y - v.y);
		}

		public VectorDouble mult(double c) {
			return new VectorDouble(x * c, y * c);
		}

		public double norm() {
			return Math.sqrt(x * x + y * y);
		}

		public double norm2() {
			return x * x + y * y;
		}

		public void normalize() {
			double n = norm();
			x /= n;
			y /= n;
		}
	}

	public long dp(VectorInt a, VectorInt b) {
		return a.x * b.x + a.y * b.y;
	}

	public long cp(VectorInt a, VectorInt b) {
		return a.x * b.y - a.y * b.x;
	}

	public double dp(VectorDouble a, VectorDouble b) {
		return a.x * b.x + a.y * b.y;
	}

	public double cp(VectorDouble a, VectorDouble b) {
		return a.x * b.y - a.y * b.x;
	}

	Random random = new Random(566);

	double eps = 1e-9;

	public class Fret implements Comparable<Fret> {
		int value;
		int index;

		public Fret(int value, int index) {
			this.value = value;
			this.index = index;
		}

		@Override
		public int compareTo(Fret o) {
			if (value != o.value) {
				return value - o.value;
			}
			return index - o.index;
		}

	}

	public class SegmentTreeMaxSumXor {
		int pow;
		int[] sum;
		int[] xor;
		int[][] maxPrefSum;
		int[][] maxSufSum;
		int[][] maxSum;
		int inf;

		public SegmentTreeMaxSumXor(int[] a, int[] xor1) {
			pow = 1;
			while (pow < a.length) {
				pow *= 2;
			}
			inf = Integer.MIN_VALUE / 2;
			sum = new int[2 * pow];
			xor = new int[2 * pow];
			maxPrefSum = new int[2][2 * pow];
			maxSum = new int[2][2 * pow];
			maxSufSum = new int[2][2 * pow];
			for (int i = 0; i < a.length; i++) {
				sum[pow + i] = a[i];
				xor[pow + i] = xor1[i];
				maxSum[0][pow + i] = 0;
				maxPrefSum[0][pow + i] = 0;
				maxSufSum[0][pow + i] = 0;
				maxSum[1][pow + i] = inf;
				maxPrefSum[1][pow + i] = inf;
				maxSufSum[1][pow + i] = inf;
				maxSum[xor1[i]][pow + i] = Math.max(a[i], maxSum[xor1[i]][pow + i]);
				maxPrefSum[xor1[i]][pow + i] = maxSum[xor1[i]][pow + i];
				maxSufSum[xor1[i]][pow + i] = maxSum[xor1[i]][pow + i];
			}
			for (int i = pow - 1; i > 0; i--) {
				update(i);
			}
		}

		public int get() {
			return maxSum[0][1];
		}

		public void set(int v, int tl, int tr, int x, int value, int xor1) {
			if (v >= pow) {
				sum[v] = value;
				xor[v] = xor1;
				maxSum[0][v] = 0;
				maxPrefSum[0][v] = 0;
				maxSufSum[0][v] = 0;
				maxSum[1][v] = inf;
				maxPrefSum[1][v] = inf;
				maxSufSum[1][v] = inf;
				maxSum[xor1][v] = Math.max(value, maxSum[xor1][v]);
				maxPrefSum[xor1][v] = maxSum[xor1][v];
				maxSufSum[xor1][v] = maxSum[xor1][v];
				return;
			}
			int tm = (tl + tr) / 2;
			if (x < tm) {
				set(2 * v, tl, tm, x, value, xor1);
			} else {
				set(2 * v + 1, tm, tr, x, value, xor1);
			}
			update(v);
		}

		public void update(int i) {
			sum[i] = f(sum[2 * i], sum[2 * i + 1]);
			xor[i] = xor[2 * i] ^ xor[2 * i + 1];
			for (int j = 0; j < 2; j++) {
				maxSum[j][i] = Math.max(maxSum[j][2 * i], maxSum[j][2 * i + 1]);
				for (int xl = 0; xl < 2; xl++) {
					maxSum[j][i] = Math.max(maxSum[j][i], maxSufSum[xl][2 * i] + maxPrefSum[j ^ xl][2 * i + 1]);
				}
				maxPrefSum[j][i] = Math.max(maxPrefSum[j][2 * i], maxPrefSum[j ^ xor[2 * i]][2 * i + 1] + sum[2 * i]);
				maxSufSum[j][i] = Math.max(maxSufSum[j][2 * i + 1],
						maxSufSum[j ^ xor[2 * i + 1]][2 * i] + sum[2 * i + 1]);
			}
		}

		public int f(int a, int b) {
			return a + b;
		}
	}
	
	public int[][] readGraph(int n, int m) {
		int[][] to = new int[n][];
		index = new int[n][];
		xor = new int[m];
		int[] sz = new int[n];
		int[] x = new int[m];
		int[] y = new int[m];
		for (int i = 0; i < m; i++) {
			x[i] = in.nextInt() - 1;
			y[i] = in.nextInt() - 1;
			xor[i] = in.nextInt();
			sz[x[i]]++;
			sz[y[i]]++;
		}
		for (int i = 0; i < to.length; i++) {
			to[i] = new int[sz[i]];
			index[i] = new int[sz[i]];
			sz[i] = 0;
		}
		for (int i = 0; i < x.length; i++) {
			index[x[i]][sz[x[i]]] = i;
			index[y[i]][sz[y[i]]] = i;
			to[x[i]][sz[x[i]]++] = y[i];
			to[y[i]][sz[y[i]]++] = x[i];
		}
		return to;
	}
	
	public void dfs(int v, int edge) {
		for (int i = 0; i < index[v].length; i++) {
			if (index[v][i] == edge) {
				continue;
			}
			xor1[c] = xor[index[v][i]];
			first[index[v][i]] = c;
			value[c++] = 1;
			dfs(to[v][i], index[v][i]);
		}
		if (edge >= 0) {
			xor1[c] = xor[edge];
			second[edge] = c;
			value[c++] = -1;
		}
	}
	
	int[][] to;
	int[] xor;
	int[][] index;

	int[] value;
	int[] xor1;
	
	int c = 0;
	
	int[] first;
	int[] second;
	
	public void solve() {
		int n = in.nextInt();
		to = readGraph(n, n - 1);
		value = new int[2 * n - 2];
		xor1 = new int[2 * n - 2];
		first = new int[n - 1];
		second = new int[n - 1];
		dfs(0, -1);
		SegmentTreeMaxSumXor tree = new SegmentTreeMaxSumXor(value, xor1);
		int q = in.nextInt();
		for (int test = 0; test < q; test++) {
			int e = in.nextInt() - 1;
			xor1[first[e]] ^= 1;
			xor1[second[e]] ^= 1;
			tree.set(1, 0, tree.pow, first[e], 1, xor1[first[e]]);
			tree.set(1, 0, tree.pow, second[e], -1, xor1[second[e]]);
			out.println(tree.get());
		}
	}

	public void run() {
		try {
			if (systemIO) {
				in = new FastScanner(System.in);
				out = new PrintWriter(System.out);
			} else {
				in = new FastScanner(new File("input.txt"));
				out = new PrintWriter(new File("output.txt"));
			}
			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String nextLine() {
			try {
				return br.readLine();
			} catch (IOException e) {
				return null;
			}
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

	}

	// AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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