import java.util.Scanner;
/**
* Created by m1786 on 2017/4/2.
*/
public class 碉堡问题 {
static char a[][]=new char [4 ][4 ];
static String s[]=new String[4 ];
static int iBest=0 ;
static int n;
public static void main (String args[]){
Scanner sc=new Scanner(System.in);
while (true ){
n=sc.nextInt();
if (n==0 ){
return ;
}
sc.nextLine();
for (int i=0 ;i<n;i++){
s[i]=sc.nextLine();
}
for (int i=0 ;i<n;i++)
for (int j=0 ;j<n;j++){
a[i][j]=s[i].charAt(j);
}
dfs(0 ,0 );
System.out.println(iBest);
}
}
static boolean canPlace(int m,int n){
for (int i=n-1 ;i>=0 ;i--){
if (a[m][i]=='O' )
return false ;
if (a[m][i]=='X' )
break ;
}
for (int i=m-1 ;i>=0 ;i--){
if (a[i][n]=='O' )
return false ;
if (a[i][n]=='X' )
break ;
}
return true ;
}
static void dfs(int t,int current){
int x;int y;
if (t==n*n){
if (current>iBest){
iBest=current;
return ;
}
}
else {
x=t/n;
y=t%n;
if (a[x][y]=='.' &&canPlace(x,y)){
a[x][y]='O' ;
dfs(t+1 ,current+1 );
a[x][y]='.' ;
}
dfs(t+1 ,current);
}
}
}