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 CPP):

Solution:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<unordered_map>
#include<map>
#include<queue>
#include<complex>
#include<set>
#define int long long
//#define double long double
using namespace std;
using pii = pair<int, int>;
const int inf = 1e9 + 7;
struct segtree {
	vector<int> t;
	vector<int> mod;
	segtree() {
		t = {};
		mod = {};
	}
	segtree(int n, int x) {
		t = vector<int>(4 * n, x);
		mod = vector<int>(4 * n, -inf);
	}
	void push(int v, int tl, int tr) {
		//cout << v << ' ' << tl << ' ' << tr << endl;
		if (tl >= tr || mod[v] == -inf) return;
		int tm = (tl + tr) >> 1;
		t[2 * v] = mod[v] * (tm - tl + 1);
		t[2 * v + 1] = mod[v] * (tr - tm);
		mod[2 * v] = mod[v];
		mod[2 * v + 1] = mod[v];
		mod[v] = -inf;
	}
	int get(int v, int tl, int tr, int l, int r) {
		push(v, tl, tr);
		if (tl > tr || l > r) return 0;
		if (tl == l && tr == r) {
			return t[v];
		}
		int tm = (tl + tr) >> 1;
		return (get(2 * v, tl, tm, l, min(r, tm)) + get(2 * v + 1, tm + 1, tr, max(l, tm + 1), r));
	}
	void upd(int v, int tl, int tr, int l, int r, int x) {
		push(v, tl, tr);
		if (tl > tr || l > r) return;
		if (tl == l && tr == r) {
			mod[v] = x;
			t[v] = x * (tr - tl + 1);
			return;
		}
		int tm = (tl + tr) >> 1;
		upd(2 * v, tl, tm, l, min(r, tm), x);
		upd(2 * v + 1, tm + 1, tr, max(l, tm + 1), r, x);
		t[v] = t[2 * v] + t[2 * v + 1];
	}
	void add(int v, int tl, int tr, int x, int ps) {
		//cout << tl << ' ' << tr << ' ' << ps << endl;
		push(v, tl, tr);
		if (tl == tr) {
		//	cout << "OK\n";
			t[v] += x;
			return;
		}
		int tm = (tl + tr) >> 1;
		if (ps <= tm) {
			add(2 * v, tl, tm, x, ps);
		} else {
			add(2 * v + 1, tm + 1, tr, x, ps);
		}
		t[v] = t[2 * v] + t[2 * v + 1];
	}
};
vector<vector<int>> g1, g2;
vector<int> tin1, tout1, tin2, tout2;
int tm1 = 0, tm2 = 0;
void dfs1(int v, int p = -1) {
	tin1[v] = tm1++;
	for (auto u : g1[v]) {
		if (u != p) {
			dfs1(u, v);
		}
	}
	tout1[v] = tm1;
}
void dfs2(int v, int p = -1) {
	tin2[v] = tm2++;
	for (auto u : g2[v]) {
		if (u != p) {
			dfs2(u, v);
		}
	}
	tout2[v] = tm2;
}
segtree t1, t2;
int ANS = 0;
int curval = 0;
void dfsres(int v,int n,int p = -1) {
	int p0 = -1;
	bool ok = 0;
	int add = 0;
	if (t1.get(1, 0, n - 1, tin2[v], tout2[v] - 1) == 0) {
		ok = 1;
		p0 = t2.get(1, 0, n - 1, tin2[v], tin2[v]);
		if (p0 == -1) {
			curval++;
			add = 1;
		}
		if (p0 != -1) {
			t2.upd(1, 0, n - 1, tin2[p0], tout2[p0] - 1, -1);
		}
		t2.upd(1, 0, n - 1, tin2[v], tout2[v] - 1, v);
	}
	t1.add(1, 0, n - 1, 1, tin2[v]);
	ANS = max(ANS, curval);
	for (auto u : g1[v]) {
		if (u == p) continue;
		dfsres(u, n, v);
	}
	t1.add(1, 0, n - 1, -1, tin2[v]);
	if (ok) {
		t2.upd(1, 0, n - 1, tin2[v], tout2[v] - 1, -1);
	}
	if (p0 != -1) {
		t2.upd(1, 0, n - 1, tin2[p0], tout2[p0] - 1, p0);
	}
	curval -= add;
}
void solve() {
	int n;
	cin >> n;
	t1 = segtree(n, 0);
	t2 = segtree(n, -1);
	g1.clear();
	g2.clear();
	tin1.clear();
	tin2.clear();
	tout1.clear();
	tout2.clear();
	tm1 = 0, tm2 = 0;
	g1.resize(n);
	g2.resize(n);
	tin1.resize(n);
	tin2.resize(n);
	tout1.resize(n);
	tout2.resize(n);
	for (int i = 1; i < n; ++i) {
		int x;
		cin >> x;
		g1[x - 1].push_back(i);
	}
	for (int i = 1; i < n; ++i) {
		int x;
		cin >> x;
		g2[x - 1].push_back(i);
	}
	ANS = 0;
	dfs1(0);
	dfs2(0);
	dfsres(0, n);
	cout << ANS << '\n';
}
int32_t main() {
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.tie(0);
    int tt = 1;
    std::cin >> tt;
    while (tt--) {
        solve();
    }
}