Battleships is a pen and paper puzzle played on a 10×10 grid that hides ten ships. One ship covers 4 squares, two of them cover 3 squares each, three of them cover 2 squares each, and the last four cover a single square each. Every ship runs horizontally or vertically, no two ships overlap, and no two ships touch, not even at a corner. The only clues are the row sums and the column sums printed beside the grid. Each sum says how many squares of that row or that column a ship covers.
When you design a Battleships puzzle, the row and column sums have to admit exactly one solution. Sometimes the sums by themselves are enough. When they are not, the setter reveals the contents of one or more squares to rule out every solution but one.
A revealed square has one of seven types. The character in the right column is the one the output uses.
| Type | Character |
|---|---|
| water | w |
| interior of a ship | X |
| left end of a horizontal ship | < |
| top end of a vertical ship | ^ |
| right end of a horizontal ship | > |
| bottom end of a vertical ship | v |
| one square ship | O |
The last character is the capital letter O, not a zero. X is upper case while w and v are lower case. The row order of this table is also the order that ranks the types whenever the output has to choose between them.
Given the row sums and the column sums, find the smallest number of revealed squares that leaves exactly one solution. If that number is greater than 2, reject the puzzle as too ambiguous.
The first line has an integer n, the number of test cases. Each test case takes two lines: the ten row sums on the first line and the ten column sums on the second, separated by spaces. Rows are numbered 1 to 10 from top to bottom and columns are numbered 1 to 10 from left to right. Every test case has at least one solution, and no test case has more than 12000 of them.
Print one line per test case. The line starts with the word Case, a space, the case number, a colon and a space. Then print how many solutions the sums allow. Then print a space, followed by too ambiguous when the smallest number of revealed squares is greater than 2, or by that smallest number otherwise.
When the smallest number is 1 or 2, the squares follow it. Each square is preceded by a space and written as the row number, a comma and the column number inside parentheses, then =, then the character of its type. When the smallest number is 0, the line ends there.
Squares are ranked this way: a smaller row number comes first, a smaller column number breaks a tie inside the same row, and on the same square the type that appears earlier in the table above comes first. With one square, print the highest ranked square that works. With two squares, print the pair in rank order, and among all pairs that work choose the one whose first square ranks highest, breaking a tie by the second square.