Problems
The Google Assistant and Android Auto teams are collaborating on a new prototype car that can be driven via voice commands. The early prototype works through a phone connected to a car simulator. Unfortunately, one of the early testers dropped their phone in the toilet, damaging the microphone and making it harder to use the new feature. Since they do not want to miss out on the opportunity, they want your help to use it anyway.
The early prototype moves on a simple grid of
The tester set up a driving grid such that each cell can contain either a wall, a hazard, or be empty. If a command would make the car move into a wall, or outside the grid, it does nothing instead. If a command makes the car move into a hazard, the car cannot execute any more commands.
The tester has marked some empty cells of the grid as interesting starts and others as interesting
finishes. A pair of an interesting start and an interesting finish is drivable if there is
a strategy to drive the car through voice commands from the start that makes it end at the finish
with probability at least
Input
The first line of the input gives the number of test cases,
- A period (
.) represents an uninteresting empty cell. - A hash symbol (
#) represents a cell containing a wall. - An asterisk (
*) represents a cell containing a hazard. - An English lowercase letter (
athroughz) represents an empty cell that is an interesting start. - An English uppercase letter (
AthroughZ) represents an empty cell that is an interesting finish.
Output
For each test case, output one line containing
Case #,
where NONE if there
are no drivable pairs. Otherwise,
Example
4
1 2
aZ
4 4
a..c
**.*
.Y.#
bX#Z
2 2
a*
*Z
2 7
a*bcd*.
...*F#.
Case #1: aZ
Case #2: aY bX bY cY
Case #3: NONE
Case #4: dF