Relaxed Golf

Relaxed Golf is a solitaire game. Cards are dealt face up in 7 columns of 5 cards each. The remaining 17 cards are put face down into the draw pile. Suits don’t matter, so we will represent cards using integers between 1 (Ace) and 13 (King), four of each. For this problem, we will know the order of the cards in the draw pile. Finally, we have the discard pile. The goal of the game is to put all of the cards into the discard pile. A move consists of playing a card from the top of the draw pile or the top of one of the non-empty columns on top of the discard pile. When playing from the columns, the rank of card played must differ by exactly one from the rank of the card on top of the discard pile. In Relaxed Golf (as opposed to regular Golf), wraparound is allowed. Kings may be played on top of aces, and vice versa. We can play cards from the draw pile onto the discard pile at any time. In fact, the first move must be from the draw pile. Input The input starts with a line giving the number of test cases, N. Each test case consists of 6 lines. The first 5 lines have 7 cards each and list the cards in the columns, with the top cards appearing on the 5th line. The 6th line lists the cards in the draw pile, from bottom to top. Output For each test case, output one line containing ‘Case # x:’ followed by either ‘Yes’ or ‘No’, depending on whether the puzzle can be solved or not. Sample Input 2 910 910 910 9 7878787 5656565 3434343 1212121 13 13 13 13 12 12 12 12 11 11 11 11 10 8 6 4 2 5 5 513131313 7776666 9988887 1110101010 9 9 12 12 12 12 11 11 11 11112222333344445 Sample Output Case #1: Yes Case #2: No Golf and sex are about the only things you can enjoy without being good at. Jimmy Demaret