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<cstring>
#define lc (u<<1)
#define rc (u<<1|1)
using namespace std;
const int maxn=300010;
int Fir1[maxn],Nxt1[maxn<<1],Too1[maxn<<1],tot1;
int Fir2[maxn],Nxt2[maxn<<1],Too2[maxn<<1],tot2;
int siz[maxn],fa[maxn],dfn[maxn],last[maxn],Times;
int top[maxn],dep[maxn],son[maxn],ans,n;
template<class T>inline T Max(const T &a,const T &b){return a>b?a:b;}
struct SegmentTree{
	int l,r,v;
}tr[maxn<<2];
inline void add1(int a,int b){
	Too1[++tot1]=b;Nxt1[tot1]=Fir1[a];Fir1[a]=tot1;
}
inline void add2(int a,int b){
	Too2[++tot2]=b;Nxt2[tot2]=Fir2[a];Fir2[a]=tot2;
}
inline void dfs2(int u,int f){
	siz[u]=1;fa[u]=f;son[u]=0;
	for(int i=Fir2[u];i;i=Nxt2[i]){
		int v=Too2[i];
		if(v!=f){
			dfs2(v,u);
			siz[u]+=siz[v];
			if(siz[v]>siz[son[u]])son[u]=v;
		}
	}
}
inline void dfs3(int u,int f,int tp){
	dfn[u]=++Times;
	top[u]=tp;dep[u]=dep[f]+1;
	if(!son[u]){last[u]=Times;return;}
	dfs3(son[u],u,tp);
	for(int i=Fir2[u];i;i=Nxt2[i]){
		int v=Too2[i];
		if(v!=f&&v!=son[u])dfs3(v,u,v);
	}
	last[u]=Times;
}
inline void build(int u,int l,int r){
	tr[u].l=l;tr[u].r=r;tr[u].v=0;
	if(tr[u].l==tr[u].r)return;
	int mid=(l+r)>>1;
	build(lc,l,mid);build(rc,mid+1,r);
}
inline void modify(int u,int l,int r,int d){
	if(l<=tr[u].l&&tr[u].r<=r){tr[u].v=d;return;}
	int mid=(tr[u].l+tr[u].r)>>1;
	if(l<=mid)modify(lc,l,r,d);
	if(mid<r) modify(rc,l,r,d);
}
inline int query(int u,int x){
	if(tr[u].l==tr[u].r||tr[u].v)return tr[u].v;
	int mid=(tr[u].l+tr[u].r)>>1;
	if(x<=mid)return query(lc,x);
	else return query(rc,x);
}
inline void add(int x,int d){
	int fx=top[x];
	while(fx!=1){
		modify(1,dfn[fx],dfn[x],d);
		x=fa[fx];fx=top[x];
	}
	modify(1,1,dfn[x],d);
}
inline void dfs1(int u,int f,int cnt){
	int x=query(1,dfn[u]);
	if(x){
		if(dep[x]<dep[u]){
			add(x,0);
			modify(1,dfn[x],last[x],0);
			add(u,u);
			modify(1,dfn[u],last[u],u);
		}
	}
	else{
		add(u,u);
		modify(1,dfn[u],last[u],u);
		++cnt;
	}
	ans=Max(ans,cnt);
	for(int i=Fir1[u];i;i=Nxt1[i]){
		int v=Too1[i];
		if(v!=f)dfs1(v,u,cnt);
	}
	if(x){
		if(dep[x]<dep[u]){
			add(u,0);
			modify(1,dfn[u],last[u],0);
			add(x,x);
			modify(1,dfn[x],last[x],x);
		}
	}
	else{
		add(u,0);
		modify(1,dfn[u],last[u],0);
	}
}
int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		scanf("%d",&n);
		memset(Fir1,0,sizeof(int)*(n+1));tot1=0;
		memset(Fir2,0,sizeof(int)*(n+1));tot2=0;
		ans=0;Times=0;
		build(1,1,n);
		for(int i=2;i<=n;++i){
			int a;
			scanf("%d",&a);
			add1(a,i);add1(i,a);
		}
		for(int i=2;i<=n;++i){
			int a;
			scanf("%d",&a);
			add2(a,i);add2(i,a);
		}
		dfs2(1,0);
		dfs3(1,0,1);
		dfs1(1,0,0);
		printf("%d\n",ans);
	}
	return 0;
}