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<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=55;
int test,n,ans;
bool e1[maxn][maxn],e2[maxn][maxn],ban[maxn][maxn],mv[maxn];
int par1[maxn],par2[maxn],deg[maxn],q[maxn];
vector<int>edge1[maxn],edge2[maxn],nedge[maxn];

void dfs1(int x,int p,bool f){
	par1[x]=p;
	mv[x]=f;
	rep(i,int(edge1[x].size())){
		int y=edge1[x][i];
		if(y==p||ban[x][y])continue;
		dfs1(y,x,f||(!e2[x][y]));
	}
}
void dfs2(int x,int p){
	par2[x]=p;
	rep(i,int(edge2[x].size())){
		int y=edge2[x][i];
		if(y==p)continue;
		dfs2(y,x);
	}
}
int work(int x){
	dfs1(x,0,false);
	dfs2(x,0);
	REP(i,n)nedge[i].clear(),deg[i]=0;
	REP(i,n){
		if(mv[i]&&mv[par1[i]])nedge[i].pb(par1[i]),deg[par1[i]]++;
		if(mv[i]&&mv[par2[i]])nedge[par2[i]].pb(i),deg[i]++;
	}
	int l=1,r=0;
	REP(i,n)if(!deg[i])q[++r]=i;
	while(l<=r){
		int x=q[l++];
		rep(i,int(nedge[x].size())){
			int y=nedge[x][i];
			deg[y]--;
			if(!deg[y])q[++r]=y;
		}
	}
	if(r!=n)return n+1;
	int res=0;
	REP(i,n)res+=mv[i];
	return res;
}

int main(){
	scanf("%d",&test);
	while(test--){
		scanf("%d",&n);
		ans=n+1;
		REP(i,n){
			edge1[i].clear();
			edge2[i].clear();
			REP(j,n)e1[i][j]=e2[i][j]=false;
		}
		REP(i,n-1){
			int u,v;
			scanf("%d%d",&u,&v);
			edge1[u].pb(v);
			edge1[v].pb(u);
			e1[u][v]=e1[v][u]=true;
		}
		REP(i,n-1){
			int u,v;
			scanf("%d%d",&u,&v);
			edge2[u].pb(v);
			edge2[v].pb(u);
			e2[u][v]=e2[v][u]=true;
		}
		bool ok=true;
		REP(i,n)rep(j,int(edge1[i].size()))ok&=e2[i][edge1[i][j]];
		if(ok){
			puts("0");
			continue;
		}
		REP(i,n)if(int(edge1[i].size())==1){
			int ii=edge1[i][0];
			ban[i][ii]=ban[ii][i]=true;
			e1[i][ii]=e1[ii][i]=false;
			REP(j,n)if(j!=i&&j!=ii){
				edge1[i].pb(j);
				edge1[j].pb(i);
				e1[i][j]=e1[j][i]=true;
				ans=min(ans,work(i)+1);
				edge1[i].pop_back();
				edge1[j].pop_back();
				e1[i][j]=e1[j][i]=false;
			}
			ban[i][ii]=ban[ii][i]=false;
			e1[i][ii]=e1[ii][i]=true;
		}
		printf("%d\n",ans==n+1?-1:ans);
	}
	return 0;
}