#P6210. King's Visit

King's Visit

Problem Description

In chess, a king can move horizontally, vertically or diagonally to an adjacent cell in each move.
You are given an $8\times 8$ board with some obstacles. The starting position of the king is also given. Your task is to calculate the maximum number of cells that the king can visit, such that:
1.The king never moves to an obstacle.
2.Each cell are visited at most once (the starting position has already been visited at the beginning).

Input

The first line is the number of test cases. For each test case, there are $8$ lines and each line contains $8$ characters, in which the letter 'K' is the starting position, a letter 'O' is an obstacle and a '.' is an empty cell. There is an empty line after each test case.

Output

For each test case, output a line containing an integer, which is the maximum number of cells that the king can visit.

2 .O....O. O......O ........ ...K.... ........ ........ O......O .O....O.

.O....O. O...OOO. ......O. ......O. .O....O. .O....O. OOOOOO.. .......K

53 33