#P2006. ACSL 2015-2016 Intermediate Division Contest #3 ACSL ABC

ACSL 2015-2016 Intermediate Division Contest #3 ACSL ABC

Easy as ABC is a puzzle game by Wei-Hwa Huang. In the puzzle the given letters are placed in the grid so that each letter appears just once in each row and column. Further, letters are given outside the grid. These letters tell that that letter will be the first found in that row or column starting from that direction. In addition some cells in the puzzle will be filled () at the start of the game. The game is played on a 4 x 4 grid. The grid uses cells 8 – 11, 14 – 17, 20 – 23 and 26 – 29. The other cells are used to place first found letters. The outside A in Grid #2 is at location #7. Cells 1, 6, 31 and 36 are not used.

INPUT FORMAT

There will be 5 lines of input. Each line will contain the location number of 4 filled cells. That will be followed by the number of first found letters given and their value and location. That will be followed by a cell location. The input data for Grid #2 is given in Sample Input #1.

OUTPUT FORMAT

For each input line print the letter that correctly fills the given cell location. In Sample Input #1, cells 9, 18, 22 and 26 are filled. 4 first found letters and locations are given. The last location on the line, 14, is the cell to be filled by the correct letter.

SAMPLE

INPUT

9, 17, 22, 26, 4, A, 7, C, 18, C, 19, C, 32, 14
11,16, 20, 27, 4, A, 7, B, 19, A, 24, B 30, 22
9, 14, 23, 28, 3, B, 7, A, 19, A, 30, 10
8, 15, 23, 28, 4, A, 7, C, 24, C, 33, A, 30, 20
9, 16, 23, 26, 4, A, 7, B, 19, B, 25, B, 18, 15

OUTPUT

B
C
A
A
A