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:
// 2021
#include <bits/stdc++.h>
#define rep(i, x, y) for(int i = x; i < y; i++)
#define REP(i, x, y) for(int i = x; i <= y; i++)
#define per(i, x, y) for(register int i = x; i > y; i--)
#define PER(i, x, y) for(register int i = x; i >= y; i--)
#define repl(i, x, y) for(register long long i = x; i < y; i++)
#define REPL(i, x, y) for(register long long i = x; i <= y; i++)
#define perl(i, x, y) for(register long long i = x; i > y; i--)
#define PERL(i, x, y) for(register long long i = x; i >= y; i--)
#define LLL __int128
#define int128 __int128
#define DEBUG(x) cerr << #x << " : " << x << endl
using namespace std;
typedef unsigned int uint;
typedef long long int64;
typedef long long LL;
typedef unsigned long long uint64;
typedef unsigned long long ULL;
typedef long double LLF;
inline void NO() { cout << "NO\n"; }
inline void YES() { cout << "YES\n"; }
inline void NEG() { cout << "-1\n"; }
template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; }
template<typename T> inline bool chkmin(T &a, T b) { return a > b ? a = b, true : false; }
template<typename T> inline void read(T &val)
{
	val = 0; char c = getchar(); int f = 1;
	while(!isdigit(c)) { if(c == '-') f = -1; c = getchar(); }
	while(isdigit(c)) { val = (val << 3) + (val << 1) + (c ^ 48); c = getchar(); }
	val *= f;
}
template<typename T> void write_(T val) { if(!val) return; write_(val / 10); putchar(val % 10 + 48); }
template<typename T> inline void write(T val)
{
	if(val == 0) putchar(48);
	else if(val < 0) { putchar('-'); write_(-val); }
	else write_(val);
}

//#define int long long

const int N = 3e5 + 5;
int n, a[N], b[N], ord[N], siz[N], idx, cnt, ans;
vector<int> G1[N], G2[N];

struct binary_indexed_tree
{
	int o[N];
	void Clear() { for(int i = 1; i <= n; i++) o[i] = 0; }
	void Modify(int p, int v) { for(; p <= n; p += p & -p) o[p] += v; }
	int Query(int p) 
	{ 
		int res = 0; 
		for(; p; p -= p & -p) res += o[p]; 
		return res; 
	}
} t1, t2; 

void Dfs2(int u)
{
	ord[u] = ++idx;
	siz[u] = 1;
	for(int v : G2[u])
	{
		Dfs2(v);
		siz[u] += siz[v];
	}
}
void Dfs1(int u)
{
	int flag = 0, res;
	if(t2.Query(ord[u] + siz[u] - 1) - t2.Query(ord[u] - 1)) flag = 1;
	else
	{
		res = t1.Query(ord[u]);
		if(res > 0)
		{
			t1.Modify(ord[res], -res);
			t1.Modify(ord[res] + siz[res], res);
			t2.Modify(ord[res], -1);
			t1.Modify(ord[u], u);
			t1.Modify(ord[u] + siz[u], -u);
			t2.Modify(ord[u], 1);
			flag = 2;
		}
		else
		{
			cnt++; flag = 3; 
			t1.Modify(ord[u], u);
			t1.Modify(ord[u] + siz[u], -u);
			t2.Modify(ord[u], 1);
		}
	}
	chkmax(ans, cnt);
	for(int v : G1[u]) Dfs1(v);
	if(flag == 1) return;
	if(flag == 2)
	{
		t1.Modify(ord[u], -u);
		t1.Modify(ord[u] + siz[u], u);
		t2.Modify(ord[u], -1);
		t1.Modify(ord[res], res);
		t1.Modify(ord[res] + siz[res], -res);
		t2.Modify(ord[res], 1);
	}
	if(flag == 3)
	{
		cnt--;
		t1.Modify(ord[u], -u);
		t1.Modify(ord[u] + siz[u], u);
		t2.Modify(ord[u], -1);
	}
}

signed main()
{
#ifdef LOCAL
//	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
int test_cases;
cin >> test_cases;
//test_cases = 1;
while(test_cases--)
{
	cin >> n;
	t1.Clear(); t2.Clear(); idx = ans = 0;
	REP(i, 1, n) { G1[i].clear(); G2[i].clear(); }
	REP(i, 2, n) { cin >> a[i]; G1[a[i]].push_back(i); }
	REP(i, 2, n) { cin >> b[i]; G2[b[i]].push_back(i); }
	Dfs2(1);
	// REP(i, 1, n) cout << "[" << ord[i] << "]\n";
	Dfs1(1);
	cout << ans << endl;
}
	return 0;
}