/*
 *   backtracking using list of empty squares
 */
#include <iostream>
#include <iomanip>
#include <time.h>
using namespace std;

const int SIZE = 8;

char board[SIZE][SIZE];
bool visited[SIZE][SIZE];

struct sq {
	int r, c;
} sqs[SIZE*SIZE];
int nempty;

struct move {
	int i, j;
	int s;
};

int start, debugstop;		// temporary
void printBoard(int n)
{
	for(int i=0; i<n; i++) {
		for(int j=0; j<n; j++)
			cout << board[i][j];
		cout << endl;
	}
}

int connect(int n, int i, int j, char side)
{
	int c = 0;
	visited[i][j] = true;
	if (board[i][j] == side) {
		c=1;
		if (i>0 && !visited[i-1][j])
			c += connect(n, i-1, j, side);
		if (i<n-1 && !visited[i+1][j])
			c += connect(n, i+1, j, side);
		if (j>0 && !visited[i][j-1])
			c += connect(n, i, j-1, side);
		if (j<n-1 && !visited[i][j+1])
			c += connect(n, i, j+1, side);
	}
	return c;
}
	
int maxConnected(int n, char side)
{
	int i, j;
	for(i=0; i<n; i++)
		for(j=0; j<n; j++)
			visited[i][j] = false;
	int best = 0;
	for(i=0; i<n; i++)
		for(j=0; j<n; j++) {
			if (board[i][j] == side && !visited[i][j]) {
				int temp = connect(n, i, j, side);
				if (temp > best)
					best = temp;
			}
		}
	return best;
}

int score(int n)
{
	int c0 = maxConnected(n, '0');
	int c1 = maxConnected(n, '1');
	return c0-c1;
}

move minimax(int n, int cnt, int alpha, int beta);

move maximin(int n, int cnt, int alpha, int beta)
{
	move best;
	int mybeta = beta;
	if (cnt == n*n) {
		best.s = score(n);
		return best;
	}
	best.s = n*n;
	for(int k=0; k<nempty; k++) {
		int i=sqs[k].r;
		int j=sqs[k].c;
		if (board[i][j] == '.') {
			board[i][j] = '1';
			move s = minimax(n, cnt+1, alpha, mybeta);
			board[i][j] = '.';
			if (s.s <= alpha)
				return s;
			else if (s.s < best.s) {
				best.s = s.s;
				if (best.s < mybeta)
					mybeta = best.s;
				best.i = i;
				best.j = j;
			}
		}
	}
	return best;
}

move minimax(int n, int cnt, int alpha, int beta)
{
	move best;
	int myalpha = alpha;
	if (cnt == n*n) {
		best.s = score(n);
		return best;
	}
	best.s = -n*n;
	for(int k=0; k<nempty; k++) {
		int i=sqs[k].r;
		int j=sqs[k].c;
		if (board[i][j] == '.') {
			board[i][j] = '0';
			move s = maximin(n, cnt+1, myalpha, beta);
			board[i][j] = '.';
			if (s.s >= beta) {
				return s;
			}
			else if (s.s > best.s) {
				best.s = s.s;
				if (best.s > myalpha)
					myalpha = best.s;
				best.i = i;
				best.j = j;
			}
		}
	}
	return best;
}

int main()
{
	int i, j, n;
	cin >> n;
	while (n != 0) {
		int start = 0;
		nempty = 0;
		for(i=0; i<n; i++)
			for(j=0; j<n; j++) {
				cin >> board[i][j];
				if (board[i][j] != '.')
					start++;
				else {
					sqs[nempty].r = i;
					sqs[nempty].c = j;
					nempty++;
				}
			}
		move mv;
		if (start%2 == 0)
			mv = minimax(n, start, -n*n-1, n*n+1);
		else {
			mv = maximin(n, start, -n*n-1, n*n+1);
			mv.s = -mv.s;
		}
		cout << '(' << mv.i << ',' << mv.j << ") " << mv.s << endl;
		cin >> n;
	}
	return 0;
}
