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 <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define enter putchar('\n')
#define space putchar(' ')
#define fi first
#define se second
//#define ivorysi
#define pii pair<int,int>
using namespace std;
typedef long long int64;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 + c - '0';
	c = getchar();
    }
    res *= f;
}

template<class T>
void out(T x) {
    if(x < 0) {putchar('-');x = -x;}
    if(x >= 10) out(x / 10);
    putchar('0' + x % 10);
}
int N;
int a[2][55][55],fa[2][55],used[55],ind[55],vis[55],ans;
struct node {
    int to,next;
}E[205];
int sumE,head[55];
void add(int u,int v) {
    E[++sumE].to = v;
    E[sumE].next = head[u];
    head[u] = sumE;
}
void dfs(int id,int u,int f) {
    fa[id][u] = f;if(id == 1) used[u] = (used[f] && (fa[0][u] == fa[1][u]));
    for(int i = 1 ; i <= N ; ++i) {
        if(i != f && a[id][u][i]) dfs(id,i,u);
    }
}
bool dfs2(int u) {
    vis[u] = 1;
    for(int i = head[u] ; i ; i = E[i].next) {
        int v = E[i].to;
        if(!vis[v]) {if(!dfs2(v)) return false;}
        else if(vis[v] == 1) return false;
    }
    vis[u] = 2;
    return true;
}
void check_r(int r) {
    used[0] = 1;
    dfs(0,r,0);dfs(1,r,0);
    memset(head,0,sizeof(head));sumE = 0;
    int s = 0;
    for(int i = 1 ; i <= N ; ++i) {
        if(!used[i]) {
            if(!used[fa[0][i]]) add(fa[0][i],i);
            if(!used[fa[1][i]]) add(i,fa[1][i]);
            ++s;
        }
    }
    memset(vis,0,sizeof(vis));
    for(int i = 1 ; i <= N ; ++i) {
        if(!vis[i] && !dfs2(i)) return;
    }
    ans = min(ans,s + 1);
}
void Solve() {
    read(N);
    memset(a,0,sizeof(a));
    memset(ind,0,sizeof(ind));
    int u,v;
    for(int i = 1 ; i < N ; ++i)  {
        read(u);read(v);
        a[0][u][v] = a[0][v][u] = 1;
        ind[u]++;ind[v]++;
    }
    for(int i = 1 ; i < N ; ++i) {
        read(u);read(v);
        a[1][u][v] = a[1][v][u] = 1;
    }
    used[0] = 1;
    dfs(0,1,0);dfs(1,1,0);
    int cnt = 0;
    for(int i = 1 ; i <= N ; ++i) {
        if(!used[i]) ++cnt;
    }
    if(!cnt) {puts("0");return;}
    ans = N + 1;
    for(int i = 1 ; i <= N ; ++i) {
        if(ind[i] == 1) {
            int f = 0;
            for(int j = 1 ; j <= N ; ++j) if(a[0][i][j]) f = j;
            a[0][i][f] = a[0][f][i] = 0;
            for(int j = 1 ; j <= N ; ++j) {
                a[0][i][j] = a[0][j][i] = 1;
                check_r(i);
                a[0][i][j] = a[0][j][i] = 0;
            }
            a[0][i][f] = a[0][f][i] = 1;
        }
    }
    if(ans == N + 1) {puts("-1");}
    else {out(ans);enter;}
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    int T;
    read(T);
    while(T--) {
        Solve();
    }
    return 0;
}