
2005 South Central USA Regional Programming Contest 

Introduction:
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 175, inclusive, with each set of fifteen numbers corresponding to a letter: B for 115, I for 1630, N for 3145, G for 4660, and O for 6175.
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:
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:
For example, given an X of 4, a Y of 2, and a set of input patterns as follows:
XXOOO OOOXX OOOOO OOOOO XXOOO OOOXX OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO XXOOO OOOXX OOOOO OOOOO XXOOO OOOXXthe set of winning patterns (of which only one must be marked to have a bingo) is:
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 XXOXXOutput:
For each data set, output a single line containing the fewest amount of numbers that still need to be called to form a bingo.
Sample Input:
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
Sample Output:
4 0 1