#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int N;
bool A[50][50],B[50][50];
bool e[50][50];
void dfsA(int v, int p, vector<bool>& isfixed){
    rep(u,N) if(u!=p && A[v][u]){
            if(!isfixed[v] && !isfixed[u]){
                e[v][u] = 1;
//			printf("(%d->%d)\n",v,u);
            }
            dfsA(u,v,isfixed);
        }
}
void dfsB(int v, int p, vector<bool>& isfixed){
    rep(u,N) if(u!=p && B[v][u]){
            if(!isfixed[v] && !isfixed[u]){
                e[u][v] = 1;
//			printf("(%d->%d)\n",u,v);
            }
            dfsB(u,v,isfixed);
        }
}
vector<int> vis;
bool dfsCycle(int v){
    if(vis[v]==1){
        return 1;
    }
    if(vis[v]==2) return 0;
    vis[v] = 1;
    rep(u,N) if(e[v][u]){
            if(dfsCycle(u)) return 1;
        }
    vis[v]=2;
    return 0;
}
bool hascycle(){
    vis = vector<int>(N,0);
    rep(i,N) if(vis[i]==0){
            if(dfsCycle(i)) return 1;
        }
    return 0;
}
int solve(){
    cin>>N;
    rep(i,N) rep(j,N) A[i][j] = B[i][j] = 0;
    rep(i,N-1){
        int x,y;
        cin>>x>>y;
        x--,y--;
        A[x][y] = A[y][x] = 1;
    }
    rep(i,N-1){
        int x,y;
        cin>>x>>y;
        x--,y--;
        B[x][y] = B[y][x] = 1;
    }

    int ans = 100;
    rep(x,N) rep(y,N){
        vector<bool> isfixed(N,false);
        if(x==y){
            int r = x;
            queue<int> que;
            isfixed[r] = true;
            que.push(r);
            while(!que.empty()){
                int v = que.front();
                que.pop();
                rep(u,N) if(A[v][u] && B[v][u] && !isfixed[u]){
                        isfixed[u] = 1;
                        que.push(u);
                    }
            }
        }
        rep(i,N) rep(j,N) e[i][j] = 0;
        dfsA(x,-1,isfixed);
        dfsB(y,-1,isfixed);
        if(!hascycle()){
            int fixedNum = 0;
            rep(i,N) if(isfixed[i]) fixedNum++;
            int tmp = N-fixedNum;
            chmin(ans,tmp);
        }
    }
    if(ans==100) return -1;
    return ans;
}
int main(){
    int T;
    cin>>T;
    rep(i,T) cout<<solve()<<endl;
}
### Prompt

Please create a solution in cpp 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 <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int N;
bool A[50][50],B[50][50];
bool e[50][50];
void dfsA(int v, int p, vector<bool>& isfixed){
    rep(u,N) if(u!=p && A[v][u]){
            if(!isfixed[v] && !isfixed[u]){
                e[v][u] = 1;
//			printf("(%d->%d)\n",v,u);
            }
            dfsA(u,v,isfixed);
        }
}
void dfsB(int v, int p, vector<bool>& isfixed){
    rep(u,N) if(u!=p && B[v][u]){
            if(!isfixed[v] && !isfixed[u]){
                e[u][v] = 1;
//			printf("(%d->%d)\n",u,v);
            }
            dfsB(u,v,isfixed);
        }
}
vector<int> vis;
bool dfsCycle(int v){
    if(vis[v]==1){
        return 1;
    }
    if(vis[v]==2) return 0;
    vis[v] = 1;
    rep(u,N) if(e[v][u]){
            if(dfsCycle(u)) return 1;
        }
    vis[v]=2;
    return 0;
}
bool hascycle(){
    vis = vector<int>(N,0);
    rep(i,N) if(vis[i]==0){
            if(dfsCycle(i)) return 1;
        }
    return 0;
}
int solve(){
    cin>>N;
    rep(i,N) rep(j,N) A[i][j] = B[i][j] = 0;
    rep(i,N-1){
        int x,y;
        cin>>x>>y;
        x--,y--;
        A[x][y] = A[y][x] = 1;
    }
    rep(i,N-1){
        int x,y;
        cin>>x>>y;
        x--,y--;
        B[x][y] = B[y][x] = 1;
    }

    int ans = 100;
    rep(x,N) rep(y,N){
        vector<bool> isfixed(N,false);
        if(x==y){
            int r = x;
            queue<int> que;
            isfixed[r] = true;
            que.push(r);
            while(!que.empty()){
                int v = que.front();
                que.pop();
                rep(u,N) if(A[v][u] && B[v][u] && !isfixed[u]){
                        isfixed[u] = 1;
                        que.push(u);
                    }
            }
        }
        rep(i,N) rep(j,N) e[i][j] = 0;
        dfsA(x,-1,isfixed);
        dfsB(y,-1,isfixed);
        if(!hascycle()){
            int fixedNum = 0;
            rep(i,N) if(isfixed[i]) fixedNum++;
            int tmp = N-fixedNum;
            chmin(ans,tmp);
        }
    }
    if(ans==100) return -1;
    return ans;
}
int main(){
    int T;
    cin>>T;
    rep(i,T) cout<<solve()<<endl;
}
```