Bingo is a game in which players try to form patterns on a 5 x 5 grid (or card). Each column on the card is represented by a letter in the game's namesake: B, I, N, G, or O. Each square on the grid contains a number. Players mark numbers as they are chosen randomly until a person has a card with a winning pattern marked (or bingo). An exception to this is the center square in the grid, which is a free spot and is already marked for all players at the beginning of each game. The possible numbers called are 1-75, inclusive, with each set of fifteen numbers corresponding to a letter: B for 1-15, I for 16-30, N for 31-45, G for 46-60, and O for 61-75.
Given the amount of numbers for each letter already called and information used to determine the set of winning patterns, write a program to determine the fewest amount of numbers that still need to be called for a possible bingo.
Input to this problem will begin with a line containing a single integer n indicating the number of data sets. The first line in each data set will be in the format B I N G O X Y where:
XXOOO OOOXX OOOOO OOOOOthe set of winning patterns (of which only one must be marked to have a bingo) is:
XXOOO OOOXX OOOOO OOOOO
OOOOO OOOOO OOOOO OOOOO
OOOOO OOOOO XXOOO OOOXX
OOOOO OOOOO XXOOO OOOXX
XXOXX XXOOO XXOOO OOOXX OOOXX OOOOO
XXOXX XXOOO XXOOO OOOXX OOOXX OOOOO
OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO
OOOOO XXOOO OOOXX XXOOO OOOXX XXOXX
OOOOO XXOOO OOOXX XXOOO OOOXX XXOXX
For each data set, output a single line containing the fewest amount of numbers that still need to be called to form a bingo.
3 0 1 0 2 1 4 2 XXOOO OOOXX OOOOO OOOOO XXOOO OOOXX OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO XXOOO OOOXX OOOOO OOOOO XXOOO OOOXX 1 1 0 1 1 5 1 XXXXX OOOOO OOOOO OOOOO OOOOO OOOOO XXXXX OOOOO OOOOO OOOOO OOOOO OOOOO XXXXX OOOOO OOOOO OOOOO OOOOO OOOOO XXXXX OOOOO OOOOO OOOOO OOOOO OOOOO XXXXX 15 15 15 15 4 1 1 XXXXX XXXXX XXXXX XXXXX XXXXX
4 0 1