Unfortunately, right after Bessie arranged the bracelets in such a careful manner, Farmer John drove by in his tractor, shaking the table and causing the bracelets to shift around and possibly break into multiple (not necessarily closed or simple) polygonal chains! Afterward, Bessie wanted to check whether the three conditions above still held. However, it was dark, so she couldn't see the bracelets anymore.
Fortunately, Bessie had a flashlight. She chose MM (1≤M≤50) vertical lines x=1,x=2,…,x=M and for each line, she swept the beam of the flashlight along that line from y=−∞ to y=∞, recording the colors of all bracelets she saw in the order they appeared. Luckily, no beam crossed over any vertex of any polygonal chain or two line segments at the same time. Furthermore, for each beam, every color that appeared appeared exactly twice.
Can you help Bessie use this information to determine whether it is possible that the bracelets still satisfy all three of the conditions above?
The first line of the input contains T. Each of the T sub-test cases then follow.
The first line of each sub-test case contains two integers N and MM. Each sub-test case then contains MM additional lines. For each ii from 11 to MM, the i-th additional line contains an integer ki (0≤ki≤2N, ki even), followed by ki integers ci1,ci2,…,ciki (cij∈[1,N], every cij appears zero or two times). This means that when Bessie swept her flashlight from (i,−∞) to (i,∞), she encountered the colors ci1,ci2,…,ciki in that order.
5
1 2
2 1 1
2 1 1
1 3
2 1 1
0
2 1 1
2 1
4 1 2 1 2
4 2
6 1 2 2 3 3 1
6 1 2 4 4 2 1
2 2
4 1 1 2 2
4 2 2 1 1
YES
NO
NO
YES
NO
An example of a feasible bracelet configuration for the first sub-case is:
For the fourth sub-case, a feasible arrangement is the following: