László Babai

For each of up to 100 test cases, decide whether two simple graphs on 3 vertices given by their edge lists are isomorphic.

Easy2GraphBrute forceImplementationNo attempts yetTime limit1sMemory limit256 MB

Problem

László Babai is a Hungarian computer scientist and mathematician. He won the Gödel Prize, and he works on the theory of computation, algorithms, combinatorics, and group theory. He gave an algorithm that decides Graph Isomorphism in exp((logn)O(1))\exp((\log n)^{O(1)}) time. The best time known before that was exp(O(nlogn))\exp(O(\sqrt{n \log n})).

Graph Isomorphism asks the following. Two undirected graphs A=(VA,EA)A = (V_A, E_A) and B=(VB,EB)B = (V_B, E_B) are given, where VA={a1,a2,,anA}V_A = \{a_1, a_2, \ldots, a_{n_A}\} and VB={b1,b2,,bnB}V_B = \{b_1, b_2, \ldots, b_{n_B}\}. The graphs AA and BB are isomorphic if and only if both conditions hold.

  1. AA and BB have the same number of vertices and the same number of edges.
  2. There is a bijection f:VAVBf : V_A \to V_B such that {u,v}EA\{u, v\} \in E_A if and only if {f(u),f(v)}EB\{f(u), f(v)\} \in E_B.

In other words, relabeling the vertices of AA produces BB.

Nobody knows whether Graph Isomorphism is in P, and nobody knows whether it is NP-complete. Take the first step of that challenge and decide whether two undirected simple graphs on 3 vertices are isomorphic.

Input

The first line has one integer TT (1T1001 \le T \le 100), the number of test cases.

Each test case gives two graphs in a row, both in the same format. The description of one graph starts with the number of edges mm (0m30 \le m \le 3) of an undirected simple graph on 3 vertices numbered 1 to 3. Then mm lines follow, each holding two distinct integers uu and vv (uvu \ne v, u,v{1,2,3}u, v \in \{1, 2, 3\}), which means that an edge joins vertex uu and vertex vv. At most one edge joins any pair of vertices.

Output

For each test case, print yes on its own line if the two graphs are isomorphic, and no otherwise.