// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double INF=1e+10;
const long double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		// if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ
vector<int>g[60];
vector<int>g2[60];
vector<int>G[60];
vector<int>G2[60];
int v[60];
int pa[60];
int pb[60];
int chi[60];
void dfs(int a,int b){
	pa[a]=b;

	for(int i=0;i<g[a].size();i++){
		if(b==g[a][i])continue;
		dfs(g[a][i],a);
		chi[a]++;
	}
}
void dfs2(int a,int b){
	pb[a]=b;
	for(int i=0;i<g2[a].size();i++){
		if(b==g2[a][i])continue;
		dfs2(g2[a][i],a);
	}
}
int n;
int f(int a){
	int i=a;
	for(int j=0;j<n;j++)v[j]=chi[j]=0;
	dfs(i,-1);
	dfs2(i,-1);
	
	v[i]=1;
	int tmp=0;
	while(1){
		bool chg=false;
		for(int j=0;j<n;j++){
			if(v[j])continue;
			if(!v[pb[j]])continue;
			if(pa[j]==pb[j]){
				// printf("%d 0\n",j);
				v[j]=1;
				chg=true;
				break;
			}
		}
		if(chg)continue;
		for(int j=0;j<n;j++){
			if(v[j])continue;
			if(chi[j])continue;
			if(!v[pb[j]])continue;
			// printf("%d 1\n",j);
			chi[pa[j]]--;
			v[j]=1;
			tmp++;
			chg=true;
			break;
		}
		if(chg)continue;
		break;
	}
	bool ok=true;
	for(int j=0;j<n;j++)if(!v[j])ok=false;
	if(ok){
		// printf("%d\n",tmp);
		return tmp;
	}return mod;
}
int mat[2][60][60];
int main(){
	int T;scanf("%d",&T);
	while(T--){
		int a;scanf("%d",&a);
		n=a;
		for(int k=0;k<2;k++)for(int i=0;i<60;i++)for(int j=0;j<60;j++)mat[k][i][j]=0;
		for(int i=0;i<60;i++){
			g[i].clear();
			g2[i].clear();
		}
		for(int i=0;i<a-1;i++){
			int p,q;scanf("%d%d",&p,&q);p--;q--;
			g[p].push_back(q);
			g[q].push_back(p);
			mat[0][p][q]=mat[0][q][p]=1;
		}
		for(int i=0;i<a-1;i++){
			int p,q;scanf("%d%d",&p,&q);p--;q--;
			g2[p].push_back(q);
			g2[q].push_back(p);
			mat[1][p][q]=mat[1][q][p]=1;
		}
		int ret=mod;
		for(int i=0;i<a;i++){
			ret=min(ret,f(i));
		}
		for(int i=0;i<a;i++){
			G[i]=g[i];
			G2[i]=g2[i];
		}
		for(int i=0;i<a;i++){
			if(G[i].size()==1){
				mat[0][i][G[i][0]]=mat[0][G[i][0]][i]=0;
				for(int j=0;j<a;j++){
					if(i==j)continue;
					mat[0][i][j]=mat[0][j][i]=1;
					for(int k=0;k<a;k++){
						g[k].clear();
					}
					for(int k=0;k<a;k++)for(int l=0;l<a;l++){
						if(mat[0][k][l]){
							g[k].push_back(l);
						}
					}
					ret=min(ret,f(i)+1);
					mat[0][i][j]=mat[0][j][i]=0;
				}
				mat[0][i][G[i][0]]=mat[0][G[i][0]][i]=1;
			}
		}
		if(ret==mod)ret=-1;
		printf("%d\n",ret);
	}
}
### Prompt

In Cpp, your task is to solve the following problem:

Snuke has found two trees A and B, each with N vertices numbered 1 to N. The i-th edge of A connects Vertex a_i and b_i, and the j-th edge of B connects Vertex c_j and d_j. Also, all vertices of A are initially painted white.

Snuke would like to perform the following operation on A zero or more times so that A coincides with B:

* Choose a leaf vertex that is painted white. (Let this vertex be v.)
* Remove the edge incident to v, and add a new edge that connects v to another vertex.
* Paint v black.



Determine if A can be made to coincide with B, ignoring color. If the answer is yes, find the minimum number of operations required.

You are given T cases of this kind. Find the answer for each of them.

Constraints

* 1 \leq T \leq 20
* 3 \leq N \leq 50
* 1 \leq a_i,b_i,c_i,d_i \leq N
* All given graphs are trees.

Input

Input is given from Standard Input in the following format:


