Note: To advance to the next rounds, you will need to score 25 points. Solving just this problem will not give you enough points.

Problem

Recently you went to a magic show. You were very impressed by one of the tricks, so you decided to try to figure out the secret behind it!

The magician starts by arranging 16 cards in a square grid: 4 rows of cards, with 4 cards in each row. Each card has a different number from 1 to 16 written on the side that is showing. Next, the magician asks a volunteer to choose a card, and to tell him which row that card is in.

Finally, the magician arranges the 16 cards in a square grid again, possibly in a different order. Once again, he asks the volunteer which row her card is in. With only the answers to these two questions, the magician then correctly determines which card the volunteer chose. Amazing, right?

You decide to write a program to help you understand the magician's technique. The program will be given the two arrangements of the cards, and the volunteer's answers to the two questions: the row number of the selected card in the first arrangement, and the row number of the selected card in the second arrangement. The rows are numbered 1 to 4 from top to bottom.

Your program should determine which card the volunteer chose; or if there is more than one card the volunteer might have chosen (the magician did a bad job); or if there's no card consistent with the volunteer's answers (the volunteer cheated).

Solving this problem

Usually, Google Code Jam problems have 1 Small input and 1 Large input. This problem has only 1 Small input. Once you have solved the Small input, you have finished solving this problem.

Input

The first line of the input gives the number of test cases, T. T test cases follow. Each test case starts with a line containing an integer: the answer to the first question. The next 4 lines represent the first arrangement of the cards: each contains 4 integers, separated by a single space. The next line contains the answer to the second question, and the following four lines contain the second arrangement in the same format.

Output

For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1).

If there is a single card the volunteer could have chosen, y should be the number on the card. If there are multiple cards the volunteer could have chosen, y should be "Bad magician!", without the quotes. If there are no cards consistent with the volunteer's answers, y should be "Volunteer cheated!", without the quotes. The text needs to be exactly right, so consider copying/pasting it from here.

Limits

1 ≤ T ≤ 100.
1 ≤ both answers ≤ 4.
Each number from 1 to 16 will appear exactly once in each arrangement.

Sample

Input
Output

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
Case #1: 7
Case #2: Bad magician!
Case #3: Volunteer cheated!

Google Code Jam 资格赛: Problem A. Magic Trick的更多相关文章

  1. [Google Code Jam (Qualification Round 2014) ] A. Magic Trick

    Problem A. Magic Trick Small input6 points You have solved this input set.   Note: To advance to the ...

  2. Google Code Jam 2014 资格赛:Problem B. Cookie Clicker Alpha

    Introduction Cookie Clicker is a Javascript game by Orteil, where players click on a picture of a gi ...

  3. Google Code Jam Africa 2010 Qualification Round Problem B. Reverse Words

    Google Code Jam Africa 2010 Qualification Round Problem B. Reverse Words https://code.google.com/cod ...

  4. Google Code Jam Africa 2010 Qualification Round Problem A. Store Credit

    Google Code Jam Qualification Round Africa 2010 Problem A. Store Credit https://code.google.com/code ...

  5. Google Code Jam 2010 Round 1C Problem A. Rope Intranet

    Google Code Jam 2010 Round 1C Problem A. Rope Intranet https://code.google.com/codejam/contest/61910 ...

  6. [C++]Saving the Universe——Google Code Jam Qualification Round 2008

    Google Code Jam 2008 资格赛的第一题:Saving the Universe. 问题描述如下: Problem The urban legend goes that if you ...

  7. [Google Code Jam (Qualification Round 2014) ] B. Cookie Clicker Alpha

    Problem B. Cookie Clicker Alpha   Introduction Cookie Clicker is a Javascript game by Orteil, where ...

  8. [C++]Store Credit——Google Code Jam Qualification Round Africa 2010

    Google Code Jam Qualification Round Africa 2010 的第一题,很简单. Problem You receive a credit C at a local ...

  9. Google Code Jam 2014 资格赛:Problem D. Deceitful War

    This problem is the hardest problem to understand in this round. If you are new to Code Jam, you sho ...

随机推荐

  1. java trim start end space

    Java program that trims starts and ends public class Program { public static String trimEnd(String v ...

  2. OC语言基础之代码的封装

    1.封装的注意点 1: // 成员变量尽量不要用@public 2: // @public 3: int age; 1: //@public 2: // 只读(readonly):只允许外界访问我的n ...

  3. Lazy Scheduler:我的轻量级任务调度框架

    一.背景 工作中经常涉及任务调度,一直都是采用while(true) => if hitted DO => Thread.Sleep(interval)的模式.但是最近实在是感觉这种实现模 ...

  4. 写了一个远程桌面管理的Visual Studio扩展程序

    最近看了写Visual Studio扩展相关的一些资料,周末写了一个远程桌面管理器的扩展程序来练练手,由于和VisualStudio集成了,无需切换窗口,用起来还是觉得挺方便的. 关于远程桌面管理器的 ...

  5. sqlserver日志文件缩小

    原文:sqlserver日志文件缩小        最近装了个500g的固态硬盘,导入我原来的数据库后发现有60多个G的内存不见了, 最后发现我的某个数据库有60多个G的日志文件(.ldf文件)文件, ...

  6. ubi and ubifs应用手记

    转:http://blog.sina.com.cn/s/blog_5de7d9f80100dpa4.html 1.配置ubi and ubifsin .config  CONFIG_MTD_UBI=y ...

  7. Android录制视频报错setVideoSize called in a invalid state 1

    录制视频时想获取手机支持的录制视频的分辨率,使用代码如下: List<Camera.Size> videoSize = camera.getParameters().getSupporte ...

  8. jsonObject关于xml,json,bean之间的转换关系

    1.json转换为JAVA @Test public void jsonToJAVA() { System.out.println("json字符串转java代码"); Strin ...

  9. pure-ftp 服务配置篇

    FTP 是File Transfer Protocol(文件传输协议)的英文简称,而中文简称为 "文传协议" 用于Internet上的控制文件的双向传输. FTP的主要作用,就是让 ...

  10. Console-算法:fun1(do while)

    ylbtech-Arithmetic:Console-算法[do while]-XX   1.A,Demo(案例) 1.B,Solution(解决方案) using System; namespace ...