/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 110;
VI e[2][SIZE];
set<PII>need;
void init(int N){
    FOR(i,1,N){
        REP(j,2)e[j][i].clear();
    }
    need.clear();
}
bool equal(int N){
    FOR(i,1,N){
        REP(j,2)sort(ALL(e[j][i]));
        if(e[0][i]!=e[1][i])return 0;
    }
    return 1;
}
int deg[SIZE];
bool is_leaf_in_tree0(int x){
    return deg[x]==1;
}
int stop[SIZE];
int dfs0(int x,int lt){
    stop[x]=1;
    int num=1;
    for(int y:e[1][x]){
        if(y==lt)continue;
        if(binary_search(ALL(e[0][x]),y)){
            num+=dfs0(y,x);
        }
    }
    return num;
}
int father[SIZE],father2[SIZE];
void build(int x,int lt){
    father[x]=lt;
    for(int y:e[1][x]){
        if(y==lt)continue;
        build(y,x);
    }
}
void build2(int x,int lt){
    father2[x]=lt;
    for(int y:e[0][x]){
        if(y==lt)continue;
        build2(y,x);
    }
}
bool valid(int N,int x,int y){
    stop[x]=1;
    FOR(i,1,N)deg[i]=SZ(e[0][i]);
    deg[e[0][x][0]]--;
    deg[y]++;
    set<int>AA;
    build(x,x);
    build2(y,y);
    FOR(i,1,N){
        if(deg[i]==1&&!stop[i]){
            //if(x==1&&y==2)W(i,"-");
            AA.insert(i);
        }
    }
    while(SZ(AA)){
        bool suc=0;
        for(int v:AA){
            if(stop[father[v]]){
                //if(x==1&&y==2)W(v,"ker");
                AA.erase(v);
                suc=1;
                stop[v]=1;
                int u=father2[v];
                deg[u]--;
                if(!stop[u]&&deg[u]==1){
                    AA.insert(u);
                }
                break;
            }
        }
        if(!suc)break;
    }
    FOR(i,1,N){
        if(!stop[i])return 0;
    }
    return 1;
}
int main(){
    CASET{
        int N; R(N);
        init(N);
        REPP(i,1,N){
            int x,y; R(x,y);
            e[0][x].PB(y);
            e[0][y].PB(x);
        }
        REPP(i,1,N){
            int x,y; R(x,y);
            need.insert({x,y});
            need.insert({y,x});
            e[1][x].PB(y);
            e[1][y].PB(x);
        }
        FOR(i,1,N)REP(j,2)sort(ALL(e[j][i]));
        if(equal(N))W(0);
        else{
            int an=N+1;
            FOR(x,1,N){
                if(SZ(e[0][x])==1){
                    FOR(y,1,N){
                        if(x==y)continue;
                        if(e[0][x][0]==y)continue;
                        int now=0;
                        MS0(stop);
                        if(need.count({x,y})){
                            now=dfs0(y,x);
                        }
                        if(valid(N,x,y)){
                            //W(x,y,now);
                            an=min(an,N-now);
                        }
                    }
                }
            }
            if(an==N+1)W(-1);
            else W(an);
        }
    }
    return 0;
}

### Prompt

Your task is to create a CPP solution to the following 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

### Response

```cpp
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 110;
VI e[2][SIZE];
set<PII>need;
void init(int N){
    FOR(i,1,N){
        REP(j,2)e[j][i].clear();
    }
    need.clear();
}
bool equal(int N){
    FOR(i,1,N){
        REP(j,2)sort(ALL(e[j][i]));
        if(e[0][i]!=e[1][i])return 0;
    }
    return 1;
}
int deg[SIZE];
bool is_leaf_in_tree0(int x){
    return deg[x]==1;
}
int stop[SIZE];
int dfs0(int x,int lt){
    stop[x]=1;
    int num=1;
    for(int y:e[1][x]){
        if(y==lt)continue;
        if(binary_search(ALL(e[0][x]),y)){
            num+=dfs0(y,x);
        }
    }
    return num;
}
int father[SIZE],father2[SIZE];
void build(int x,int lt){
    father[x]=lt;
    for(int y:e[1][x]){
        if(y==lt)continue;
        build(y,x);
    }
}
void build2(int x,int lt){
    father2[x]=lt;
    for(int y:e[0][x]){
        if(y==lt)continue;
        build2(y,x);
    }
}
bool valid(int N,int x,int y){
    stop[x]=1;
    FOR(i,1,N)deg[i]=SZ(e[0][i]);
    deg[e[0][x][0]]--;
    deg[y]++;
    set<int>AA;
    build(x,x);
    build2(y,y);
    FOR(i,1,N){
        if(deg[i]==1&&!stop[i]){
            //if(x==1&&y==2)W(i,"-");
            AA.insert(i);
        }
    }
    while(SZ(AA)){
        bool suc=0;
        for(int v:AA){
            if(stop[father[v]]){
                //if(x==1&&y==2)W(v,"ker");
                AA.erase(v);
                suc=1;
                stop[v]=1;
                int u=father2[v];
                deg[u]--;
                if(!stop[u]&&deg[u]==1){
                    AA.insert(u);
                }
                break;
            }
        }
        if(!suc)break;
    }
    FOR(i,1,N){
        if(!stop[i])return 0;
    }
    return 1;
}
int main(){
    CASET{
        int N; R(N);
        init(N);
        REPP(i,1,N){
            int x,y; R(x,y);
            e[0][x].PB(y);
            e[0][y].PB(x);
        }
        REPP(i,1,N){
            int x,y; R(x,y);
            need.insert({x,y});
            need.insert({y,x});
            e[1][x].PB(y);
            e[1][y].PB(x);
        }
        FOR(i,1,N)REP(j,2)sort(ALL(e[j][i]));
        if(equal(N))W(0);
        else{
            int an=N+1;
            FOR(x,1,N){
                if(SZ(e[0][x])==1){
                    FOR(y,1,N){
                        if(x==y)continue;
                        if(e[0][x][0]==y)continue;
                        int now=0;
                        MS0(stop);
                        if(need.count({x,y})){
                            now=dfs0(y,x);
                        }
                        if(valid(N,x,y)){
                            //W(x,y,now);
                            an=min(an,N-now);
                        }
                    }
                }
            }
            if(an==N+1)W(-1);
            else W(an);
        }
    }
    return 0;
}

```