#include <bits/stdc++.h>
typedef int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
//#define endl '\n'
//#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=55;
ll n;
ll yal[N][N];
vector <int> y[N];
ll par[N];
ll par2[N];
ll ans;
void dfsfindpar(ll v,ll p){
    par[v]=p;
    for (auto u : y[v]){
        if (u==p) continue;
        dfsfindpar(u,v);
    }
    return ;
}
vector <int> g[N];
vector <int> out[N];
void dfsfind(ll v,ll p){
    par2[v]=p;
    for (auto u : g[v]){
        if (u==p) continue;
        dfsfind(u,v);
    }
    return;
}
ll in[N];
ll jav;
ll vis2[N];
void dddfs(ll v,ll p,ll k){
    if (k!=v){
        out[k].pb(v);
        in[v]++;
    }
    for (auto u : g[v]){
        if (u==p) continue;
        dddfs(u,v,k);
    }
    return ;
}
void ddfs(ll v,ll p){
    if (!vis2[v]) dddfs(v,p,v);
    for (auto u : g[v]){
        if (u==p) continue;
        ddfs(u,v);
    }
    return ;
}
void dfs(ll v,ll p){
    if (par[v]!=p){
        jav++;
        ddfs(v,p);

    }
    for (auto u : g[v]){
        if (u==p) continue;
        dfs(u,v);
    }
    return ;
}
ll vis[N];
void check(){
    memset(vis2,0,sizeof vis2);
    memset(vis,0,sizeof vis);
    queue <int> q;
    for (int i=1;i<=n;i++){
        if (!in[i]) q.push(i);
    }
    while(q.size()){
        ll v=q.front();
        q.pop();
        vis[v]=1;
        for (auto u : out[v]){
            in[u]--;
            if (in[u]==0) q.push(u);
        }
    }
    for (int i=1;i<=n;i++){
        if (!vis[i]) jav=1e9;
    }
    return ;
}
ll solve(ll v){
    jav=0;
    for (int i=1;i<=n;i++){
        out[i].clear();
        in[i]=0;
        g[i].clear();
        for (int j=1;j<=n;j++){
            if (yal[i][j]) g[i].pb(j);
        }
    }
    dfsfind(v,v);
    dfsfindpar(v,v);
    dfs(v,v);
    for (int t=1;t<=n;t++){
        for (int i=1;i<=n;i++){
            if (in[par[i]] || par2[par[i]]!=par[par[i]] || out[par[i]].size()){
                out[i].pb(par[i]);
                in[par[i]]++;
            }
        }
    }
   // cout << par2[par[4]] << " par " << par[par[4]] << endl;
    check();
    return jav;
}
ll Main(){
    ans=1e9;
    cin >> n;
    memset(yal,0,sizeof yal);
    for (int i=1;i<=n;i++) y[i].clear();
    for (int i=1;i<n;i++){
        ll u,v;
        cin >> u >> v;
        yal[u][v]=1;
        yal[v][u]=1;
    }
    for (int i=0;i<n-1;i++){
        ll u,v;
        cin >> u >> v;
        y[u].pb(v);
        y[v].pb(u);
    }
    for (int i=1;i<=n;i++){
        ll deg=0;
        ll id=0;
        for (int j=1;j<=n;j++){
            if (yal[i][j]){
                deg++;
                id=j;
            }
        }
        if (deg>1) continue;
        yal[i][id]=0;
        yal[id][i]=0;
        for (int j=1;j<=n;j++){
            if (i==j) continue;
            /// case ans=0 ;
            yal[i][j]=1;
            yal[j][i]=1;
            ans=min(ans,solve(i)+(j!=id));
       //     cout << i << " " << j << " " << ans << endl;
            yal[i][j]=0;
            yal[j][i]=0;
        }
        yal[i][id]=1;
        yal[id][i]=1;
    }
    if (ans>2*n) kill(-1);
    kill(ans);

}
int32_t main(){
    sync;
    ll t;
    cin >> t;
    while(t--) Main();
    return 0;
}






Measured memory_bytes: 3808