Problem: Soroush and Keshi each have a labeled and rooted tree on n vertices. Both of their trees are rooted from vertex 1.

Soroush and Keshi used to be at war. After endless decades of fighting, they finally became allies to prepare a Codeforces round. To celebrate this fortunate event, they decided to make a memorial graph on n vertices.

They add an edge between vertices u and v in the memorial graph if both of the following conditions hold: 

  * One of u or v is the ancestor of the other in Soroush's tree. 
  * Neither of u or v is the ancestor of the other in Keshi's tree. 



Here vertex u is considered ancestor of vertex v, if u lies on the path from 1 (the root) to the v.

Popping out of nowhere, Mashtali tried to find the maximum clique in the memorial graph for no reason. He failed because the graph was too big. 

Help Mashtali by finding the size of the maximum clique in the memorial graph.

As a reminder, clique is a subset of vertices of the graph, each two of which are connected by an edge.

Input

The first line contains an integer t (1≤ t≤ 3 ⋅ 10^5) — the number of test cases. The description of the test cases follows.

The first line of each test case contains an integer n (2≤ n≤ 3 ⋅ 10^5).

The second line of each test case contains n-1 integers a_2, …, a_n (1 ≤ a_i < i), a_i being the parent of the vertex i in Soroush's tree.

The third line of each test case contains n-1 integers b_2, …, b_n (1 ≤ b_i < i), b_i being the parent of the vertex i in Keshi's tree.

It is guaranteed that the given graphs are trees.

It is guaranteed that the sum of n over all test cases doesn't exceed 3 ⋅ 10^5.

Output

For each test case print a single integer — the size of the maximum clique in the memorial graph.

Example

Input


4
4
1 2 3
1 2 3
5
1 2 3 4
1 1 1 1
6
1 1 1 1 2
1 2 1 2 2
7
1 1 3 4 4 5
1 2 1 4 2 5


Output


1
4
1
3

Note

In the first and third test cases, you can pick any vertex.

In the second test case, one of the maximum cliques is \{2, 3, 4, 5\}.

In the fourth test case, one of the maximum cliques is \{3, 4, 6\}.

Solution (in JAVA):

Solution:
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;

public class Main {
	static PrintWriter outprint;
	static Reader scanner;
	public static void main(String[] args) throws IOException {
		input_output();
		Main solver = new Main();
		solver.solve();
		outprint.close();

		outprint.flush();
	}

	static long INF = (long)1e18;
	static int MAXN = (int)4e5 + 5;
	static int MOD = 998244353;
	static int q, t, n, m, k;
	static double pi = Math.PI;

	static List<Integer> adj1[], adj2[];

	void solve() throws IOException {
		t = scanner.nextInt();

		while (t --> 0) {
			n = scanner.nextInt();

			adj1 = new ArrayList[n+1];
			adj2 = new ArrayList[n+1];
			for (int i = 1; i <= n; i++) {
				adj1[i] = new ArrayList<>();
				adj2[i] = new ArrayList<>();
			}

			for (int i = 2; i <= n; i++) {
				int tmp = scanner.nextInt();

				adj1[i].add(tmp);
				adj1[tmp].add(i);
			}

			for (int i = 2; i <= n; i++) {
				int tmp = scanner.nextInt();

				adj2[i].add(tmp);
				adj2[tmp].add(i);
			}

			st = new ArrayDeque<>();
			total = 1;
			ans = 0; cnt = 0;
			depth = new int[n+1];
			in = new int[n+1];
			out = new int[n+1];
			set = new TreeSet<>();
			set2 = new TreeSet<>();
			last = new int[n+1];

			dfs2(1, 0);
			dfs(1, 0);

			outprint.println(total);
		}
	}

	static void dfs2(int s, int p) {
		in[s] = out[s] = cnt++;

		for (int e : adj2[s]) {
			if (e == p) continue;

			depth[e] = depth[s]+1;
			dfs2(e, s);
			out[s] = out[e];
		}
	}

	static void dfs(int s, int p) {
		for (int e : adj1[s]) {
			if (e == p) continue;

			insert(e);
			dfs(e, s);
		}

		remove(s);
	}

	static Node low, high;
	static TreeSet<Node> set, set2;
	static ArrayDeque<State> st;
	static int ans, cnt, total;
	static int[] last, in, out, depth;
	static void insert(int s) {
		// check something above me?
		low = set2.higher(new Node(s, out[s]-1));
		// outprint.println("hello "+s+" "+((low != null) ? low.id+" "+low.in+" "+in[low.id]+" "+in[s]+" "+out[s] : ""));
		if (low != null && out[s] <= low.in && in[low.id] <= in[s]) { // a node above me exists
			//outprint.println("bye "+s);
			set.remove(low);
			set.add(new Node(s, in[s]));
			set2.remove(new Node(low.id, out[low.id]));
			set2.add(new Node(s, out[s]));
			//outprint.println("remove2 "+low.id+" "+out[s]+" "+low.in+" "+low.id);
			//outprint.println("add2 "+s);
			st.addLast(new State(-1, low.id));
			st.addLast(new State(1, s));
			last[s]+=2;
			return;
		}

		// else
		// check if a node below me exists
		high = set.higher(new Node(s, in[s]));
		if (high != null && high.in <= out[s]) { // a node below me exists.
			return;
		} else { // nothing below me exists.
			set.add(new Node(s, in[s]));
			set2.add(new Node(s, out[s]));
			st.addLast(new State(1, s));
			ans++;
			//outprint.println("add1 "+s);
			total = Math.max(total, ans);
			last[s]++;
		}
	}

	static void remove(int s) {
		while (last[s] > 0) {
			State tmp = st.removeLast();
			if (tmp.type == -1) {
				set.add(new Node(tmp.id, in[tmp.id]));
				set2.add(new Node(tmp.id, out[tmp.id]));
				//outprint.println("add3 "+tmp.id);
			} else {
				set.remove(new Node(tmp.id, in[tmp.id]));
				set2.remove(new Node(tmp.id, out[tmp.id]));
				//outprint.println("remove3 "+tmp.id);
			}
			if (tmp.type == 1) ans--;
			else ans++;
			//ans += tmp.val;
			total = Math.max(total, ans);
			last[s]--;
		}
	}

	static class Node implements Comparable<Node> {
		int id, in;

		Node(int id, int in) {
			this.id = id;
			this.in = in;
		}

		public int compareTo(Node o) {
			if (this.in != o.in) return this.in - o.in;
			return this.id - o.id;
		}
	}

	static class State {
		int type, id;

		State(int type, int id) {
			this.type = type;
			this.id = id;
		}
	}

	static class Reader {
		private InputStream mIs;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public Reader() {
			this(System.in);
		}

		public Reader(InputStream is) {
			mIs = is;
		}

		public int read() {
			if (numChars == -1) {
				throw new InputMismatchException();

			}
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = mIs.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0) {
					return -1;
				}
			}
			return buf[curChar++];
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String next() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

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

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9') {
					throw new InputMismatchException();
				}
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9') {
					throw new InputMismatchException();
				}
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

	}
	static void input_output() throws IOException {
		File f = new File("in.txt");
		if (f.exists() && !f.isDirectory()) {
			scanner = new Reader(new FileInputStream("in.txt"));
		} else scanner = new Reader();
		f = new File("out.txt");
		if (f.exists() && !f.isDirectory()) {
			outprint = new PrintWriter(new File("out.txt"));
		} else outprint = new PrintWriter(System.out);
	}
}