Bingo (1) P97323


Statement
 

pdf   zip

html

A bingo ticket contains 15 different numbers from 1 to 99, in 3 lines in order with 5 numbers each one. The players mark the numbers of their bingo ticket at the same time as those ones are taken out from a lottery drum. It is awarded the first player that marks off all the numbers of one of the lines (“Line correct - please pay out!”) and the first player that marks off the whole bingo ticket (“House correct - please pay out!”). If there are various players that mark off a whole line or the whole bingo ticket at the same time the prize is fairly shared.

In this problem we give the order in which the 99 balls will go out of the lottery drum, and you are asked to discover which ticket will call out line, and which ticket will call out house. In particular, you must solve various similar situations: the order of the ball will be always the same, but in each situation will only be a certain subset of tickets.

Input

The input consists of a line with the number k of tickets, with 1≤ k ≤ 100. Afterwards, and separated by lines in white, the k tickets are given. The 15 numbers of each ticket are given separated by spaces and distributed in 3 lines of 5 numbers.

A line with the number q of different situations follows, with 1≤ q≤ 1000. A situation is a subset of n of the k ticktets that are played. Each situation is described by the number n (between 1 and k), two spaces of separation, and the indices of the n tickets that are played, all of them different, between 1 and k, in the same line and separated by spaces.

Finally, separated by a line in white, the 99 numbers of the lottery drum are given in the order that they go out, separated by spaces and changing of line every 10 numbers.

Output

Your program must print q lines, one per situation. Each line contains two numbers separated by a space: the index of the ticket that obtains the line, and the index of the ticket that obtains the house. In case of being more than one awarded, it must print a 0 in the corresponding place.

Public test cases
  • Input

    5
    
    1 2 3 4 97
    5 6 7 8 98
    9 10 11 12 99
    
    1 2 3 4 97
    6 7 8 15 98
    9 10 11 12 99
    
    1 2 3 4 97
    6 7 8 25 98
    9 10 11 12 99
    
    1 2 3 4 97
    6 7 8 35 98
    9 10 11 12 99
    
    1 2 3 4 97
    6 7 8 45 98
    9 10 11 12 99
    
    5
    1  1
    2  1 2
    5  1 2 3 4 5
    3  1 2 3
    4  1 2 3 4
    
    1 2 3 4 5 6 7 8 9 10
    11 12 13 14 15 16 17 18 19 20
    21 22 23 24 25 26 27 28 29 30
    31 32 33 34 35 36 37 38 39 40
    41 42 43 44 45 46 47 48 49 50
    51 52 53 54 55 56 57 58 59 60
    61 62 63 64 65 66 67 68 69 70
    71 72 73 74 75 76 77 78 79 80
    81 82 83 84 85 86 87 88 89 90
    91 92 93 94 95 96 97 98 99
    

    Output

    1 1
    0 0
    0 0
    0 0
    0 0
    
  • Input

    5
    
    3 18 35 61 68
    4 24 41 64 75
    12 30 49 66 82
    
    24 35 60 82 93
    29 39 65 86 97
    34 48 66 87 99
    
    7 31 38 68 83
    12 33 46 75 87
    23 34 57 79 97
    
    11 19 45 51 74
    15 23 49 55 94
    16 42 50 66 99
    
    2 17 28 46 66
    7 19 37 49 83
    16 23 39 64 96
    
    7
    1  3
    2  5 4
    3  3 1 2
    2  4 3
    4  3 5 4 1
    5  1 2 3 4 5
    4  1 4 2 3
    
    6 48 97 8 19 66 49 42 95 11
    93 51 79 40 7 47 80 26 37 44
    86 89 25 72 17 31 15 58 76 57
    46 5 61 62 1 4 23 30 55 2
    9 90 64 56 12 91 24 45 21 39
    99 75 83 32 29 78 59 16 22 13
    94 84 77 27 33 85 81 53 69 60
    28 68 67 73 87 70 35 10 43 52
    63 36 65 38 3 14 50 92 34 96
    18 20 71 74 54 41 88 98 82 
    

    Output

    3 3
    5 5
    3 3
    4 3
    5 3
    5 3
    4 3
    
  • Information
    Author
    Omer Giménez
    Language
    English
    Translator
    Carlos Molina
    Original language
    Spanish
    Other languages
    Spanish
    Official solutions
    C++
    User solutions
    C++