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;

#define cout cerr
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)

typedef long long ll;
typedef pair<int,int> pii;
#define FR first
#define SE second

inline void rd(int &x){
	x=0;char ch=getchar();int f=1;
	while(ch<'0'||ch>'9'){
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	x*=f;
}


int n;
#define Maxn 300010
int in[Maxn],out[Maxn],dfk=0;
namespace T2{
int head[Maxn],v[Maxn<<1],nxt[Maxn<<1],tot=0;
inline void add_edge(int s,int e){
	tot++;v[tot]=e;nxt[tot]=head[s];head[s]=tot;
	tot++;v[tot]=s;nxt[tot]=head[e];head[e]=tot;
}
void dfs(int u,int f){
	in[u]=++dfk;
	for(int i=head[u];i;i=nxt[i])
		if(v[i]!=f){
			dfs(v[i],u);
		}
	out[u]=dfk;
}
void init(){
		tot=0;memset(head,0,sizeof(int)*(n+1));
	}
}

struct cmp
{
    bool operator()(const int &L,const int &R)const{
        return	in[L]<in[R];
    }
};

set<int,cmp> S;
bool vis[Maxn];
int Ans;

set<int,cmp>::iterator it,p;

void Add(int u){
	vis[u]=0;
	if(S.size()==0){
		vis[u]=1;S.insert(u);
		Ans=1;return;
	}
	S.insert(u);
	it=S.find(u);p=it;p++;
	if(p!=S.end()){
		it++;
		int t=(*it);
		if(in[t]<=out[u])vis[u]=0;
		else vis[u]=1;
		it--;
	}else vis[u]=1;
	Ans+=vis[u];
	if(it!=S.begin()){
		it--;
		int t=(*it);
		Ans-=vis[t];
		if(in[u]<=out[t])vis[t]=0;
		else vis[t]=1;
		Ans+=vis[t];
	}
}

void Del(int u){
	Ans-=vis[u];
	it=S.find(u);
	if(it!=S.begin()){
		it--;int t=(*it);
		Ans-=vis[t];
		S.erase(u);p=it;p++;
		if(p==S.end())vis[t]=1;
		else{
			it++;
			int y=(*it);
			if(in[y]<=out[t])vis[t]=0;
			else vis[t]=1;
		}
		Ans+=vis[t];
	}else S.erase(u);
}

namespace T1{
	int head[Maxn],v[Maxn<<1],nxt[Maxn<<1],tot=0;
inline void add_edge(int s,int e){
	tot++;v[tot]=e;nxt[tot]=head[s];head[s]=tot;
	tot++;v[tot]=s;nxt[tot]=head[e];head[e]=tot;
}
	int res=0;
	void dfs(int u,int f){
		Add(u);res=max(res,Ans);
		for(int i=head[u];i;i=nxt[i])
		if(v[i]!=f){
			dfs(v[i],u);
		}
		Del(u);
	}
	void calc(){
		res=0;Ans=0;S.clear();
		dfs(1,0);
		printf("%d\n",res);
	}
	void init(){
		tot=0;memset(head,0,sizeof(int)*(n+1));
	}
}

int main(){
	int T;rd(T);
	while(T--){
		rd(n);int x;
		dfk=0;
		T1::init();T2::init();
		rep(i,2,n){
			rd(x);
			T1::add_edge(x,i);
		}
		rep(i,2,n){
			rd(x);
			T2::add_edge(x,i);
		}
		T2::dfs(1,0);
		T1::calc();
	}
	return 0;
}