Find the card shared by the chosen rows of two 4 by 4 layouts, or report a bad layout or cheating.
Easy1ArrayImplementationInterviewNo attempts yetTime limit5sMemory limit512 MBYou saw a magic trick at a show and decided to work out how it is done.
The magician lays out 16 cards in a grid of 4 rows and 4 columns. The face-up side of each card carries a different number from 1 to 16. The magician asks a volunteer to pick one card in her head, then asks which row that card is in.
The magician then lays the same 16 cards out in a 4 by 4 grid again, possibly in a different order. He asks the volunteer which row her card is in this time. From those two answers alone the magician names the chosen card.
Given both arrangements and both answers, find the card the volunteer picked. Rows are numbered 1 to 4 from top to bottom. If exactly one card matches both answers, that card is the answer. If two or more cards match, the magician laid the cards out badly. If no card matches, the volunteer lied.
The first line contains the number of test cases T.
Each test case starts with a line holding the answer to the first question. The next 4 lines hold the first arrangement, 4 integers per line separated by single spaces. The line after that holds the answer to the second question, and the following 4 lines hold the second arrangement in the same format.
Limits
For each test case, print one line in the form Case #x: y, where x is the test case number starting from 1.
If exactly one card matches both answers, y is the number on that card. If two or more cards match, y is Bad magician!. If no card matches, y is Volunteer cheated!. Both phrases must match exactly, down to the exclamation mark.