#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define __ELWKEL__ ios_base::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr);
#define testCase int t;cin>>t;while(t--)
#define ll long long
#define ull unsigned long long
#define all(v) ((v).begin()), ((v).end())
#define rall(v) ((v).rbegin()), ((v).rend())
#define sz(v) ((int)((v).size()))
#define INF 1000000000
#define INFLL 1000000000000000000
using namespace std;
using namespace __gnu_pbds;
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 5;
char grid[N][N];
int n ,cnt;
//Bashof el constraints
bool can(int i , int j){
    if(grid[i][j] == 'X') return false;

    bool valid = 1;
    for(int col = 0; col < j;col++){
        if(grid[i][col]=='O') valid = 0;
        else if(grid[i][col] == 'X') valid = 1;
    }
    if(!valid) return false;
    for(int col = n-1; col > j;col--){
        if(grid[i][col]=='O') valid = 0;
        else if(grid[i][col] == 'X') valid = 1;
    }
    if(!valid) return false;
    for(int row = 0 ;row < i;row++){
        if(grid[row][j]=='O') valid = 0;
        else if(grid[row][j]=='X') valid = 1;
    }
    if(!valid) return false;
    for(int row = n-1 ;row > i;row--){
        if(grid[row][j]=='O') valid = 0;
        else if(grid[row][j]=='X') valid = 1;
    }
    if(!valid) return false;
    return true;
}


void rec(int i , int j , int cur){
    if(j == n) //last cell in row .... go to next row
        return rec(i + 1 , 0 , cur) ,void();

    if(i == n) // end
        return cnt = max(cnt , cur) , void();

    if(can(i , j)){
        grid[i][j]='O';
        rec(i , j + 1, cur + 1);
        grid[i][j]='.';
    }
    rec(i , j + 1, cur);
}

void solve(){
string s ="";
    while(true){
        cin >> n;
        if(!n) break;
        cnt = 0;
        for(int i = 0 ; i< n;i++){
            for(int j = 0; j < n;j++)
                cin >> grid[i][j];
        }
        rec(0 , 0 , 0);
        cout << s<< cnt ,s = "\n";
    }
}

int32_t main() {                /*____*/ __ELWKEL__ /*____*/
//    testCase
    solve();
}