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 <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

// SCC
struct scc {
  int n, k;
  vvi to, ot, d, gt; // to, rev_to, groups, group_to
  vi g, used, kv; // group, gomi, topo_ord
  scc(int n=0):n(n),to(n),ot(n){}
  int inc() { to.pb(vi()); ot.pb(vi()); return n++;}
  void add(int a, int b) { to[a].pb(b); ot[b].pb(a);}
  void dfs(int v) {
    if (used[v]) return;
    used[v] = 1;
    rep(i,sz(to[v])) dfs(to[v][i]);
    kv[--k] = v;
  }
  void rfs(int v) {
    if (g[v] != -1) return;
    g[v] = k; d[k].pb(v);
    rep(i,sz(ot[v])) rfs(ot[v][i]);
  }
  void init() {
    k = n;
    used = kv = vi(n);
    g = vi(n,-1);
    rep(i,n) dfs(i);
    rep(i,n) if (g[kv[i]] == -1)  {
      d.pb(vi());
      rfs(kv[i]);
      k++;
    }
    gt = vvi(k);
    rep(i,n)rep(j,sz(ot[i])) {
      int v = g[ot[i][j]], u = g[i];
      if (v != u) gt[v].pb(u);
    }
    rep(i,k) {
      sort(rng(gt[i]));
      gt[i].erase(unique(rng(gt[i])),gt[i].end());
    }
  }
};
//
struct Solver {
  int n;
  vvi to, g;
  scc s;
  void tfs(int v, int p=-1) {
    for (int u : to[v]) {
      if (u == p) continue;
      s.add(v,u);
      tfs(u,v);
    }
  }
  void gfs(int v, int p=-1) {
    for (int u : g[v]) {
      if (u == p) continue;
      s.add(u,v);
      gfs(u,v);
    }
  }
  int dfs(int v, int p=-1) {
    int res = 1;
    rep(i,n) {
      if (i == v || i == p) continue;
      int fl = 0;
      if (binary_search(rng(to[v]),i)) fl |= 1;
      if (binary_search(rng(g[v]),i)) fl |= 2;
      if (fl == 1) tfs(i,v);
      if (fl == 2) gfs(i,v);
      if (fl == 3) res += dfs(i,v);
    }
    return res;
  }
  int calc(int root) {
    s = scc(n);
    int res = n-dfs(root);
    s.init();
    if (s.k != n) return INF;
    return res;
  }
  void solve() {
    scanf("%d",&n);
    to = g = vvi(n);
    rep(i,n-1) {
      int a,b;
      scanf("%d%d",&a,&b);
      --a; --b;
      to[a].pb(b);
      to[b].pb(a);
    }
    rep(i,n-1) {
      int a,b;
      scanf("%d%d",&a,&b);
      --a; --b;
      g[a].pb(b);
      g[b].pb(a);
    }
    rep(i,n) sort(rng(to[i]));
    rep(i,n) sort(rng(g[i]));
    int ans = INF;
    rep(i,n) {
      int now = calc(i);
      mins(ans,now);
      // cerr<<i<<": "<<now<<endl;
      if (now == INF && sz(to[i]) == 1) {
        int p = to[i][0];
        rep(j,n) if (i != j && j != p) {
          vvi to_ = to;
          to = vvi(n);
          rep(v,n) for (int u : to_[v]) {
            if (P(v,u) == P(i,p)) continue;
            if (P(v,u) == P(p,i)) continue;
            to[v].pb(u);
          }
          to[i].pb(j);
          to[j].pb(i);
          rep(k,n) sort(rng(to[k]));
          int nw = calc(i);
          mins(ans,nw+1);
          to = to_;
        }
      }
    }
    if (ans == INF) ans = -1;
    cout<<ans<<endl;
    // if (ans == -1) {
    //   cout<<n<<endl;
    //   rep(i,n)for (int j : to[i]) if (i < j) cout<<i+1<<" "<<j+1<<endl;
    //   rep(i,n)for (int j : g[i]) if (i < j) cout<<i+1<<" "<<j+1<<endl;
    // }
  }
};

int main() {
  int ts;
  scanf("%d",&ts);
  rrep(ti,ts) {
    Solver solver;
    solver.solve();
    // cerr<<ti<<endl;
  }
  return 0;
}