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;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=55,inf=1e9;
int n,ans,sum,rd[N],a[N],b[N],d[N],A[N],B[N],ti;
vector<int> f[N],g[N],v[N];
void ins(int a,int b){
	v[a].pb(b); rd[b]++; 
}
void dfsa(int p,int fa){
	sum++;
	for(auto i:f[p])if(i!=fa){dfsa(i,p); ins(i,p);}
}
void dfsb(int p,int fa){
	for(auto i:g[p])if(i!=fa){dfsb(i,p); ins(p,i);}
}
void dfs(int p,int fa){
	ti++;
	vector<int> zs,a,b;
	for(auto i:f[p])if(i!=fa)A[i]=ti;
	for(auto i:g[p])if(i!=fa){
		B[i]=ti;
		if(A[i]==ti)zs.pb(i); else b.pb(i);
	}
	for(auto i:f[p])if(i!=fa&&B[i]!=ti)a.pb(i);
	for(auto i:zs)dfs(i,p);
	for(auto i:a)dfsa(i,p);
	for(auto i:b)dfsb(i,p);
}
void solve(vector<int> A,vector<int> B,vector<int> C,vector<int> D,int rt){
	For(i,1,n){
		f[i].clear(); g[i].clear(); v[i].clear(); rd[i]=0;
	}sum=0;
	For(i,0,n-2){
		f[A[i]].pb(B[i]);
		f[B[i]].pb(A[i]);
		g[C[i]].pb(D[i]);
		g[D[i]].pb(C[i]);
	}
	dfs(rt,0);
	queue<int> q;
	For(i,1,n)if(!rd[i])q.push(i);
	while(q.size()){
		int t=q.front(); q.pop();
		for(auto i:v[t])if(--rd[i]==0)q.push(i);
	}
	For(i,1,n)if(rd[i])return;
	ans=min(ans,sum);
}
int main(){
	int T=read();
	while(T--){
		n=read(); ans=inf;
		memset(d,0,sizeof(d));
		set<PI> s1,s2;
		For(i,1,n-1){
			a[i]=read(); b[i]=read();
			if(a[i]>b[i])swap(a[i],b[i]);
			s1.insert(mp(a[i],b[i]));
			d[a[i]]++; d[b[i]]++;
		}
		vector<int> C,D;
		For(i,1,n-1){
			int x=read(),y=read();
			if(x>y)swap(x,y);
			C.pb(x); D.pb(y);
			s2.insert(mp(x,y));
		}
		if(s1==s2){puts("0"); continue;}
		For(i,1,n)if(d[i]==1){
			For(j,1,n)if(i!=j){
				vector<int> A,B;
				For(k,1,n-1){
					if(b[k]==i)A.pb(j); else A.pb(a[k]);
					if(a[k]==i)B.pb(j); else B.pb(b[k]);
				}
				solve(A,B,C,D,i);
			}
		}
		writeln(ans==inf?-1:ans+1);
	}
}