Under construction

Still being built. Things may change

Magic Trick

Interview

Time limit5sMemory limit512 MB

Summary
Find the card shared by the chosen rows of two 4 by 4 layouts, or report a bad layout or cheating.
Level

Easy1 of 10

Topics
Array, Implementation
Solved
No attempts yet

Problem

You 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.

Input

The first line contains the number of test cases TT.

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

  • 1≤T≤1001 \le T \le 100
  • Both answers are between 1 and 4, inclusive.
  • Each number from 1 to 16 appears exactly once in each arrangement.

Output

For each test case, print one line in the form Case #x: y, where xx is the test case number starting from 1.

If exactly one card matches both answers, yy is the number on that card. If two or more cards match, yy is Bad magician!. If no card matches, yy is Volunteer cheated!. Both phrases must match exactly, down to the exclamation mark.

Examples6

  1. Example 1

    Input
    3
    2
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    3
    1 2 5 4
    3 11 6 15
    9 10 7 12
    13 14 8 16
    2
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    2
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    2
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    3
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    
    Expected output
    Case #1: 7
    Case #2: Bad magician!
    Case #3: Volunteer cheated!
    
  2. Example 2

    Input
    16
    1
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    1
    1 5 9 13
    2 6 10 14
    3 7 11 15
    4 8 12 16
    1
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    2
    1 5 9 13
    2 6 10 14
    3 7 11 15
    4 8 12 16
    1
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    3
    1 5 9 13
    2 6 10 14
    3 7 11 15
    4 8 12 16
    1
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    4
    1 5 9 13
    2 6 10 14
    3 7 11 15
    4 8 12 16
    2
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    1
    1 5 9 13
    2 6 10 14
    3 7 11 15
    4 8 12 16
    2
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    2
    1 5 9 13
    2 6 10 14
    3 7 11 15
    4 8 12 16
    2
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    3
    1 5 9 13
    2 6 10 14
    3 7 11 15
    4 8 12 16
    2
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    4
    1 5 9 13
    2 6 10 14
    3 7 11 15
    4 8 12 16
    3
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    1
    1 5 9 13
    2 6 10 14
    3 7 11 15
    4 8 12 16
    3
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    2
    1 5 9 13
    2 6 10 14
    3 7 11 15
    4 8 12 16
    3
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    3
    1 5 9 13
    2 6 10 14
    3 7 11 15
    4 8 12 16
    3
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    4
    1 5 9 13
    2 6 10 14
    3 7 11 15
    4 8 12 16
    4
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    1
    1 5 9 13
    2 6 10 14
    3 7 11 15
    4 8 12 16
    4
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    2
    1 5 9 13
    2 6 10 14
    3 7 11 15
    4 8 12 16
    4
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    3
    1 5 9 13
    2 6 10 14
    3 7 11 15
    4 8 12 16
    4
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    4
    1 5 9 13
    2 6 10 14
    3 7 11 15
    4 8 12 16
    
    Expected output
    Case #1: 1
    Case #2: 2
    Case #3: 3
    Case #4: 4
    Case #5: 5
    Case #6: 6
    Case #7: 7
    Case #8: 8
    Case #9: 9
    Case #10: 10
    Case #11: 11
    Case #12: 12
    Case #13: 13
    Case #14: 14
    Case #15: 15
    Case #16: 16
    
  3. Example 3

    Input
    1
    1
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    1
    1 5 9 13
    2 6 10 14
    3 7 11 15
    4 8 12 16
    
    Expected output
    Case #1: 1
    
  4. Example 4

    Input
    4
    1
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    1
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    2
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    2
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    3
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    3
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    4
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    4
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    
    Expected output
    Case #1: Bad magician!
    Case #2: Bad magician!
    Case #3: Bad magician!
    Case #4: Bad magician!
    
  5. Example 5

    Input
    4
    1
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    2
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    2
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    4
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    3
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    1
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    4
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    3
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    
    Expected output
    Case #1: Volunteer cheated!
    Case #2: Volunteer cheated!
    Case #3: Volunteer cheated!
    Case #4: Volunteer cheated!
    
  6. Example 6

    Input
    3
    1
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    1
    1 2 5 6
    3 4 7 8
    9 10 13 14
    11 12 15 16
    2
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    2
    1 2 5 6
    3 4 7 8
    9 10 13 14
    11 12 15 16
    1
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16
    4
    1 2 5 6
    3 4 7 8
    9 10 13 14
    11 12 15 16
    
    Expected output
    Case #1: Bad magician!
    Case #2: Bad magician!
    Case #3: Volunteer cheated!