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 <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &x){
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}
inline void write(int x){if (x > 9) write(x/10); putchar(x%10+'0'); }

const int N = 300005;

int n,ans,fa1[N],fa2[N];

vector<int>G1[N],G2[N];

struct BIT{
	int d[N],n;
	inline void init(int nn){ n = nn,memset(d,0,n+1<<2); }
	inline void add(int x){ while (x <= n) ++d[x],x+=x&-x; }
	inline void add2(int x){ while (x <= n) --d[x],x+=x&-x; }
	inline int ask(int x){
		int r=0; while (x)r+=d[x],x-=x&-x; return r; 
	}
	inline int qry(int l,int r){
		return ask(r)-ask(l-1);
	}
}T2;

struct Seg{
	#define lc o<<1
	#define rc o<<1|1
	int n,val[N<<2],is[N<<2];
	inline void Tag(int o,int v){ val[o] = v,is[o] = 1; }
	inline void down(int o){ if (is[o]) is[o] = 0,Tag(lc,val[o]),Tag(rc,val[o]); }
	inline void Build(int o,int l,int r){
		if (o == 1) n = r;
		val[o] = is[o] = 0; if (l < r){ int mid = l+r>>1; Build(lc,l,mid),Build(rc,mid+1,r); }
	}
	int ll,rr,vv;
	inline void Add(int o,int l,int r){
		if (ll <= l && rr >= r){ Tag(o,vv); return; }
		down(o); int mid =l+r>>1; if (ll<=mid) Add(lc,l,mid); if (rr>mid) Add(rc,mid+1,r);
	}
	inline int ask(int p){
		static int mid,o,l,r; o = l = 1,r = n;
		while (l < r){
			down(o),mid = l+r>>1;
			if (p <= mid) o<<=1,r = mid; else o = o<<1|1,l = mid + 1; 
		}
		return val[o];
	}
	inline void add(int l,int r,int v){
		ll =l,rr=r,vv=v; if (l<=r) Add(1,1,n);
	}
	#undef lc
	#undef rc
}T;

int tl[N],tr[N],id[N],Time;
inline void dfs2(int x){
	tl[x] = id[x] = ++Time;
	for (int i = 0; i < G2[x].size(); ++i) dfs2(G2[x][i]);
	tr[x] = Time; 
}
int Now;

inline void dfs1(int x){
	int cx = 0,cy = 0;
	if (!T2.qry(tl[x],tr[x])){
		cx = T.ask(id[x]);
		if (cx == 0){
			cy = x;
			++Now;
		}
		else{
			cy = x;
			T2.add2(id[cx]);
			T.add(tl[cx],tr[cx],0);
		}
		T2.add(id[x]);
		T.add(tl[x],tr[x],x);
	}
	ans =max(ans,Now);
	for (int i = 0; i < G1[x].size(); ++i) dfs1(G1[x][i]);
	
	if (cy == x){
		T2.add2(id[x]);
		T.add(tl[x],tr[x],0);
		if (cx == 0) --Now;
		else T2.add(id[cx]),T.add(tl[cx],tr[cx],cx);
	}
}

inline void solve(){
	int i;
	read(n),ans = 0;
	for (i = 0; i <= n; ++i) G1[i].clear(),G2[i].clear();
	for (i = 2; i <= n; ++i) read(fa1[i]),G1[fa1[i]].push_back(i);
	for (i = 2; i <= n; ++i) read(fa2[i]),G2[fa2[i]].push_back(i);
	T.Build(1,1,n); T2.init(n);
	Time = 0,dfs2(1);
	dfs1(1);
	cout << ans << '\n';
}

int main(){
	int T;
	read(T);
	while (T--) solve();
	return 0;
}