{"raw_statement":[{"iden":"problem statement","content":"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.\nSnuke would like to perform the following operation on $A$ zero or more times so that $A$ coincides with $B$:\n\n*   Choose a leaf vertex that is painted white. (Let this vertex be $v$.)\n*   Remove the edge incident to $v$, and add a new edge that connects $v$ to another vertex.\n*   Paint $v$ black.\n\nDetermine if $A$ can be made to coincide with $B$, ignoring color. If the answer is yes, find the minimum number of operations required.\nYou are given $T$ cases of this kind. Find the answer for each of them."},{"iden":"constraints","content":"*   $1 \\leq T \\leq 20$\n*   $3 \\leq N \\leq 50$\n*   $1 \\leq a_i,b_i,c_i,d_i \\leq N$\n*   All given graphs are trees."},{"iden":"input","content":"Input is given from Standard Input in the following format:\n\n$T$\n$case_1$\n$:$\n$case_{T}$\n\nEach case is given in the following format:\n\n$N$\n$a_1$ $b_1$\n$:$\n$a_{N-1}$ $b_{N-1}$\n$c_1$ $d_1$\n$:$\n$c_{N-1}$ $d_{N-1}$"},{"iden":"sample input 1","content":"2\n3\n1 2\n2 3\n1 3\n3 2\n6\n1 2\n2 3\n3 4\n4 5\n5 6\n1 2\n2 4\n4 3\n3 5\n5 6"},{"iden":"sample output 1","content":"1\n-1\n\n*   The graph in each case is shown below.\n*   In case $1$, $A$ can be made to coincide with $B$ by choosing Vertex $1$, removing the edge connecting $1$ and $2$, and adding an edge connecting $1$ and $3$. Note that Vertex $2$ is not a leaf vertex and thus cannot be chosen.\n\n![image](https://img.atcoder.jp/agc027/3f020b4a4e883680357cc55adb571fbc.png)"},{"iden":"sample input 2","content":"3\n8\n2 7\n4 8\n8 6\n7 1\n7 3\n5 7\n7 8\n4 2\n5 2\n1 2\n8 1\n3 2\n2 6\n2 7\n4\n1 2\n2 3\n3 4\n3 4\n2 1\n3 2\n9\n5 3\n4 3\n9 3\n6 8\n2 3\n1 3\n3 8\n1 7\n4 1\n2 8\n9 6\n3 6\n3 5\n1 8\n9 7\n1 6"},{"iden":"sample output 2","content":"6\n0\n7\n\n*   $A$ may coincide with $B$ from the beginning."}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}