Maximum Jumps for a Checkers King

No attempts yetTime limit1sMemory limit256 MB

Problem

While playing checkers with my daughters I decided to work out which move captures the most checkers.

In checkers you may jump an opponent checker that sits diagonally next to your own checker when the next square in the same direction is empty. The jumped checker leaves the board. A checker that reaches the far side of the board is kinged, and a king moves on all four diagonals. Within one move you may keep jumping as long as the conditions hold.

You are given a checkerboard in the middle of a game. You play red at the bottom of the board against black at the top. Find the largest number of black checkers that a single red king jumps in one move, and print the position of the king that reaches that number.

The board has 8 rows and 8 columns, and row and column numbers start at 0. Each square holds one of the following four values.

  • R: a red checker
  • K: a red king
  • B: a black checker
  • a space: an empty square

The jump rules are these.

  • If the square one step from the king along some diagonal holds B and the square two steps away along the same diagonal is an empty square on the board, the king jumps that B and lands two steps away.
  • A jumped B disappears at once, so it cannot be jumped again in the same move.
  • The square the king started on becomes empty, so a later jump of the same move may land there.
  • R and K cannot be jumped. If the landing square is off the board or is not empty, the king cannot jump in that direction.
  • Only the chosen king moves during the move. The other red checkers stay where they are and block their squares.

For example, on the board in the picture below, the king at row 1 and column 3 makes one jump going down and to the right, and two jumps going down and to the left. The largest number of jumps for that king is 2.

A checkerboard

Every board has a red king with at least one jump. No two red kings reach the same largest number of jumps.

Input

The first line contains the number of checkerboards TT (1T201 \le T \le 20).

Each board follows on 8 lines. A line gives 8 squares from left to right using R, K, B, and spaces, and trailing spaces may be missing. When a line is shorter than 8 characters, the missing squares are empty.

A board holds at most 12 black checkers and at most 12 red checkers counting the kings.

Output

For each board, print on one line the row number and the column number of the red king with the largest number of jumps, followed by that largest number of jumps, separated by spaces.