Don't Get Rooked

Time limit1sMemory limit128 MB

Problem

In chess, a rook is a piece that can move any number of squares vertically or horizontally. In this problem we consider small chess boards (at most 4×4) that may also contain walls, which rooks cannot move through. The goal is to place as many rooks on the board as possible so that no two of them can capture each other. Two rooks that lie in the same row or the same column can capture each other only if there is no wall between them; a configuration containing such a pair is illegal. If there is at least one wall between them, they cannot capture each other.

The image below shows the same board in five pictures. The first is the empty board, the second and third show legal configurations, and the fourth and fifth show illegal configurations. For this board the maximum number of rooks in a legal configuration is 5; the second picture shows one such placement, and there are several others.

Write a program that, given the description of a board, computes the maximum number of rooks that can be placed on it in a legal configuration.

Input

The input consists of one or more board descriptions, followed by a line containing the number 0 that marks the end of the input. Each board description begins with a line containing a positive integer $n$, the size of the board ($n \le 4$). The next $n$ lines each describe one row of the board, where '.' denotes an open square and an uppercase 'X' denotes a wall. There are no spaces in the input.

Output

For each board, output on its own line the maximum number of rooks that can be placed on it in a legal configuration.