Stampede!

No attempts yetTime limit5sMemory limit128 MB

Problem

You have an n×nn \times n game board. Some squares contain obstacles, but the left-most and right-most columns never do. The left-most column holds your nn pieces, one per row. Your goal is to move every piece to the right-most column as quickly as possible.

In one turn you can move each piece one square north, south, east, or west, or leave that piece where it is. A piece cannot move onto a square that contains an obstacle, and two pieces cannot move onto the same square on the same turn. All pieces move at the same time, so a piece may move onto a square another piece currently occupies as long as that other piece leaves the square on the same turn.

Given nn and the obstacles, determine the fewest number of turns needed to get every piece to the right-most column of the board.

Input

The input holds several test cases. Each test case starts with a positive integer nn, the size of the game board, with n25n \le 25. The next nn lines contain nn characters each. If the jjth character of the iith line is X, square (i,j)(i, j) contains an obstacle; a . means the square is free. Rows and columns are numbered from 0.

Column 0 and column n1n-1 never contain an obstacle, and there is always at least one obstacle-free path between those two columns.

A line holding a single 0 ends the input.

Output

For each test case print one line in the form Case i: t, where i is the test case number starting at 1 and t is the fewest turns needed to move every piece from the left-most column to the right-most column.