Elf Tournament Lineup

Decide whether 2^N elves can be lined up for a knockout tournament so every sensitive elf avoids its listed friends through the first K rounds.

Medium7BacktrackingGraphDivide and conquerNo attempts yetTime limit5sMemory limit512 MB

Problem

The elves are holding a single elimination tournament for 2N2^N elves. Before it starts, the elves receive distinct ID numbers from 11 to 2N2^N, and the elf president lines all of them up in an order of the president's choosing.

Every match is played by two elves and ends with one winner and one loser. There are no draws. In round 1 the 1st and the 2nd elf in the line play each other, the 3rd and the 4th play each other, and so on. The 2N12^{N-1} elves who lost leave the line, the 2N12^{N-1} elves who won stay where they are, and round 2 pairs up the remaining elves in the same way. After NN rounds a single elf is left, and that elf wins the tournament.

MM of the elves are sensitive. The sensitive elf with ID number EiE_i has a list of BiB_i friends and becomes sad if that elf has to play a match against one of those friends during the first KiK_i rounds. Friendship does not have to be mutual: elf aa may count elf bb as a friend while elf bb does not count elf aa as a friend.

The president wants to fix the starting order so that no elf becomes sad, no matter how the matches turn out. Decide whether such an order exists.

Input

The first line has the number of test cases TT. Each test case starts with a line holding two integers NN and MM. After that come MM groups of two lines each. The first line of a group has three integers EiE_i, KiK_i and BiB_i, and the second line has the BiB_i ID numbers of the friends of elf EiE_i.

Limits

  • 1T2001 \le T \le 200
  • 1N41 \le N \le 4
  • 0M2N0 \le M \le 2^N
  • 1Ei2N1 \le E_i \le 2^N, and the MM values EiE_i are all different
  • 1KiN1 \le K_i \le N
  • every friend ID is between 11 and 2N2^N, differs from EiE_i, and appears at most once in the list of elf EiE_i
  • MB1+B2++BMmin(2M,2N)M \le B_1 + B_2 + \dots + B_M \le \min(2M, 2^N)

Output

For each test case, print one line containing "Case #x: ", where x is the test case number starting from 1, followed by YES if the president can line the elves up so that no elf ever becomes sad, and NO otherwise.