T
case_1
:
case_{T}


Each case is given in the following format:


N
a_1 b_1
:
a_{N-1} b_{N-1}
c_1 d_1
:
c_{N-1} d_{N-1}


Output

For each case, if A can be made to coincide with B ignoring color, print the minimum number of operations required, and print `-1` if it cannot.

Examples

Input

2
3
1 2
2 3
1 3
3 2
6
1 2
2 3
3 4
4 5
5 6
1 2
2 4
4 3
3 5
5 6


Output

1
-1


Input

3
8
2 7
4 8
8 6
7 1
7 3
5 7
7 8
4 2
5 2
1 2
8 1
3 2
2 6
2 7
4
1 2
2 3
3 4
3 4
2 1
3 2
9
5 3
4 3
9 3
6 8
2 3
1 3
3 8
1 7
4 1
2 8
9 6
3 6
3 5
1 8
9 7
1 6


Output

6
0
7

### Response

```cpp
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double INF=1e+10;
const long double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		// if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ
vector<int>g[60];
vector<int>g2[60];
vector<int>G[60];
vector<int>G2[60];
int v[60];
int pa[60];
int pb[60];
int chi[60];
void dfs(int a,int b){
	pa[a]=b;

	for(int i=0;i<g[a].size();i++){
		if(b==g[a][i])continue;
		dfs(g[a][i],a);
		chi[a]++;
	}
}
void dfs2(int a,int b){
	pb[a]=b;
	for(int i=0;i<g2[a].size();i++){
		if(b==g2[a][i])continue;
		dfs2(g2[a][i],a);
	}
}
int n;
int f(int a){
	int i=a;
	for(int j=0;j<n;j++)v[j]=chi[j]=0;
	dfs(i,-1);
	dfs2(i,-1);
	
	v[i]=1;
	int tmp=0;
	while(1){
		bool chg=false;
		for(int j=0;j<n;j++){
			if(v[j])continue;
			if(!v[pb[j]])continue;
			if(pa[j]==pb[j]){
				// printf("%d 0\n",j);
				v[j]=1;
				chg=true;
				break;
			}
		}
		if(chg)continue;
		for(int j=0;j<n;j++){
			if(v[j])continue;
			if(chi[j])continue;
			if(!v[pb[j]])continue;
			// printf("%d 1\n",j);
			chi[pa[j]]--;
			v[j]=1;
			tmp++;
			chg=true;
			break;
		}
		if(chg)continue;
		break;
	}
	bool ok=true;
	for(int j=0;j<n;j++)if(!v[j])ok=false;
	if(ok){
		// printf("%d\n",tmp);
		return tmp;
	}return mod;
}
int mat[2][60][60];
int main(){
	int T;scanf("%d",&T);
	while(T--){
		int a;scanf("%d",&a);
		n=a;
		for(int k=0;k<2;k++)for(int i=0;i<60;i++)for(int j=0;j<60;j++)mat[k][i][j]=0;
		for(int i=0;i<60;i++){
			g[i].clear();
			g2[i].clear();
		}
		for(int i=0;i<a-1;i++){
			int p,q;scanf("%d%d",&p,&q);p--;q--;
			g[p].push_back(q);
			g[q].push_back(p);
			mat[0][p][q]=mat[0][q][p]=1;
		}
		for(int i=0;i<a-1;i++){
			int p,q;scanf("%d%d",&p,&q);p--;q--;
			g2[p].push_back(q);
			g2[q].push_back(p);
			mat[1][p][q]=mat[1][q][p]=1;
		}
		int ret=mod;
		for(int i=0;i<a;i++){
			ret=min(ret,f(i));
		}
		for(int i=0;i<a;i++){
			G[i]=g[i];
			G2[i]=g2[i];
		}
		for(int i=0;i<a;i++){
			if(G[i].size()==1){
				mat[0][i][G[i][0]]=mat[0][G[i][0]][i]=0;
				for(int j=0;j<a;j++){
					if(i==j)continue;
					mat[0][i][j]=mat[0][j][i]=1;
					for(int k=0;k<a;k++){
						g[k].clear();
					}
					for(int k=0;k<a;k++)for(int l=0;l<a;l++){
						if(mat[0][k][l]){
							g[k].push_back(l);
						}
					}
					ret=min(ret,f(i)+1);
					mat[0][i][j]=mat[0][j][i]=0;
				}
				mat[0][i][G[i][0]]=mat[0][G[i][0]][i]=1;
			}
		}
		if(ret==mod)ret=-1;
		printf("%d\n",ret);
	}
}
```