King Game

On a small board with burned squares, two players alternately move a king to an unvisited neighboring square; report who wins under optimal play.

Hard9Game theoryGraphDFSBacktrackingNo attempts yetTime limit5sMemory limit512 MB

Problem

Alice and Bob play a game on a chessboard with RR rows and CC columns, so RCRC squares in total. Some of the squares are burned.

A king is placed on an unburned square, and Alice and Bob move it one step at a time, taking turns.

On a turn the player must move the king to one of the 8 squares next to its current square, subject to two conditions:

  • the destination square must not be burned;
  • the king must never have entered that square before. The starting square already counts as entered.

A player who cannot move the king on their turn loses. Alice moves first. Determine who wins when both players play optimally.

Input

The first line contains the number of test cases, NN.

NN test cases follow. The first line of each case contains two integers RR and CC. The next RR lines each contain a string of length CC that describes the CC squares of one row. Each string uses only the characters ., # and K.

  • # is a burned square.
  • . is a square that is unburned and unoccupied.
  • K is the square the king starts on. That square is unburned.

Each test case contains exactly one K.

Output

For each test case, print one line: Case #X: followed by A if Alice wins or B if Bob wins. Here XX is the case number, starting from 1.

Constraints

  • 1N1001 \le N \le 100
  • 1R,C151 \le R, C \le 15