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<cstdio>
#include<algorithm>
#include<set>
#define pii std::pair<int,int>
#define mp std::make_pair
#define fir first
#define sec second
#define N 300005

int T;

int n;

int ans;

namespace T2{
	int hd[N],_hd;
	struct edge{
		int v,nxt;
	}e[N<<1];
	inline void addedge(int u,int v){
		e[++_hd]=(edge){v,hd[u]};
		hd[u]=_hd;
	}
	
	int fa[N],son[N],dep[N],sz[N];
	inline void dfs1(int u){
		dep[u]=dep[fa[u]]+1;
		sz[u]=1;
		for(int i=hd[u];i;i=e[i].nxt){
			int v=e[i].v;
			if(v==fa[u])
				continue;
			fa[v]=u;
			dfs1(v);
			sz[u]+=sz[v];
			if(sz[v]>sz[son[u]])
				son[u]=v;
		}
	}
	int top[N],dfn[N],_dfn;
	inline void dfs2(int u){
		dfn[u]=++_dfn;
		top[u]=u==son[fa[u]]?top[fa[u]]:u;
		if(son[u])
			dfs2(son[u]);
		for(int i=hd[u];i;i=e[i].nxt){
			int v=e[i].v;
			if(v==son[u]||v==fa[u])
				continue;
			dfs2(v);
		}
	}
	inline int lca(int u,int v){
		while(top[u]!=top[v]){
			if(dep[top[u]]<dep[top[v]])
				std::swap(u,v);
			u=fa[top[u]];
		}
		return dep[u]<dep[v]?u:v;
	}
	inline bool chka(int u,int v){
		return lca(u,v)==u;
	}
	
	std::set<pii> s;
	inline int ins(int u){
		auto it=s.insert(mp(dfn[u],u)).fir,L=it,R=it;
		R++;
		if(R!=s.end())
			if(chka(u,R->sec)){
				s.erase(it);
				return -1;
			}
		if(L==s.begin())
			return 0;
		L--;
		int v=L->sec;
		if(chka(v,u)){
			s.erase(L);
			return v;
		}
		else
			return 0;
	}
}

namespace T1{
	int hd[N],_hd;
	struct edge{
		int v,nxt;
	}e[N<<1];
	inline void addedge(int u,int v){
		e[++_hd]=(edge){v,hd[u]};
		hd[u]=_hd;
	}
	
	inline void dfs(int u,int fa){
//		auto t=T2::s;
		int flg=T2::ins(u);
		ans=std::max(ans,(int)T2::s.size());
		for(int i=hd[u];i;i=e[i].nxt){
			int v=e[i].v;
			if(v==fa)
				continue;
			dfs(v,u);
		}
		if(flg>0)
			T2::s.insert(mp(T2::dfn[flg],flg));
		if(flg!=-1)
			T2::s.erase(mp(T2::dfn[u],u));
//		if(t!=T2::s)
//			puts("A");
	}
}

int main(){
	scanf("%d",&T);
	while(T--){
		for(int i=1;i<=n;i++)
			T1::hd[i]=T2::hd[i]=T2::son[i]=0;
		T1::_hd=T2::_hd=0;
		T2::_dfn=0;
		T2::s.clear();
		scanf("%d",&n);
		for(int i=2;i<=n;i++){
			int u;
			scanf("%d",&u);
			T1::addedge(u,i);
			T1::addedge(i,u);
		}
		for(int i=2;i<=n;i++){
			int u;
			scanf("%d",&u);
			T2::addedge(u,i);
			T2::addedge(i,u);
		}
		T2::dfs1(1);
		T2::dfs2(1);
		ans=0;
		T1::dfs(1,0);
		printf("%d\n",ans);
	}
}