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<stdio.h>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<utility>
#include<functional>
#include<iomanip>
#include<sstream>
#include<ctime>
#include<cassert>
using namespace std;
#define y0 y0z
#define y1 y1z
#define yn ynz
#define j0 j0z
#define j1 j1z
#define jn jnz
#define tm tmz
#define buli(x) (__builtin_popcountll(x))
#define bur0(x) (__builtin_ctzll(x))
#define bul2(x) (63-__builtin_clzll(x))
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fil(a,b) memset((a),(b),sizeof(a))
#define cl(a) fil(a,0)
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
#define rep(i,a,b) for (int i=(a),_ed=(b);i<_ed;i++)
#define per(i,a,b) for (int i=(b)-1,_ed=(a);i>=_ed;i--)
#define forg(i,gu) for (int i=gu;~i;i=e[i].next)
#define pw(x) ((ll(1))<<(x))
#define upmo(a,b) (((a)=((a)+(b))%mo)<0?(a)+=mo:(a))
#define mmo(a,b) (((a)=1ll*(a)*(b)%mo)<0?(a)+=mo:(a))
void getre(){int x=0;printf("%d\n",1/x);}
void gettle(){int res=1;while(1)res<<=1;printf("%d\n",res);}
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
template<typename T,typename S>inline bool upmin(T&a,const S&b){return a>b?a=b,1:0;}
template<typename T,typename S>inline bool upmax(T&a,const S&b){return a<b?a=b,1:0;}
template<typename N,typename PN>inline N flo(N a,PN b){return a>=0?a/b:-((-a-1)/b)-1;}
template<typename N,typename PN>inline N cei(N a,PN b){return a>0?(a-1)/b+1:-(-a/b);}
template<typename N>N gcd(N a,N b){return b?gcd(b,a%b):a;}
template<typename N>inline int sgn(N a){return a>0?1:(a<0?-1:0);}
#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)
#define lld "%I64d"
#else
#define lld "%lld"
#endif
inline void gn(long long&x){
	int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');
	c=='-'?(sg=-1,x=0):(x=c-'0');
	while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;
}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
inline void gn(double&x){double t;scanf("%lf",&t);x=t;}
inline void gn(long double&x){double t;scanf("%lf",&t);x=t;}
inline void gs(char *s){scanf("%s",s);}
inline void gc(char &c){while((c=getchar())>126 || c<33);}
inline void pc(char c){putchar(c);}
#ifdef JCVB
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
typedef long long ll;
typedef double db;
inline ll sqr(ll a){return a*a;}
inline db sqrf(db a){return a*a;}
const int inf=0x3f3f3f3f;
//const ll inf=0x3f3f3f3f3f3f3f3fll;
const db pi=3.14159265358979323846264338327950288L;
const db eps=1e-6;
//const int mo=0;
//int qp(int a,ll b){int n=1;do{if(b&1)n=1ll*n*a%mo;a=1ll*a*a%mo;}while(b>>=1);return n;}

int n;
vi cha[55],chb[55];
vi ocha[55],ochb[55];

int waitb[55];
int fab[55];

int curdeg[55];
int deleteleaf[55];
void okb(int rot) {
	waitb[rot]=-1;
	for (int v:chb[rot]) {
		if(waitb[v]==0) {
			fab[v]=rot;
			waitb[v]=1;
		}
	}
}

void dfs(int u,int pr) {
	for (int v:cha[u]) {
		if(v==pr)continue;
		if(waitb[v]==1 && fab[v]==u) {
			okb(v);
			dfs(v,u);
		}
	}
}

void oka(int u) {
	deleteleaf[u]=1;
	for (int v:cha[u]) {
		if(!deleteleaf[v]) {
			curdeg[v]--;
		}
	}
}
int ok(int rot,int to) {
	//printf("%d %d\n",rot,to);
	fab[rot]=0;
	rep(i,1,n+1){
		cha[i].clear();
	}
	rep(u,1,n+1)for(int v:ocha[u]) {
		if(u>v)continue;

		if(u==rot || v==rot)continue;
		cha[u].pb(v);
		cha[v].pb(u);
	}
	cha[rot].pb(to);
	cha[to].pb(rot);

	rep(i,1,n+1)curdeg[i]=siz(cha[i]);

	cl(waitb);
	cl(deleteleaf);
	cl(fab);

	okb(rot);

	dfs(rot,-1);

	int gainum=0;
	rep(u,1,n+1)if(waitb[u]!=-1)gainum++;

	while(1) {
		int hasleft=0;
		int done=0;
		rep(u,1,n+1)if(waitb[u]==1) {
			hasleft=1;
			if(curdeg[u]==1) {
				okb(u);
				oka(u);
				done=1;
				break;
			}
		}

		if(done)continue;
		if(!hasleft) {
			return gainum;
		}
		return inf;
	}

}
void work(){
	gn(n);
	rep(i,1,n+1){
		ocha[i].clear(),ochb[i].clear();
	}

	rep(i,1,n){
		int a,b;
		gn(a);gn(b);
		ocha[a].pb(b);
		ocha[b].pb(a);
	}
	rep(i,1,n){
		int a,b;
		gn(a);gn(b);
		ochb[a].pb(b);
		ochb[b].pb(a);
	}
	rep(i,1,n+1)chb[i]=ochb[i];

	int mi = inf;
	rep(i,1,n+1)rep(j,1,n+1)if(i!=j) {
		if(siz(ocha[i])==1) {
			int fa = ok(i,j);
			if(fa>=inf)continue;
			if(ocha[i][0]!=j) fa++;
			upmin(mi,fa);
		}
	}
	if(mi==inf)mi=-1;

	printf("%d\n",mi);

}
int main()
{
	int te;gn(te);
	while(te--){
		work();
	}
	return 0;

}