#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();
}
I2RlZmlu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BuKSAvLyBlbmQKICAgICAgICByZXR1cm4gY250ID0gbWF4KGNudCAsIGN1cikgLCB2b2lkKCk7CgogICAgaWYoY2FuKGkgLCBqKSl7CiAgICAgICAgZ3JpZFtpXVtqXT0nTyc7CiAgICAgICAgcmVjKGkgLCBqICsgMSwgY3VyICsgMSk7CiAgICAgICAgZ3JpZFtpXVtqXT0nLic7CiAgICB9CiAgICByZWMoaSAsIGogKyAxLCBjdXIpOwp9Cgp2b2lkIHNvbHZlKCl7CnN0cmluZyBzID0iIjsKICAgIHdoaWxlKHRydWUpewogICAgICAgIGNpbiA+PiBuOwogICAgICAgIGlmKCFuKSBicmVhazsKICAgICAgICBjbnQgPSAwOwogICAgICAgIGZvcihpbnQgaSA9IDAgOyBpPCBuO2krKyl7CiAgICAgICAgICAgIGZvcihpbnQgaiA9IDA7IGogPCBuO2orKykKICAgICAgICAgICAgICAgIGNpbiA+PiBncmlkW2ldW2pdOwogICAgICAgIH0KICAgICAgICByZWMoMCAsIDAgLCAwKTsKICAgICAgICBjb3V0IDw8IHM8PCBjbnQgLHMgPSAiXG4iOwogICAgfQp9CgppbnQzMl90IG1haW4oKSB7ICAgICAgICAgICAgICAgIC8qX19fXyovIF9fRUxXS0VMX18gLypfX19fKi8KLy8gICAgdGVzdENhc2UKICAgIHNvbHZlKCk7Cn0=