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

Solution (in CPP):

Solution:
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;
#define N 105
int dfn[N],low[N],scc[N],n,m,head[N],cnt,head2[N],cnt2,f1[N],f2[N],head3[N],cnt3,vis[N],is[N],ct,ct2,fg,e1[N][2],e2[N][2],in[N],T;
struct edge{int t,next;}ed[N*10],ed2[N*10],ed3[N*10];
stack<int> tp;
void adde(int f,int t){ed[++cnt]=(edge){t,head[f]};head[f]=cnt;ed[++cnt]=(edge){f,head[t]};head[t]=cnt;}
void adde2(int f,int t){ed2[++cnt2]=(edge){t,head2[f]};head2[f]=cnt2;ed2[++cnt2]=(edge){f,head2[t]};head2[t]=cnt2;}
void adde3(int f,int t){ed3[++cnt3]=(edge){t,head3[f]};head3[f]=cnt3;}
void dfs1(int u,int fa){f1[u]=fa;for(int i=head[u];i;i=ed[i].next)if(ed[i].t!=fa)dfs1(ed[i].t,u);}
void dfs2(int u,int fa){f2[u]=fa;for(int i=head2[u];i;i=ed2[i].next)if(ed2[i].t!=fa)dfs2(ed2[i].t,u);}
void dfs3(int u,int fa)
{
	vis[u]=1;
	for(int i=head2[u];i;i=ed2[i].next)if(ed2[i].t!=fa)is[ed2[i].t]=1;
	queue<int> tp;
	for(int i=head[u];i;i=ed[i].next)if(is[ed[i].t])tp.push(ed[i].t);
	for(int i=head2[u];i;i=ed2[i].next)if(ed2[i].t!=fa)is[ed2[i].t]=0;
	while(!tp.empty())dfs3(tp.front(),u),tp.pop();
}
void dfs4(int u)
{
	tp.push(u);
	dfn[u]=low[u]=++ct;
	for(int i=head3[u];i;i=ed3[i].next)
	{
		if(!dfn[ed3[i].t])dfs4(ed3[i].t),low[u]=min(low[u],low[ed3[i].t]);
		else if(!scc[ed3[i].t])low[u]=min(low[u],dfn[ed3[i].t]);
	}
	if(dfn[u]==low[u])
	{
		int st=++ct2,s=tp.top();
		tp.pop();scc[s]=st;
		while(s!=u)
		{
			s=tp.top();tp.pop();
			scc[s]=st,fg=1;
		}
	}
}
int check(int s)
{
	int as=0;
	for(int i=1;i<=n;i++)head[i]=head2[i]=head3[i]=scc[i]=low[i]=dfn[i]=vis[i]=0;
	ct=ct2=fg=cnt=cnt2=cnt3=0;
	for(int i=1;i<n;i++)adde(e1[i][0],e1[i][1]),adde2(e2[i][0],e2[i][1]);
	dfs1(s,0);dfs2(s,0);dfs3(s,0);
	for(int i=1;i<=n;i++)if(!vis[i]){as++;if(!vis[f1[i]])adde3(i,f1[i]);if(!vis[f2[i]])adde3(f2[i],i);}
	for(int i=1;i<=n;i++)if(!dfn[i])dfs4(i);
	if(fg)return -1;
	return as;
}
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d",&n);
		for(int i=1;i<n;i++)scanf("%d%d",&e1[i][0],&e1[i][1]);
		for(int i=1;i<n;i++)scanf("%d%d",&e2[i][0],&e2[i][1]);
		int mn=1e9,fg2=0;
		for(int i=1;i<=n;i++){int st=check(i);if(st!=-1&&st<mn)mn=st;}
		if(mn<1e9)printf("%d\n",mn);
		else
		{
			for(int i=1;i<=n;i++)
			{
				int st=0;
				for(int j=1;j<n;j++)if(e1[j][0]==i||e1[j][1]==i){if(st)st=-1;else st=j;}
				if(st==-1)continue;
				int l1=e1[st][0],l2=e1[st][1];
				for(int j=1;j<=n;j++)if(j!=i){e1[st][0]=i,e1[st][1]=j;if(check(i)!=-1)fg2=1;}
				e1[st][0]=l1,e1[st][1]=l2;
			}
			if(fg2)printf("%d\n",n);
			else printf("-1\n");
		}
	}
}//