#!/usr/bin/env python3

class TestCase:
    def __init__(self, first_answer, second_answer, first_grid, second_grid):
        self.first_answer = first_answer
        self.second_answer = second_answer
        self.first_grid = first_grid
        self.second_grid = second_grid
    def __repr__(self):
        return "{} {}".format(self.first_answer, self.second_answer)
    def solve(self):
        first_possible_cards = set(self.first_grid[self.first_answer - 1])
        second_possible_cards = set(self.second_grid[self.second_answer - 1])
        possible_cards = first_possible_cards.intersection(second_possible_cards)
        num_possible_cards = len(possible_cards)
        if num_possible_cards == 0: return "Volunteer cheated!"
        elif num_possible_cards == 1: return next(iter(possible_cards))
        else: return "Bad magician!"

def read_data(filename):
    with open(filename) as f:
        test_cases = []
        num_test_cases = int(f.readline())
        for _ in range(num_test_cases):
            first_answer = int(f.readline())
            first_grid = []
            for _ in range(4):
                row = [int(x) for x in f.readline().split()]
                first_grid.append(row)
            second_answer = int(f.readline())
            second_grid = []
            for _ in range(4):
                row = [int(x) for x in f.readline().split()]
                second_grid.append(row)
            test_case = TestCase(first_answer, second_answer, first_grid, second_grid)
            test_cases.append(test_case)
    return num_test_cases, test_cases

if __name__ == "__main__":
    num_test_cases, test_cases = read_data("A-small-practice.in")
    for it in range(num_test_cases):
        test_case = test_cases[it]
        print("Case #{}:".format(it + 1), test_case.solve())
@@ -17,16 +17,96 @@
 ython3%0A%0A
+%22%22%22%0AGoogle Code Jam%0AQualification Round 2014%0AProblem A. Minesweeper Master%0A%22%22%22%0A%0A
 class Te

Add docstring