Pink Floyd are pulling a prank on Roger Waters. They know he doesn't like walls, he wants to be able to walk freely, so they are blocking him from exiting his room which can be seen as a grid.

Roger Waters has a square grid of size $n\times n$ and he wants to traverse his grid from the upper left ($1,1$) corner to the lower right corner ($n,n$). Waters can move from a square to any other square adjacent by a side, as long as he is still in the grid. Also except for the cells ($1,1$) and ($n,n$) every cell has a value $0$ or $1$ in it.

Before starting his traversal he will pick either a $0$ or a $1$ and will be able to only go to cells values in which are equal to the digit he chose. The starting and finishing cells ($1,1$) and ($n,n$) are exempt from this rule, he may go through them regardless of picked digit. Because of this the cell ($1,1$) takes value the letter 'S' and the cell ($n,n$) takes value the letter 'F'.

For example, in the first example test case, he can go from ($1, 1$) to ($n, n$) by using the zeroes on this path: ($1, 1$), ($2, 1$), ($2, 2$), ($2, 3$), ($3, 3$), ($3, 4$), ($4, 4$)

The rest of the band (Pink Floyd) wants Waters to not be able to do his traversal, so while he is not looking they will invert at most two cells in the grid (from $0$ to $1$ or vice versa). They are afraid they will not be quick enough and asked for your help in choosing the cells.  Note that you cannot invert cells $(1, 1)$ and $(n, n)$.

We can show that there always exists a solution for the given constraints.

Also note that Waters will pick his digit of the traversal after the band has changed his grid, so he must not be able to reach ($n,n$) no matter what digit he picks.


-----Input-----

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 50$). Description of the test cases follows.

The first line of each test case contains one integers $n$ ($3 \le n \le 200$).

The following $n$ lines of each test case contain the binary grid, square ($1, 1$) being colored in 'S' and square ($n, n$) being colored in 'F'.

The sum of values of $n$ doesn't exceed $200$.


-----Output-----

For each test case output on the first line an integer $c$ ($0 \le c \le 2$)  — the number of inverted cells.

In $i$-th of the following $c$ lines, print the coordinates of the $i$-th cell you inverted. You may not invert the same cell twice.  Note that you cannot invert cells $(1, 1)$ and $(n, n)$.


-----Example-----
Input
3
4
S010
0001
1000
111F
3
S10
101
01F
5
S0101
00000
01111
11111
0001F

Output
1
3 4
2
1 2
2 1
0



-----Note-----

For the first test case, after inverting the cell, we get the following grid:



S010

0001

1001

111F

Difficulty: EASY
Tags: Implementation

Constructive algorithms

Starter code:

Solutions:
for _ in range(int(input())):
	n = int(input())
	a = list()
	for i in range(n):
		s = input()
		a.append(s)
	i = int(a[0][1])
	j = int(a[1][0])
	c1 = int(a[0][2])
	c2 = int(a[1][1])
	c3 = int(a[2][0])
	r = []
	if i == j:
		if i == 0:
			if c1 == c2 == c3 == 0:
				r.append((1, 2))
				r.append((2, 1))
			else:
				if c1 == 0:
					r.append((1, 3))
				if c2 == 0:
					r.append((2, 2))
				if c3 == 0:
					r.append((3, 1))
		elif c1 == c2 == c3 == 1:
			r.append((1, 2))
			r.append((2, 1))
		else:
			if c1 == 1:
				r.append((1, 3))
			if c2 == 1:
				r.append((2, 2))
			if c3 == 1:
				r.append((3, 1))
	elif i == 1:
		if c1 == c2 == c3:
			if c1 == 1:
				r.append((1, 2))
			else:
				r.append((2, 1))
		elif c1 + c2 + c3 == 1:
			r.append((2, 1))
			if c1 == 1:
				r.append((1, 3))
			elif c2 == 1:
				r.append((2, 2))
			elif c3 == 1:
				r.append((3, 1))
		else:
			r.append((1, 2))
			if c1 == 0:
				r.append((1, 3))
			elif c2 == 0:
				r.append((2, 2))
			elif c3 == 0:
				r.append((3, 1))
	elif c1 == c2 == c3:
		if c1 == 1:
			r.append((2, 1))
		else:
			r.append((1, 2))
	elif c1 + c2 + c3 == 1:
		r.append((1, 2))
		if c1 == 1:
			r.append((1, 3))
		elif c2 == 1:
			r.append((2, 2))
		elif c3 == 1:
			r.append((3, 1))
	else:
		r.append((2, 1))
		if c1 == 0:
			r.append((1, 3))
		elif c2 == 0:
			r.append((2, 2))
		elif c3 == 0:
			r.append((3, 1))
	print(len(r))
	for i in r:
		print(*i)


def solve(n, grid):
	pos = []
	if grid[0][1] == grid[1][0]:
		if grid[n - 1][n - 2] == grid[0][1]:
			pos.append((n - 1, n - 2))
		if grid[n - 2][n - 1] == grid[0][1]:
			pos.append((n - 2, n - 1))
	elif grid[n - 1][n - 2] == grid[n - 2][n - 1]:
		if grid[0][1] == grid[n - 1][n - 2]:
			pos.append((0, 1))
		if grid[1][0] == grid[n - 1][n - 2]:
			pos.append((1, 0))
	elif grid[0][1] == grid[n - 2][n - 1] and grid[1][0] == grid[n - 1][n - 2]:
		pos.append((0, 1))
		pos.append((n - 1, n - 2))
	else:
		dx = [-1, 0, 1, 0]
		dy = [0, 1, 0, -1]

		def is_valid(x, y, visited):
			if x == 0 and y == 0:
				return True
			elif x < 0 or y < 0 or x >= n or (y >= n):
				return False
			for _ in range(4):
				(nx, ny) = (x + dx[_], y + dy[_])
				if (nx, ny) in visited:
					continue
				if not (0 <= nx < n and 0 <= ny < n):
					continue
				if nx == 0 and ny == 0:
					return True
				if grid[x][y] != grid[nx][ny]:
					continue
				visited.add((nx, ny))
				if is_valid(nx, ny, visited):
					return True
				visited.discard((nx, ny))
			return False
		if is_valid(n - 1, n - 2, set()):
			pos.append((n - 1, n - 2))
			pos.append((1, 0))
		if is_valid(n - 2, n - 1, set()):
			pos.append((n - 2, n - 1))
			pos.append((0, 1))
	res = []
	for (x, y) in pos:
		res.append((x + 1, y + 1))
	return res
t = int(input())
for _ in range(t):
	n = int(input())
	g = [input() for _ in range(n)]
	pos = solve(n, g)
	if not pos:
		print(0)
	else:
		print(len(pos))
		print('\n'.join(('{} {}'.format(_[0], _[1]) for _ in pos)))


import sys, io, os
BUFSIZE = 8192

class FastIO(io.IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = io.BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(io.IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
T = int(input())
for _ in range(T):
	N = int(input())
	S = [input() for _ in range(N)]
	Ans1 = []
	Ans2 = []
	if S[0][1] == '1':
		Ans1.append((1, 2))
	else:
		Ans2.append((1, 2))
	if S[1][0] == '1':
		Ans1.append((2, 1))
	else:
		Ans2.append((2, 1))
	if S[-2][-1] == '0':
		Ans1.append((N - 1, N))
	else:
		Ans2.append((N - 1, N))
	if S[-1][-2] == '0':
		Ans1.append((N, N - 1))
	else:
		Ans2.append((N, N - 1))
	if len(Ans1) <= 2:
		Ans = Ans1
	else:
		Ans = Ans2
	print(len(Ans))
	for (a, b) in Ans:
		print(a, b)


import os, sys
from io import IOBase, BytesIO
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def get_input(a=str):
	return a(input())

def get_int_input():
	return get_input(int)

def get_input_arr(a):
	return list(map(a, input().split()))

def get_int_input_arr():
	return get_input_arr(int)

def solve():
	t = get_int_input()
	for _ in range(t):
		n = get_int_input()
		grid = []
		for i in range(n):
			grid.append(get_input())
		if grid[0][1] == grid[1][0] and grid[-2][-1] == grid[-1][-2] and (grid[-1][-2] != grid[0][1]):
			cout << 0 << endl
		elif grid[0][1] == grid[1][0] and grid[-2][-1] == grid[-1][-2] and (grid[-1][-2] == grid[0][1]):
			cout << 2 << endl
			cout << 1 << ' ' << 2 << endl
			cout << 2 << ' ' << 1 << endl
		elif grid[0][1] != grid[1][0] and grid[-2][-1] == grid[-1][-2]:
			if grid[1][0] == grid[-2][-1]:
				cout << 1 << endl
				cout << 2 << ' ' << 1 << endl
			elif grid[0][1] == grid[-2][-1]:
				cout << 1 << endl
				cout << 1 << ' ' << 2 << endl
		elif grid[0][1] == grid[1][0] and grid[-2][-1] != grid[-1][-2]:
			if grid[1][0] == grid[-2][-1]:
				cout << 1 << endl
				cout << n - 1 << ' ' << n << endl
			elif grid[0][1] == grid[-1][-2]:
				cout << 1 << endl
				cout << n << ' ' << n - 1 << endl
		elif grid[0][1] != grid[1][0] and grid[-2][-1] != grid[-1][-2]:
			if grid[0][1] == grid[-2][-1]:
				cout << 2 << endl
				cout << 1 << ' ' << 2 << endl
				cout << n << ' ' << n - 1 << endl
			if grid[0][1] == grid[-1][-2]:
				cout << 2 << endl
				cout << 1 << ' ' << 2 << endl
				cout << n - 1 << ' ' << n << endl

def main():
	solve()
main()


t = int(input())
for i in range(t):
	list1 = []
	n = int(input())
	for j in range(n):
		list1.append(input())
	s_right = list1[0][1]
	s_down = list1[1][0]
	f_left = list1[-1][-2]
	f_up = list1[-2][-1]
	if s_right == s_down and f_left == f_up:
		if s_right != f_left:
			print(0)
		else:
			print(2)
			print(n - 1, ' ', n)
			print(n, ' ', n - 1)
	elif s_right != s_down and f_left == f_up:
		if s_right == f_left:
			print(1)
			print(1, ' ', 2)
		elif s_down == f_left:
			print(1)
			print(2, ' ', 1)
	elif s_right == s_down and f_left != f_up:
		if s_right == f_left:
			print(1)
			print(n, ' ', n - 1)
		elif s_down == f_up:
			print(1)
			print(n - 1, ' ', n)
	else:
		print(2)
		if s_right == f_up:
			print(1, ' ', 2)
			print(n, ' ', n - 1)
		elif s_right == f_left:
			print(1, ' ', 2)
			print(n - 1, ' ', n)


for _ in range(int(input())):
	n = int(input())
	arr = []
	for i in range(n):
		arr.append(input())
	a = int(arr[0][1])
	b = int(arr[1][0])
	c = int(arr[n - 1][n - 2])
	d = int(arr[n - 2][n - 1])
	if a == b and c == d and (c != a):
		print(0)
	elif a == b and c != d:
		if c == a:
			print(1)
			print(n, n - 1)
		else:
			print(1)
			print(n - 1, n)
	elif a != b and c == d:
		print(1)
		if c == a:
			print(1, 2)
		else:
			print(2, 1)
	elif a == b and c == d:
		print(2)
		print(1, 2)
		print(2, 1)
	elif a != b and c != d:
		print(2)
		if a != c:
			print(1, 2)
			print(n, n - 1)
		elif a != d:
			print(1, 2)
			print(n - 1, n)


import math

def solve():
	s = []
	n = int(input())
	for i in range(n):
		s.append(input())
	(p, q, r, s) = (s[0][1], s[1][0], s[n - 2][n - 1], s[n - 1][n - 2])
	x = ''.join(sorted(p + q))
	y = ''.join(sorted(r + s))
	if x == '00' and y == '11' or (x == '11' and y == '00'):
		print(0)
	elif x == '00' and y == '00' or (x == '11' and y == '11'):
		print(2)
		print(n - 1, n)
		print(n, n - 1)
	elif x == '01' and y == '01':
		print(2)
		if p == '0':
			print('1 2')
		else:
			print('2 1')
		if r == '1':
			print(n - 1, n)
		else:
			print(n, n - 1)
	elif x == '00' and y == '01':
		print(1)
		if r == '0':
			print(n - 1, n)
		else:
			print(n, n - 1)
	elif x == '01' and y == '00':
		print(1)
		if p == '0':
			print('1 2')
		else:
			print('2 1')
	elif x == '01' and y == '11':
		print(1)
		if p == '1':
			print('1 2')
		else:
			print('2 1')
	elif x == '11' and y == '01':
		print(1)
		if r == '1':
			print(n - 1, n)
		else:
			print(n, n - 1)
	else:
		print(0)
for z in range(int(input())):
	solve()


for _ in range(int(input())):
	n = int(input())
	mat = []
	for i in range(n):
		mat.append(input())
	d = [(1, 2), (2, 1), (n - 1, n), (n, n - 1)]
	items = [int(mat[0][1]), int(mat[1][0]), int(mat[-2][-1]), int(mat[-1][-2])]
	ans = []
	if items[:2] == [0, 0] or items[2:] == [1, 1]:
		for i in range(4):
			if i < 2 and items[i]:
				ans.append(d[i])
			elif i > 1 and (not items[i]):
				ans.append(d[i])
	else:
		for i in range(4):
			if i > 1 and items[i]:
				ans.append(d[i])
			elif i < 2 and (not items[i]):
				ans.append(d[i])
	print(len(ans))
	for i in ans:
		print(*i)


for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		a.append(list(input()))
	c = 0
	s = []
	if a[0][1] == a[1][0] and a[n - 1][n - 2] == a[n - 2][n - 1]:
		if a[0][1] != a[n - 1][n - 2]:
			print(0)
		else:
			print(2)
			print('1 2')
			print('2 1')
	elif a[0][1] == a[1][0] and a[n - 1][n - 2] != a[n - 2][n - 1]:
		if a[n - 1][n - 2] == a[0][1]:
			print(1)
			print(f'{n} {n - 1}')
		else:
			print(1)
			print(f'{n - 1} {n}')
	elif a[0][1] != a[1][0] and a[n - 1][n - 2] == a[n - 2][n - 1]:
		if a[n - 1][n - 2] == a[0][1]:
			print(1)
			print('1 2')
		else:
			print(1)
			print('2 1')
	else:
		print(2)
		if a[0][1] == '0':
			print('2 1')
		else:
			print('1 2')
		if a[n - 1][n - 2] == '1':
			print(f'{n - 1} {n}')
		else:
			print(f'{n} {n - 1}')


T = int(input())
M = [[0 for i in range(300)] for j in range(300)]
for t in range(T):
	n = int(input())
	for i in range(n):
		a = input()
		for j in range(n):
			if a[j] != 'S' and a[j] != 'F':
				M[i][j] = int(a[j])
	res1 = []
	res0 = []
	if M[0][1] == 1:
		res0.append((1, 2))
	else:
		res1.append((1, 2))
	if M[1][0] == 1:
		res0.append((2, 1))
	else:
		res1.append((2, 1))
	if M[n - 1][n - 2] == 1:
		res1.append((n, n - 1))
	else:
		res0.append((n, n - 1))
	if M[n - 2][n - 1] == 1:
		res1.append((n - 1, n))
	else:
		res0.append((n - 1, n))
	if len(res1) <= 2:
		print(len(res1))
		for (a, b) in res1:
			print(a, b)
	else:
		print(len(res0))
		for (a, b) in res0:
			print(a, b)


(T,) = map(int, input().split())
for _ in range(T):
	(N,) = map(int, input().split())
	X = []
	for _ in range(N):
		X.append(input().strip())
	(a, b) = (int(X[0][1]), int(X[1][0]))
	(c, d) = (int(X[-1][-2]), int(X[-2][-1]))
	if (a, b, c, d) == (1, 1, 0, 0):
		print(0)
	if (a, b, c, d) == (0, 0, 1, 1):
		print(0)
	if (a, b, c, d) == (0, 0, 0, 0):
		print(2)
		print(1, 2)
		print(2, 1)
	if (a, b, c, d) == (1, 1, 1, 1):
		print(2)
		print(1, 2)
		print(2, 1)
	if (a, b, c, d) == (0, 1, 0, 1):
		print(2)
		print(1, 2)
		print(N - 1, N)
	if (a, b, c, d) == (1, 0, 1, 0):
		print(2)
		print(1, 2)
		print(N - 1, N)
	if (a, b, c, d) == (1, 0, 0, 1):
		print(2)
		print(1, 2)
		print(N, N - 1)
	if (a, b, c, d) == (0, 1, 1, 0):
		print(2)
		print(1, 2)
		print(N, N - 1)
	if (a, b, c, d) == (0, 0, 0, 1):
		print(1)
		print(N, N - 1)
	if (a, b, c, d) == (1, 1, 1, 0):
		print(1)
		print(N, N - 1)
	if (a, b, c, d) == (0, 0, 1, 0):
		print(1)
		print(N - 1, N)
	if (a, b, c, d) == (1, 1, 0, 1):
		print(1)
		print(N - 1, N)
	if (a, b, c, d) == (0, 1, 0, 0):
		print(1)
		print(1, 2)
	if (a, b, c, d) == (1, 0, 1, 1):
		print(1)
		print(1, 2)
	if (a, b, c, d) == (1, 0, 0, 0):
		print(1)
		print(2, 1)
	if (a, b, c, d) == (0, 1, 1, 1):
		print(1)
		print(2, 1)


def getInverts(arr, N):
	inverts = []
	if arr[0][1] == arr[1][0]:
		if arr[-1][-2] == arr[0][1]:
			inverts.append([N - 1, N - 2])
		if arr[-2][-1] == arr[0][1]:
			inverts.append([N - 2, N - 1])
	elif arr[-1][-2] == arr[-2][-1]:
		if arr[0][1] == arr[-1][-2]:
			inverts.append([0, 1])
		else:
			inverts.append([1, 0])
	elif arr[0][1] == arr[-1][-2]:
		inverts.append([0, 1])
		inverts.append([N - 2, N - 1])
	else:
		inverts.append([1, 0])
		inverts.append([N - 2, N - 1])
	return inverts
T = int(input())
for t in range(T):
	N = int(input())
	arr = []
	for n in range(N):
		arr.append(list(input()))
	inverts = getInverts(arr, N)
	print(len(inverts))
	for i in inverts:
		print(i[0] + 1, i[1] + 1)


import sys
input = sys.stdin.readline

def main():
	n = int(input())
	maze = [input().strip() for _ in range(n)]
	ans = []
	if maze[0][1] == '0':
		ans.append((1, 2))
	if maze[1][0] == '0':
		ans.append((2, 1))
	if maze[n - 1][n - 2] == '1':
		ans.append((n, n - 1))
	if maze[n - 2][n - 1] == '1':
		ans.append((n - 1, n))
	if len(ans) <= 2:
		print(len(ans))
		for row in ans:
			print(*row)
		return
	ans = []
	if maze[0][1] == '1':
		ans.append((1, 2))
	if maze[1][0] == '1':
		ans.append((2, 1))
	if maze[n - 1][n - 2] == '0':
		ans.append((n, n - 1))
	if maze[n - 2][n - 1] == '0':
		ans.append((n - 1, n))
	if len(ans) <= 2:
		print(len(ans))
		for row in ans:
			print(*row)
for _ in range(int(input())):
	main()


for _ in range(int(input())):
	n = int(input())
	G = []
	for a in range(n):
		G.append(input())
	a1 = int(G[0][1])
	a2 = int(G[1][0])
	b1 = int(G[-2][-1])
	b2 = int(G[-1][-2])
	if a1 == 0 and a2 == 0:
		if b1 == 1:
			if b2 == 1:
				print(0)
			else:
				print(1)
				print(n, n - 1)
		elif b2 == 1:
			print(1)
			print(n - 1, n)
		else:
			print(2)
			print(n, n - 1)
			print(n - 1, n)
	elif b1 == 0 and b2 == 0:
		if a1 == 1:
			if a2 == 1:
				print(0)
			else:
				print(1)
				print(2, 1)
		elif a2 == 1:
			print(1)
			print(1, 2)
		else:
			print(2)
			print(1, 2)
			print(2, 1)
	elif a1 == 1 and a2 == 1:
		if b1 == 0:
			if b2 == 0:
				print(0)
			else:
				print(1)
				print(n, n - 1)
		elif b2 == 0:
			print(1)
			print(n - 1, n)
		else:
			print(2)
			print(n, n - 1)
			print(n - 1, n)
	elif b1 == 1 and b2 == 1:
		if a1 == 0:
			if a2 == 0:
				print(0)
			else:
				print(1)
				print(2, 1)
		elif a2 == 0:
			print(1)
			print(1, 2)
		else:
			print(2)
			print(1, 2)
			print(2, 1)
	else:
		print(2)
		if a1 == 0:
			print(2, 1)
		else:
			print(1, 2)
		if b1 == 0:
			print(n - 1, n)
		else:
			print(n, n - 1)


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(t,) = I()
for _ in range(t):
	(n,) = I()
	l = [input().strip() for i in range(n)]
	an = []
	le = [0, 0, 1, 1, 1]
	p = [1, 1, 0, 0, 0]
	rq = [l[0][1], l[1][0], l[1][1], l[2][0], l[0][2]]
	pos = [[1, 2], [2, 1], [2, 2], [3, 1], [1, 3]]
	ct = cp = 0
	a1 = []
	for i in range(5):
		if le[i] != int(rq[i]):
			ct += 1
			a1.append(pos[i])
	for i in range(5):
		if p[i] != int(rq[i]):
			cp += 1
			an.append(pos[i])
	if ct <= cp:
		an = a1
	print(len(an))
	for i in an:
		print(*i)


def find_invert_positions(m):
	n = len(m)
	a = m[0][1]
	b = m[1][0]
	c = m[n - 1][n - 2]
	d = m[n - 2][n - 1]
	coords = []
	if a == b:
		if c == a:
			coords.append([n, n - 1])
		if d == a:
			coords.append([n - 1, n])
	elif c == d:
		if a == c:
			coords.append([1, 2])
		if b == c:
			coords.append([2, 1])
	else:
		coords.append([2, 1])
		if c == a:
			coords.append([n, n - 1])
		if d == a:
			coords.append([n - 1, n])
	assert len(coords) <= 2
	print(len(coords))
	for (y, x) in coords:
		print('{} {}'.format(y, x))
n_t = int(input())
for t in range(n_t):
	n = int(input())
	m = []
	for r in range(n):
		row = input()
		assert len(row) == n
		m.append(row)
	find_invert_positions(m)


I = input
exec(int(I()) * "n=int(I());a=[[*map(ord,I())]for _ in[0]*n];a=a[0][1],a[1][0],a[-2][-1]^1,a[-1][-2]^1;r=[y for x,y in zip(a,('1 2','2 1',f'{n-1} {n}',f'{n} {n-1}'))if(sum(a)>194)^x&1];print(len(r),*r);")


import sys
import os
from math import sqrt, log, log2, log10, gcd, floor, pow, sin, cos, tan, pi, inf, factorial
from copy import copy, deepcopy
from sys import exit, stdin, stdout
from collections import Counter, defaultdict, deque
from itertools import permutations
import heapq
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = 1000000007
iinp = lambda : int(sys.stdin.readline())
inp = lambda : sys.stdin.readline().strip()
strl = lambda : list(inp().strip().split(' '))
intl = lambda : list(map(int, inp().split(' ')))
mint = lambda : map(int, inp().split())
flol = lambda : list(map(float, inp().split(' ')))
flush = lambda : stdout.flush()

def permute(nums):

	def fun(arr, nums, cur, v):
		if len(cur) == len(nums):
			arr.append(cur.copy())
		i = 0
		while i < len(nums):
			if v[i]:
				i += 1
				continue
			else:
				cur.append(nums[i])
				v[i] = 1
				fun(arr, nums, cur, v)
				cur.pop()
				v[i] = 0
				i += 1
		return arr
	res = []
	nums.sort()
	v = [0] * len(nums)
	return fun(res, nums, [], v)

def subsets(res, index, arr, cur):
	res.append(cur.copy())
	for i in range(index, len(arr)):
		cur.append(arr[i])
		subsets(res, i + 1, arr, cur)
		cur.pop()
	return res

def sieve(N):
	root = int(sqrt(N))
	primes = [1] * (N + 1)
	(primes[0], primes[1]) = (0, 0)
	for i in range(2, root + 1):
		if primes[i]:
			for j in range(i * i, N + 1, i):
				primes[j] = 0
	return primes

def bs(arr, l, r, x):
	if x < arr[0] or x > arr[len(arr) - 1]:
		return -1
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	p = int(sqrt(n))
	for i in range(5, p + 1, 6):
		if n % i == 0 or n % (i + 2) == 0:
			return False
	return True

def solve():
	n = iinp()
	arr = []
	for i in range(n):
		a = list(input())
		arr.append(a)
	a = 0
	ares = []
	b = 0
	bres = []
	if arr[0][1] != str(0):
		a += 1
		ares.append([1, 2])
	if arr[1][0] != str(0):
		a += 1
		ares.append([2, 1])
	if arr[1][1] != str(1):
		a += 1
		ares.append([2, 2])
	if arr[2][0] != str(1):
		a += 1
		ares.append([3, 1])
	if arr[0][2] != str(1):
		a += 1
		ares.append([1, 3])
	if arr[0][1] != str(1):
		b += 1
		bres.append([1, 2])
	if arr[1][0] != str(1):
		b += 1
		bres.append([2, 1])
	if arr[1][1] != str(0):
		b += 1
		bres.append([2, 2])
	if arr[2][0] != str(0):
		b += 1
		bres.append([3, 1])
	if arr[0][2] != str(0):
		b += 1
		bres.append([1, 3])
	if a < b:
		print(a)
		for i in ares:
			print(*i)
	else:
		print(b)
		for i in bres:
			print(*i)
for _ in range(iinp()):
	solve()


I = input
exec(int(I()) * "n=int(I());a=[[*map(ord,I())]for _ in[0]*n];a=a[0][1],a[1][0],a[-2][-1]^1,a[-1][-2]^1;b=*map(a.count,a),;r=[y for x,y in zip(a,('1 2','2 1',f'{n-1} {n}',f'{n} {n-1}'))if(b[0]>3or a[b.index(min(b))])==x];print(len(r),*r);")


t = int(input())
for _ in range(t):
	mat = []
	n = int(input())
	for _ in range(n):
		mat.append(input())
	start1 = mat[0][1]
	start2 = mat[1][0]
	end1 = mat[n - 1][n - 2]
	end2 = mat[n - 2][n - 1]
	ans = 0
	changes = []
	if start1 != start2:
		if end1 == end2:
			if start1 == end1:
				ans += 1
				changes.append([0, 1])
			else:
				ans += 1
				changes.append([1, 0])
		elif start1 != end1:
			ans += 2
			changes.append([0, 1])
			changes.append([n - 1, n - 2])
		else:
			ans += 2
			changes.append([1, 0])
			changes.append([n - 1, n - 2])
	else:
		if start1 != end1 and start2 != end2:
			print(0)
			continue
		if start1 == end1 and start2 != end2:
			ans += 1
			changes.append([n - 1, n - 2])
		elif start1 != end1 and start2 == end2:
			ans += 1
			changes.append([n - 2, n - 1])
		else:
			ans += 2
			changes.append([n - 1, n - 2])
			changes.append([n - 2, n - 1])
	print(ans)
	for line in changes:
		print(int(line[0]) + 1, int(line[1]) + 1)


for t in range(int(input())):
	n = int(input())
	arr = []
	for i in range(n):
		row = list(input())
		arr.append(row)
	d1 = [int(arr[1][0]), int(arr[0][1])]
	d2 = [int(arr[n - 1][n - 2]), int(arr[n - 2][n - 1])]
	if d1 == [0, 0]:
		if d2 == [0, 0]:
			print(2)
			print(2, 1)
			print(1, 2)
		elif d2 == [1, 0]:
			print(1)
			print(n - 1, n)
		elif d2 == [0, 1]:
			print(1)
			print(n, n - 1)
		else:
			print(0)
	elif d1 == [1, 0]:
		if d2 == [0, 0]:
			print(1)
			print(1, 2)
		elif d2 == [1, 0]:
			print(2)
			print(2, 1)
			print(n, n - 1)
		elif d2 == [0, 1]:
			print(2)
			print(1, 2)
			print(n - 1, n)
		elif d2 == [1, 1]:
			print(1)
			print(2, 1)
	elif d1 == [0, 1]:
		if d2 == [0, 0]:
			print(1)
			print(2, 1)
		elif d2 == [1, 0]:
			print(2)
			print(1, 2)
			print(n - 1, n)
		elif d2 == [0, 1]:
			print(2)
			print(1, 2)
			print(n, n - 1)
		elif d2 == [1, 1]:
			print(1)
			print(1, 2)
	elif d1 == [1, 1]:
		if d2 == [0, 0]:
			print(0)
		elif d2 == [1, 0]:
			print(1)
			print(n, n - 1)
		elif d2 == [0, 1]:
			print(1)
			print(n - 1, n)
		elif d2 == [1, 1]:
			print(2)
			print(n - 1, n)
			print(n, n - 1)


import os
import sys
from math import *
from collections import *
from heapq import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz/'
M = 1000000007
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	n = Int()
	a = []
	for i in range(n):
		a.append(input())
	x = a[0][1]
	y = a[1][0]
	w = a[n - 1][n - 2]
	z = a[n - 2][n - 1]
	ans = []
	if x == y:
		if w == z:
			if w != x:
				pass
			else:
				ans.append((n, n - 1))
				ans.append((n - 1, n))
		elif w == x:
			ans.append((n, n - 1))
		else:
			ans.append((n - 1, n))
	elif w == z:
		if w == x:
			ans.append((1, 2))
		else:
			ans.append((2, 1))
	elif x == w:
		ans.append((1, 2))
		ans.append((n - 1, n))
	else:
		ans.append((1, 2))
		ans.append((n, n - 1))
	print(len(ans))
	for i in ans:
		print(*i)


test_cases = range(int(input()))
for test_case in test_cases:
	n = int(input())
	grid = []
	for i in range(n):
		new_line = [c for c in input()]
		grid.append(new_line)
	(sr, sd) = (grid[0][1], grid[1][0])
	(fl, fu) = (grid[n - 1][n - 2], grid[n - 2][n - 1])
	if sr == sd and fl == fu and (sr != fl):
		print(0)
		continue
	if sr == sd and fl == fu and (sr == fl):
		print(2)
		print(1, 2)
		print(2, 1)
		continue
	if sr == sd and sr == fl:
		print(1)
		print(n, n - 1)
		continue
	if sr == sd and sr == fu:
		print(1)
		print(n - 1, n)
		continue
	if fl == fu and fl == sr:
		print(1)
		print(1, 2)
		continue
	if fl == fu and fl == sd:
		print(1)
		print(2, 1)
		continue
	if fl == sd:
		print(2)
		print(n, n - 1)
		print(1, 2)
		continue
	if fl == sr:
		print(2)
		print(n, n - 1)
		print(2, 1)
		continue


for _ in range(int(input())):
	n = int(input())
	A = []
	for _ in range(n):
		A.append(input())
	cnt = 0
	ans = []
	if A[0][1] == A[1][0]:
		cur = A[0][1]
		if A[-1][-2] == cur:
			cnt += 1
			ans.append([n, n - 1])
		if A[-2][-1] == cur:
			cnt += 1
			ans.append([n - 1, n])
		print(cnt)
		for a in ans:
			print(*a)
	else:
		cur = A[0][1] + A[1][0] + A[-1][-2] + A[-2][-1]
		n1 = cur.count('1')
		if n1 == 2:
			if A[0][1] == '1':
				ans.append([1, 2])
			if A[1][0] == '1':
				ans.append([2, 1])
			if A[-2][-1] == '0':
				ans.append([n - 1, n])
			if A[-1][-2] == '0':
				ans.append([n, n - 1])
			print(2)
			for a in ans:
				print(*a)
		else:
			t = '1' if n1 == 1 else '0'
			if '1' in A[0][1] + A[1][0]:
				if A[0][1] == t:
					ans.append([2, 1])
				else:
					ans.append([1, 2])
			elif A[-2][-1] == t:
				ans.append([n, n - 1])
			else:
				ans.append([n - 1, n])
			print(1)
			for a in ans:
				print(*a)


from sys import stdin

def main():
	input = lambda : stdin.readline()[:-1]
	T = int(input())
	for _ in [0] * T:
		N = int(input())
		S = [input() for _ in [0] * N]
		(sd, sr) = (int(S[1][0]), int(S[0][1]))
		(fu, fl) = (int(S[N - 2][N - 1]), int(S[N - 1][N - 2]))
		if sd + sr + fu + fl == 0 or sd + sr + fu + fl == 4:
			ans1 = 2
			ans2 = [(1, 2), (2, 1)]
		elif sd == sr and fu == fl:
			ans1 = 0
			ans2 = []
		elif sd == sr:
			ans1 = 1
			if fu == sd:
				ans2 = [(N - 1, N)]
			else:
				ans2 = [(N, N - 1)]
		elif fu == fl:
			ans1 = 1
			if sd == fu:
				ans2 = [(2, 1)]
			else:
				ans2 = [(1, 2)]
		else:
			ans1 = 2
			ans2 = []
			if sd:
				ans2.append((2, 1))
			if sr:
				ans2.append((1, 2))
			if not fu:
				ans2.append((N - 1, N))
			if not fl:
				ans2.append((N, N - 1))
		print(ans1)
		for a in ans2:
			print(*a)
main()


import sys
input = sys.stdin.readline
(inp, ip) = (lambda : int(input()), lambda : [int(w) for w in input().split()])
import sys
input = sys.stdin.readline
(inp, ip) = (lambda : int(input()), lambda : [int(w) for w in input().split()])
for _ in range(inp()):
	n = inp()
	x = [list(input().strip()) for i in range(n)]
	(a, b, c, d) = (x[0][1], x[1][0], x[n - 1][n - 2], x[n - 2][n - 1])
	if a == b == c == d:
		print(2)
		print(1, 2)
		print(2, 1)
	elif a == b and c == d:
		print(0)
	elif a == b and c != d:
		print(1)
		if c == a == b:
			print(n, n - 1)
		elif d == a == b:
			print(n - 1, n)
	elif c == d and a != b:
		print(1)
		if a == c == d:
			print(1, 2)
		elif b == c == d:
			print(2, 1)
	elif a != b and c != d:
		print(2)
		if b != c:
			print(2, 1)
			print(n, n - 1)
		else:
			print(1, 2)
			print(n, n - 1)


t = int(input())
for ti in range(t):
	n = int(input())
	grid = []
	for tn in range(n):
		grid.append(input())
	bord = [grid[1][0], grid[0][1], grid[n - 1][n - 2], grid[n - 2][n - 1]]
	ans = []
	for ls in [['0', '0', '1', '1'], ['1', '1', '0', '0']]:
		ans = []
		for i in range(4):
			if ls[i] != bord[i]:
				ans.append(i)
		if len(ans) <= 2:
			break
	print(len(ans))
	if ans:
		for i in ans:
			(x, y) = [(2, 1), (1, 2), (n, n - 1), (n - 1, n)][i]
			print(x, y)


t = int(input())
for _ in range(t):
	n = int(input())
	grid = []
	for i in range(n):
		grid.append(input())
	if grid[0][1] != grid[1][0] and grid[n - 1][n - 2] != grid[n - 2][n - 1]:
		print(2)
		if grid[0][1] != grid[n - 1][n - 2]:
			print(1, 2)
			print(n, n - 1)
		else:
			print(1, 2)
			print(n - 1, n)
	elif grid[0][1] != grid[1][0] and grid[n - 1][n - 2] == grid[n - 2][n - 1]:
		print(1)
		if grid[0][1] == grid[n - 1][n - 2]:
			print(1, 2)
		else:
			print(2, 1)
	elif grid[0][1] == grid[1][0] and grid[n - 1][n - 2] == grid[n - 2][n - 1] and (grid[0][1] != grid[n - 1][n - 2]):
		print(0)
	elif grid[0][1] == grid[1][0] and grid[n - 1][n - 2] == grid[n - 2][n - 1] and (grid[0][1] == grid[n - 1][n - 2]):
		print(2)
		print(1, 2)
		print(2, 1)
	elif grid[0][1] == grid[1][0] and grid[n - 1][n - 2] != grid[n - 2][n - 1] and (grid[0][1] == grid[n - 1][n - 2]):
		print(1)
		print(n, n - 1)
	elif grid[0][1] == grid[1][0] and grid[n - 1][n - 2] != grid[n - 2][n - 1] and (grid[0][1] != grid[n - 1][n - 2]):
		print(1)
		print(n - 1, n)


for _ in range(int(input())):
	ls = []
	n = int(input())
	for i in range(n):
		ls.append(input())
	a = ls[0][1]
	b = ls[1][0]
	c = ls[n - 2][n - 1]
	d = ls[n - 1][n - 2]
	ans = []
	f = 1
	if a == b:
		if a == c:
			ans.append([n - 1, n])
		if a == d:
			ans.append([n, n - 1])
		print(len(ans))
		for i in ans:
			print(*i)
	elif c == d:
		if a == c:
			ans.append([1, 2])
		if c == b:
			ans.append([2, 1])
		print(len(ans))
		for i in ans:
			print(*i)
	elif a == c and b == d:
		print(2)
		print(1, 2)
		print(n, n - 1)
	else:
		print(2)
		print(2, 1)
		print(n, n - 1)


for _ in range(int(input())):
	n = int(input())
	grid = [input() for i in range(n)]
	moves = []

	def set_to(i, j, val):
		if grid[i][j] != val:
			moves.append((i + 1, j + 1))

	def other(x):
		return '0' if x == '1' else '1'
	if grid[0][1] == grid[1][0]:
		for (i, j) in [(n - 2, n - 1), (n - 1, n - 2)]:
			set_to(i, j, other(grid[0][1]))
	elif grid[n - 2][n - 1] == grid[n - 1][n - 2]:
		for (i, j) in [(0, 1), (1, 0)]:
			set_to(i, j, other(grid[n - 2][n - 1]))
	else:
		for (i, j) in [(0, 1), (1, 0)]:
			set_to(i, j, '0')
		for (i, j) in [(n - 2, n - 1), (n - 1, n - 2)]:
			set_to(i, j, '1')
	print(len(moves))
	for move in moves:
		print(*move)


import sys
input = sys.stdin.readline
for i in range(int(input())):
	n = int(input())
	matrix = [list(input().strip()) for _ in range(n)]
	(a, b, c, d) = (int(matrix[1][0]), int(matrix[0][1]), int(matrix[-1][-2]), int(matrix[-2][-1]))
	(A, B, C, D) = [(2, 1), (1, 2), (n, n - 1), (n - 1, n)]
	if a == b == c == d:
		print(2)
		print(*A)
		print(*B)
	elif 1 * (not a) == b == c == d:
		print(1)
		print(*B)
	elif 1 * (not b) == a == c == d:
		print(1)
		print(*A)
	elif 1 * (not c) == a == b == d:
		print(1)
		print(*D)
	elif 1 * (not d) == a == c == b:
		print(1)
		print(*C)
	elif a == 1 * (not b) and c == 1 * (not d):
		print(2)
		if a == c:
			print(*B)
			print(*C)
		else:
			print(*B)
			print(*D)
	else:
		print(0)


import itertools

def solve(matrix):
	n = len(matrix)
	cells = [(0, 1), (1, 0), (n - 1, n - 2), (n - 2, n - 1)]
	for ncells in range(3):
		for combi in itertools.combinations(cells, ncells):
			for (y, x) in combi:
				matrix[y][x] = '1' if matrix[y][x] == '0' else '0'
			if matrix[0][1] == matrix[1][0] != matrix[n - 1][n - 2] == matrix[n - 2][n - 1]:
				return combi
			for (y, x) in combi:
				matrix[y][x] = '1' if matrix[y][x] == '0' else '0'
for _ in range(int(input())):
	n = int(input())
	matrix = []
	for _ in range(n):
		(*row,) = input()
		matrix.append(row)
	ans = solve(matrix)
	print(len(ans))
	for (y, x) in ans:
		print(y + 1, x + 1)


def main():
	n = int(input())
	x_12 = int(input()[1])
	x_2 = input()
	x_21 = int(x_2[0])
	x_2n = int(x_2[-1])
	if n >= 5:
		for i in range(3, n - 1):
			input()
	if n == 3:
		x_n1 = x_2n
	else:
		x_n1 = int(input()[-1])
	x_n = int(input()[-2])
	if sum([x_12, x_21, x_n1, x_n]) == 0 or sum([x_12, x_21, x_n1, x_n]) == 4:
		print(2)
		print('1 2')
		print('2 1')
	elif sum([x_12, x_21, x_n1, x_n]) == 1:
		print(1)
		if x_12 == 1:
			print('2 1')
		elif x_21 == 1:
			print('1 2')
		elif x_n1 == 1:
			print(f'{n} {n - 1}')
		else:
			print(f'{n - 1} {n}')
	elif sum([x_12, x_21, x_n1, x_n]) == 2:
		if x_12 and x_21:
			print(0)
		elif x_n1 and x_n:
			print(0)
		elif x_12 and x_n1:
			print(2)
			print('2 1')
			print(f'{n - 1} {n}')
		elif x_12 and x_n:
			print(2)
			print('2 1')
			print(f'{n} {n - 1}')
		elif x_21 and x_n:
			print(2)
			print('1 2')
			print(f'{n} {n - 1}')
		else:
			print(2)
			print('1 2')
			print(f'{n - 1} {n}')
	elif sum([x_12, x_21, x_n1, x_n]) == 3:
		print(1)
		if x_12 == 0:
			print('2 1')
		elif x_21 == 0:
			print('1 2')
		elif x_n1 == 0:
			print(f'{n} {n - 1}')
		else:
			print(f'{n - 1} {n}')
l = int(input())
for i in range(l):
	main()


import sys
try:
	(sys.stdin, sys.stdout) = (open('in.txt', 'r'), open('out.txt', 'w'))
except:
	pass
ii1 = lambda : int(sys.stdin.readline().strip())
is1 = lambda : sys.stdin.readline().strip()
iia = lambda : list(map(int, sys.stdin.readline().strip().split()))
isa = lambda : sys.stdin.readline().strip().split()
mod = int(1000000000.0 + 7)
from collections import *
from math import *
for i in range(ii1()):
	n = ii1()
	grid = []
	for j in range(n):
		grid.append(is1())
	ans = []
	if grid[0][1] == grid[1][0]:
		if grid[n - 1][n - 2] == grid[0][1]:
			ans.append([n, n - 1])
		if grid[n - 2][n - 1] == grid[0][1]:
			ans.append([n - 1, n])
	elif grid[n - 1][n - 2] == grid[n - 2][n - 1]:
		if grid[n - 1][n - 2] == grid[0][1]:
			ans.append([1, 2])
		if grid[n - 1][n - 2] == grid[1][0]:
			ans.append([2, 1])
	else:
		if grid[0][1] == '1':
			ans.append([1, 2])
		else:
			ans.append([2, 1])
		if grid[n - 1][n - 2] == '0':
			ans.append([n, n - 1])
		else:
			ans.append([n - 1, n])
	print(len(ans))
	if ans:
		for a in ans:
			print(*a)


for _ in range(int(input())):
	n = int(input())
	nn = [input() for _ in range(n)]
	a = nn[0][1]
	b = nn[1][0]
	c = nn[-2][-1]
	d = nn[-1][-2]
	q = {a, b}
	w = {c, d}
	ap = (1, 2)
	bp = (2, 1)
	cp = (n - 1, n)
	dp = (n, n - 1)
	qw = q & w
	ans = []
	if not qw:
		pass
	elif len(q) == 1:
		(q,) = q
		if c == q:
			ans.append(cp)
		if d == q:
			ans.append(dp)
	elif len(w) == 1:
		(q,) = w
		if a == q:
			ans.append(ap)
		if b == q:
			ans.append(bp)
	else:
		if a == '0':
			ans.append(ap)
		else:
			ans.append(bp)
		if c == '1':
			ans.append(cp)
		else:
			ans.append(dp)
	print(len(ans))
	print('\n'.join((f'{a} {b}' for (a, b) in ans)))


def solve():
	n = int(input().strip())
	grid = []
	for _ in range(n):
		grid.append(input().strip())
	cells = 0
	(pick1, pick2) = (None, None)
	zeros = len(list(filter(lambda x: x == '0', [grid[0][1], grid[1][0], grid[-1][-2], grid[-2][-1]])))
	if zeros in [0, 4]:
		cells = 2
		(pick1, pick2) = ((0, 1), (1, 0))
	elif zeros in [1, 3]:
		cells = 1
		target = '0'
		if zeros == 3:
			target = '1'
		if grid[1][0] == target:
			pick1 = (0, 1)
		elif grid[0][1] == target:
			pick1 = (1, 0)
		elif grid[n - 1][n - 2] == target:
			pick1 = (n - 2, n - 1)
		else:
			pick1 = (n - 1, n - 2)
	elif grid[0][1] != grid[1][0]:
		cells = 2
		pick1 = (1, 0)
		if grid[-1][-2] == grid[0][1]:
			pick2 = (n - 1, n - 2)
		else:
			pick2 = (n - 2, n - 1)
	print(cells)
	if pick1:
		pick1 = map(str, map(lambda t: t + 1, pick1))
		print(' '.join(pick1))
	if pick2:
		pick2 = map(str, map(lambda t: t + 1, pick2))
		print(' '.join(pick2))
for _ in range(int(input().strip())):
	solve()


from sys import stdin, stdout, setrecursionlimit
import heapq
from math import gcd, ceil, sqrt
from collections import Counter, deque
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
setrecursionlimit(100000)
mod = 1000000007
tc = ii1()
for _ in range(tc):
	n = ii1()
	arr = []
	for i in range(n):
		arr.append(is1())
	st = [[0, 1], [1, 0]]
	end = [[n - 1, n - 2], [n - 2, n - 1]]
	(one, two) = ([], [])
	for i in st:
		if arr[i[0]][i[1]] == '0':
			one.append([i[0] + 1, i[1] + 1])
		else:
			two.append([i[0] + 1, i[1] + 1])
	for i in end:
		if arr[i[0]][i[1]] == '0':
			two.append([i[0] + 1, i[1] + 1])
		else:
			one.append([i[0] + 1, i[1] + 1])
	if len(two) < 3:
		print(len(two))
		for i in two:
			print(*i)
	else:
		print(len(one))
		for i in one:
			print(*i)


import math
import sys, bisect
from heapq import *
from itertools import *
from collections import *
sys.setrecursionlimit(10 ** 6)
I = lambda : int(sys.stdin.readline())
neo = lambda : map(int, sys.stdin.readline().split())
Neo = lambda : list(map(int, sys.stdin.readline().split()))
for _ in range(I()):
	n = I()
	grid = [input() for i in range(n)]
	(a, b, c, d) = (grid[0][1], grid[1][0], grid[-2][-1], grid[-1][-2])
	(e, f) = ([], [])
	if a != '0':
		e.append((1, 2))
	if b != '0':
		e.append((2, 1))
	if c != '1':
		e.append((n - 1, n))
	if d != '1':
		e.append((n, n - 1))
	if c != '0':
		f.append((n - 1, n))
	if d != '0':
		f.append((n, n - 1))
	if a != '1':
		f.append((1, 2))
	if b != '1':
		f.append((2, 1))
	if len(e) < len(f):
		print(len(e))
		for i in e:
			print(*i)
	else:
		print(len(f))
		for i in f:
			print(*i)


from math import *
t = int(input())
while t:
	t = t - 1
	n = int(input())
	a = []
	for i in range(n):
		s = input()
		a.append(s)
	l = [a[0][1], a[1][0], a[n - 1][n - 2], a[n - 2][n - 1]]
	oc = l.count('1')
	zc = l.count('0')
	out = []
	if oc == 4 or zc == 4:
		out.append([1, 0])
		out.append([0, 1])
	elif oc > zc:
		if a[1][0] == '1' and a[0][1] == '0':
			out.append([1, 0])
		elif a[1][0] == '0' and a[0][1] == '1':
			out.append([0, 1])
		elif a[n - 1][n - 2] == '1' and a[n - 2][n - 1] == '0':
			out.append([n - 1, n - 2])
		elif a[n - 1][n - 2] == '0' and a[n - 2][n - 1] == '1':
			out.append([n - 2, n - 1])
	elif oc < zc:
		if a[1][0] == '0' and a[0][1] == '1':
			out.append([1, 0])
		elif a[1][0] == '1' and a[0][1] == '0':
			out.append([0, 1])
		elif a[n - 1][n - 2] == '0' and a[n - 2][n - 1] == '1':
			out.append([n - 1, n - 2])
		elif a[n - 1][n - 2] == '1' and a[n - 2][n - 1] == '0':
			out.append([n - 2, n - 1])
	elif a[1][0] != a[0][1]:
		if a[1][0] == '0':
			out.append([1, 0])
		if a[0][1] == '0':
			out.append([0, 1])
		if a[n - 1][n - 2] == '1':
			out.append([n - 1, n - 2])
		if a[n - 2][n - 1] == '1':
			out.append([n - 2, n - 1])
	print(len(out))
	for i in out:
		print(i[0] + 1, i[1] + 1)


t = int(input())
for x in range(t):
	n = int(input())
	grid = []
	for i in range(n):
		a = input()
		b = []
		for element in a:
			b.append(element)
		grid.append(b)
	relevant = [grid[0][1], grid[1][0], grid[n - 1][n - 2], grid[n - 2][n - 1]]
	a = []
	for i in range(1, 4):
		if relevant[i] == relevant[0]:
			a.append(i)
	if len(a) == 0:
		print(1)
		print(2, 1)
	elif len(a) == 1:
		if int(a[0]) < 2:
			print(0)
		elif int(a[0]) == 2:
			print(2)
			print(2, 1)
			print(n, n - 1)
		else:
			print(2)
			print(2, 1)
			print(n - 1, n)
	elif len(a) == 2:
		if 2 in a and 3 in a:
			print(1)
			print(1, 2)
		elif 2 in a:
			print(1)
			print(n, n - 1)
		else:
			print(1)
			print(n - 1, n)
	else:
		print(2)
		print(1, 2)
		print(2, 1)


t = int(input())
for _ in range(t):
	n = int(input())
	grid = []
	for i in range(n):
		grid.append(input())
	count = 0
	ans = ''
	if grid[-1][-2] == grid[-2][-1]:
		if grid[0][1] == grid[-2][-1]:
			ans += '\n1 2'
			count += 1
		if grid[1][0] == grid[-2][-1]:
			ans += '\n2 1'
			count += 1
	elif grid[0][1] == grid[1][0]:
		if grid[-1][-2] == grid[0][1]:
			count += 1
			ans += '\n' + str(n) + ' ' + str(len(grid[0]) - 1)
		if grid[-2][-1] == grid[0][1]:
			count += 1
			ans += '\n' + str(n - 1) + ' ' + str(len(grid[0]))
	elif grid[0][1] != grid[-1][-2]:
		count += 2
		ans += '\n1 2'
		ans += '\n' + str(n) + ' ' + str(len(grid[0]) - 1)
	elif grid[0][1] != grid[-2][-1]:
		count += 2
		ans += '\n1 2'
		ans += '\n' + str(n - 1) + ' ' + str(len(grid[0]))
	print(str(count) + ans)


t = int(input())
for x in range(t):
	n = int(input())
	a = []
	for i in range(n):
		a.append(input())
	if a[1][0] == a[0][1] and a[n - 1][n - 2] != a[n - 2][n - 1]:
		print(1)
		if a[1][0] == a[n - 1][n - 2]:
			print(n, n - 1)
		else:
			print(n - 1, n)
	elif a[1][0] != a[0][1] and a[n - 1][n - 2] == a[n - 2][n - 1]:
		print(1)
		if a[1][0] == a[n - 1][n - 2]:
			print(2, 1)
		else:
			print(1, 2)
	elif a[1][0] != a[0][1] and a[n - 1][n - 2] != a[n - 2][n - 1]:
		print(2)
		if a[1][0] == a[n - 1][n - 2]:
			print(2, 1)
			print(n - 1, n)
		else:
			print(1, 2)
			print(n - 1, n)
	elif a[1][0] == a[0][1] and a[n - 1][n - 2] == a[n - 2][n - 1]:
		if a[1][0] == a[n - 1][n - 2]:
			print(2)
			print(2, 1)
			print(1, 2)
		else:
			print(0)


for _ in range(int(input())):
	n = int(input())
	mat = []
	for i in range(n):
		mat.append(list(map(str, input())))
	ans = []
	tl = [[0, 1], [1, 0]]
	tr = [[n - 1, n - 2], [n - 2, n - 1]]
	if mat[tl[0][0]][tl[0][1]] == mat[tl[1][0]][tl[1][1]]:
		x = int(mat[tl[0][0]][tl[0][1]]) ^ 1
		x = str(x)
		if mat[tr[0][0]][tr[0][1]] != x:
			ans.append([n, n - 1])
		if mat[tr[1][0]][tr[1][1]] != x:
			ans.append([n - 1, n])
	elif mat[tr[0][0]][tr[0][1]] == mat[tr[1][0]][tr[1][1]]:
		x = int(mat[tr[0][0]][tr[0][1]]) ^ 1
		x = str(x)
		if mat[tl[0][0]][tl[0][1]] != x:
			ans.append([1, 2])
		if mat[tl[1][0]][tl[1][1]] != x:
			ans.append([2, 1])
	else:
		if mat[0][1] == '1':
			ans.append([1, 2])
		if mat[1][0] == '1':
			ans.append([2, 1])
		if mat[-1][-2] == '0':
			ans.append([n, n - 1])
		if mat[-2][-1] == '0':
			ans.append([n - 1, n])
	print(len(ans))
	for i in ans:
		print(*i)


for _ in range(int(input())):
	n = int(input())
	arr = []
	for i in range(n):
		arr.append(input())
	if arr[1][0] == '0' and arr[0][1] == '0' and (arr[n - 1][n - 2] == '0') and (arr[n - 2][n - 1] == '0'):
		print(2)
		print(1, 2)
		print(2, 1)
	elif arr[1][0] == '0' and arr[0][1] == '0' and (arr[n - 1][n - 2] == '0') and (arr[n - 2][n - 1] == '1'):
		print(1)
		print(n, n - 1)
	elif arr[1][0] == '0' and arr[0][1] == '0' and (arr[n - 1][n - 2] == '1') and (arr[n - 2][n - 1] == '0'):
		print(1)
		print(n - 1, n)
	elif arr[1][0] == '0' and arr[0][1] == '0' and (arr[n - 1][n - 2] == '1') and (arr[n - 2][n - 1] == '1'):
		print(0)
	elif arr[1][0] == '0' and arr[0][1] == '1' and (arr[n - 1][n - 2] == '0') and (arr[n - 2][n - 1] == '0'):
		print(1)
		print(2, 1)
	elif arr[1][0] == '0' and arr[0][1] == '1' and (arr[n - 1][n - 2] == '0') and (arr[n - 2][n - 1] == '1'):
		print(2)
		print(1, 2)
		print(n, n - 1)
	elif arr[1][0] == '0' and arr[0][1] == '1' and (arr[n - 1][n - 2] == '1') and (arr[n - 2][n - 1] == '0'):
		print(2)
		print(2, 1)
		print(n, n - 1)
	elif arr[1][0] == '0' and arr[0][1] == '1' and (arr[n - 1][n - 2] == '1') and (arr[n - 2][n - 1] == '1'):
		print(1)
		print(1, 2)
	elif arr[1][0] == '1' and arr[0][1] == '0' and (arr[n - 1][n - 2] == '0') and (arr[n - 2][n - 1] == '0'):
		print(1)
		print(1, 2)
	elif arr[1][0] == '1' and arr[0][1] == '0' and (arr[n - 1][n - 2] == '0') and (arr[n - 2][n - 1] == '1'):
		print(2)
		print(2, 1)
		print(n, n - 1)
	elif arr[1][0] == '1' and arr[0][1] == '0' and (arr[n - 1][n - 2] == '1') and (arr[n - 2][n - 1] == '0'):
		print(2)
		print(2, 1)
		print(n - 1, n)
	elif arr[1][0] == '1' and arr[0][1] == '0' and (arr[n - 1][n - 2] == '1') and (arr[n - 2][n - 1] == '1'):
		print(1)
		print(2, 1)
	elif arr[1][0] == '1' and arr[0][1] == '1' and (arr[n - 1][n - 2] == '0') and (arr[n - 2][n - 1] == '0'):
		print(0)
	elif arr[1][0] == '1' and arr[0][1] == '1' and (arr[n - 1][n - 2] == '0') and (arr[n - 2][n - 1] == '1'):
		print(1)
		print(n - 1, n)
	elif arr[1][0] == '1' and arr[0][1] == '1' and (arr[n - 1][n - 2] == '1') and (arr[n - 2][n - 1] == '0'):
		print(1)
		print(n, n - 1)
	elif arr[1][0] == '1' and arr[0][1] == '1' and (arr[n - 1][n - 2] == '1') and (arr[n - 2][n - 1] == '1'):
		print(2)
		print(1, 2)
		print(2, 1)


def solve():
	n = int(input())
	d = [list(input()) for i in range(n)]
	cnt1 = 0
	que1 = []
	if d[0][1] != '1':
		cnt1 += 1
		que1.append((1, 2))
	if d[1][0] != '1':
		cnt1 += 1
		que1.append((2, 1))
	if d[-2][-1] != '0':
		cnt1 += 1
		que1.append((n - 1, n))
	if d[-1][-2] != '0':
		cnt1 += 1
		que1.append((n, n - 1))
	if cnt1 <= 2:
		print(cnt1)
		for (x, y) in que1:
			print(x, y)
		return
	cnt1 = 0
	que1 = []
	if d[0][1] != '0':
		cnt1 += 1
		que1.append((1, 2))
	if d[1][0] != '0':
		cnt1 += 1
		que1.append((2, 1))
	if d[-2][-1] != '1':
		cnt1 += 1
		que1.append((n - 1, n))
	if d[-1][-2] != '1':
		cnt1 += 1
		que1.append((n, n - 1))
	if cnt1 <= 2:
		print(cnt1)
		for (x, y) in que1:
			print(x, y)
		return

def main():
	t = int(input())
	for i in range(t):
		solve()
	return
main()


ans = []
for i in range(int(input())):
	n = int(input())
	grid = []
	for j in range(n):
		grid.append(input())
	(s_right, s_down) = (int(grid[0][1]), int(grid[1][0]))
	(f_left, f_up) = (int(grid[n - 1][n - 2]), int(grid[n - 2][n - 1]))
	s_sum = s_right + s_down
	f_sum = f_left + f_up
	if abs(f_sum - s_sum) == 2:
		ans.append('0')
	elif abs(f_sum - s_sum) == 1:
		ans.append('1')
		if f_sum == 2 or s_sum == 2:
			if s_sum == 1:
				if s_right == 1:
					ans.append('1 2')
				else:
					ans.append('2 1')
			elif f_sum == 1:
				if f_left == 1:
					ans.append(str(n) + ' ' + str(n - 1))
				else:
					ans.append(str(n - 1) + ' ' + str(n))
		elif s_sum == 1:
			if s_right == 0:
				ans.append('1 2')
			else:
				ans.append('2 1')
		elif f_sum == 1:
			if f_left == 0:
				ans.append(str(n) + ' ' + str(n - 1))
			else:
				ans.append(str(n - 1) + ' ' + str(n))
	elif abs(f_sum - s_sum) == 0:
		ans.append('2')
		if s_sum == 0 or s_sum == 2:
			ans.append('1 2')
			ans.append('2 1')
		else:
			if s_right == 1:
				ans.append('1 2')
			else:
				ans.append('2 1')
			if f_left == 0:
				ans.append(str(n) + ' ' + str(n - 1))
			else:
				ans.append(str(n - 1) + ' ' + str(n))
print('\n'.join(ans))


import itertools
import copy

def index(grid, ix):
	return grid[ix[0]][ix[1]]

def index_set(grid, ix, val):
	grid[ix[0]][ix[1]] = val

def index_flip(grid, ix):
	bit = ord(index(grid, ix)) - ord('0')
	new = chr(1 - bit + ord('0'))
	index_set(grid, ix, new)

def solve(n, grid):
	ri = (0, 1)
	di = (1, 0)
	ui = (n - 2, n - 1)
	li = (n - 1, n - 2)
	indices = [ri, di, ui, li]
	for p in itertools.product(*[range(2)] * 4):
		if sum(p) > 2:
			continue
		new_grid = copy.deepcopy(grid)
		for (i, x) in enumerate(p):
			if x == 1:
				index_flip(new_grid, indices[i])
		r = index(new_grid, ri)
		d = index(new_grid, di)
		u = index(new_grid, ui)
		l = index(new_grid, li)
		if r == d and u == l and (r != u):
			return [(r + 1, c + 1) for (i, (r, c)) in enumerate(indices) if p[i] == 1]

def main():
	nt = int(input())
	for _ in range(nt):
		n = int(input())
		grid = []
		for _ in range(n):
			grid.append(list(input()))
		sol = solve(n, grid)
		print(len(sol))
		for (r, c) in sol:
			print(r, c)

def test():
	n = 4
	grid = [list(r) for r in ['S010', '0001', '1000', '111F']]
	print(solve(n, grid))
main()


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
import sys
input = sys.stdin.readline
scanner = lambda : int(input())
string = lambda : input().rstrip()
get_list = lambda : list(read())
read = lambda : map(int, input().split())
get_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def is_integer(n):
	return math.ceil(n) == math.floor(n)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	if y == 0:
		return 1
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def next_prime(n, primes):
	while primes[n] != True:
		n += 1
	return n
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(moves, n):
	val = (moves + 1) // 2
	rem = moves - val
	sol = (val + 1) * (rem + 1)
	return sol < n

def sortSecond(val):
	return val[1]
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
alphs = 'abcdefghijklmnopqrstuvwxyz'
from itertools import permutations
import math
import bisect as bis
import random
import sys
import collections as collect
import functools as fnt
from decimal import Decimal

def solve():
	n = scanner()
	grid = [string() for x in range(n)]
	if grid[0][1] == '0' and grid[1][0] == '0':
		if grid[-1][-2] == '0' and grid[-2][-1] == '0':
			print(2)
			print(n - 1, n)
			print(n, n - 1)
			return
		elif grid[-1][-2] == '0':
			print(1)
			print(n, n - 1)
			return
		elif grid[-2][-1] == '0':
			print(1)
			print(n - 1, n)
			return
		else:
			print(0)
			return
	if grid[0][1] == '1' and grid[1][0] == '1':
		if grid[-1][-2] == '1' and grid[-2][-1] == '1':
			print(2)
			print(n - 1, n)
			print(n, n - 1)
			return
		elif grid[-1][-2] == '1':
			print(1)
			print(n, n - 1)
			return
		elif grid[-2][-1] == '1':
			print(1)
			print(n - 1, n)
			return
		else:
			print(0)
			return
	if grid[0][1] == '0' and grid[1][0] == '1':
		if grid[-1][-2] == '1' and grid[-2][-1] == '1':
			print(1)
			print(2, 1)
			return
		elif grid[-1][-2] == '1' and grid[-2][-1] == '0':
			print(2)
			print(1, 2)
			print(n, n - 1)
			return
		elif grid[-1][-2] == '0' and grid[-2][-1] == '0':
			print(1)
			print(1, 2)
			return
		else:
			print(2)
			print(1, 2)
			print(n - 1, n)
			return
	if grid[0][1] == '1' and grid[1][0] == '0':
		if grid[-1][-2] == '1' and grid[-2][-1] == '1':
			print(1)
			print(1, 2)
			return
		elif grid[-1][-2] == '1' and grid[-2][-1] == '0':
			print(2)
			print(2, 1)
			print(n, n - 1)
			return
		elif grid[-1][-2] == '0' and grid[-2][-1] == '0':
			print(1)
			print(2, 1)
			return
		else:
			print(2)
			print(1, 2)
			print(n, n - 1)
			return
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = scanner()
for i in range(t):
	solve()


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	n = int(data())
	mat = [list(data()) for i in range(n)]
	answer = []
	if mat[0][1] == mat[1][0] == mat[-1][-2] == mat[-2][-1]:
		answer.append((1, 2))
		answer.append((2, 1))
	elif mat[0][1] == mat[1][0] and mat[-1][-2] == mat[-2][-1]:
		pass
	elif mat[0][1] != mat[1][0] and mat[-1][-2] == mat[-2][-1]:
		if mat[0][1] == mat[-1][-2]:
			answer.append((1, 2))
		else:
			answer.append((2, 1))
	elif mat[0][1] == mat[1][0] and mat[-1][-2] != mat[-2][-1]:
		if mat[-1][-2] == mat[0][1]:
			answer.append((n, n - 1))
		else:
			answer.append((n - 1, n))
	elif mat[0][1] == mat[-1][-2]:
		answer.append((1, 2))
		answer.append((n - 1, n))
	else:
		answer.append((1, 2))
		answer.append((n, n - 1))
	out(len(answer))
	for i in answer:
		outa(*i)


for _ in range(int(input())):
	n = int(input())
	arr = []
	for i in range(n):
		arr.append([ch for ch in input()])
	count = 0
	changes = []
	if arr[0][1] == arr[1][0]:
		if arr[n - 1][n - 2] == arr[1][0]:
			count += 1
			changes.append('{} {}'.format(n, n - 1))
		if arr[n - 2][n - 1] == arr[1][0]:
			count += 1
			changes.append('{} {}'.format(n - 1, n))
	elif arr[0][1] != arr[1][0]:
		if arr[n - 1][n - 2] == arr[n - 2][n - 1]:
			if arr[1][0] == arr[n - 1][n - 2]:
				count += 1
				changes.append('{} {}'.format(2, 1))
			if arr[0][1] == arr[n - 1][n - 2]:
				count += 1
				changes.append('{} {}'.format(1, 2))
		else:
			count += 1
			changes.append('{} {}'.format(1, 2))
			if arr[n - 1][n - 2] == arr[1][0]:
				count += 1
				changes.append('{} {}'.format(n, n - 1))
			if arr[n - 2][n - 1] == arr[1][0]:
				count += 1
				changes.append('{} {}'.format(n - 1, n))
	print(count)
	print('\n'.join(changes))


import math as mt
import bisect
import sys
t = int(input())
import collections
import heapq
p = 10 ** 9 + 7

def ncr_util():
	inv[0] = inv[1] = 1
	fact[0] = fact[1] = 1
	for i in range(2, 300001):
		inv[i] = inv[i % p] * (p - p // i) % p
	for i in range(1, 300001):
		inv[i] = inv[i - 1] * inv[i] % p
		fact[i] = fact[i - 1] * i % p

def solve():
	l1 = []
	if l[0][1] == l[1][0]:
		x = str(int(l[0][1]) ^ 1)
		if l[-1][-2] != x:
			l1.append([n, n - 1])
		if l[-2][-1] != x:
			l1.append([n - 1, n])
	elif l[n - 1][n - 2] == l[n - 2][n - 1]:
		x = str(int(l[n - 1][n - 2]) ^ 1)
		if l[0][1] != x:
			l1.append([1, 2])
		if l[1][0] != x:
			l1.append([2, 1])
	else:
		x = '1'
		if l[0][1] != x:
			l1.append([1, 2])
		if l[1][0] != x:
			l1.append([2, 1])
		x = '0'
		if l[-1][-2] != x:
			l1.append([n, n - 1])
		if l[-2][-1] != x:
			l1.append([n - 1, n])
	print(len(l1))
	if len(l1) > 0:
		for i in range(len(l1)):
			print(l1[i][0], l1[i][1])
for _ in range(t):
	n = int(input())
	l = []
	for i in range(n):
		l.append(input())
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	grid = []
	for i in range(n):
		grid.append([i for i in input().strip()])
	first = grid[1][0]
	second = grid[0][1]
	third = grid[n - 1][n - 2]
	fourth = grid[n - 2][n - 1]
	if first == second == third == fourth:
		print(2)
		print(2, 1)
		print(1, 2)
	elif first == second and third == fourth:
		print(0)
	elif first == '1' and second == '1' and (third == '1') and (fourth == '0'):
		print(1)
		print(n, n - 1)
	elif first == '1' and second == '1' and (third == '0') and (fourth == '1'):
		print(1)
		print(n - 1, n)
	elif first == '1' and second == '0' and (third == '1') and (fourth == '1'):
		print(1)
		print(2, 1)
	elif first == '0' and second == '1' and (third == '1') and (fourth == '1'):
		print(1)
		print(1, 2)
	elif first != '1' and second != '1' and (third != '1') and (fourth != '0'):
		print(1)
		print(n, n - 1)
	elif first != '1' and second != '1' and (third != '0') and (fourth != '1'):
		print(1)
		print(n - 1, n)
	elif first != '1' and second != '0' and (third != '1') and (fourth != '1'):
		print(1)
		print(2, 1)
	elif first != '0' and second != '1' and (third != '1') and (fourth != '1'):
		print(1)
		print(1, 2)
	elif first == '0' and second == '1' and (third == '1') and (fourth == '0'):
		print(2)
		print(2, 1)
		print(n, n - 1)
	elif first == '1' and second == '0' and (third == '0') and (fourth == '1'):
		print(2)
		print(2, 1)
		print(n, n - 1)
	elif first == '1' and second == '0' and (third == '1') and (fourth == '0'):
		print(2)
		print(1, 2)
		print(n, n - 1)
	elif first == '0' and second == '1' and (third == '0') and (fourth == '1'):
		print(2)
		print(1, 2)
		print(n, n - 1)


t = int(input())
while t:
	mas = []
	n = int(input())
	for i in range(n):
		w = input()
		w = list(w)
		mas.append(w)
	s1 = int(mas[0][1])
	s2 = int(mas[1][0])
	f1 = int(mas[-2][-1])
	f2 = int(mas[-1][-2])
	if s1 == s2 and f1 == f2 and (f1 != s1):
		print(0)
		t -= 1
		continue
	if s1 != s2 and f1 == f2:
		if s1 == f2:
			print(1)
			print(1, 2)
			t -= 1
			continue
		else:
			print(1)
			print(2, 1)
			t -= 1
			continue
	if f1 != f2 and s1 == s2:
		if f1 == s1:
			print(1)
			print(n - 1, n)
			t -= 1
			continue
		else:
			print(1)
			print(n, n - 1)
			t -= 1
			continue
	if s1 == s2 and f1 == f2 and (s1 == f1):
		print(2)
		print(1, 2)
		print(2, 1)
		t -= 1
		continue
	if f1 != f2 and s1 != s2 and (s1 == f1):
		print(2)
		print(1, 2)
		print(n, n - 1)
		t -= 1
		continue
	if f1 != f2 and s1 != s2 and (s1 != f1):
		print(2)
		print(1, 2)
		print(n - 1, n)
		t -= 1
		continue


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter
from itertools import combinations
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):
	print(stack)

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def pow(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def gcd(a, b):
	if a == b:
		return a
	while b > 0:
		(a, b) = (b, a % b)
	return a

def prefix_sum(ar):
	return list(accumulate(ar))

def suffix_sum(ar):
	return list(accumulate(ar[::-1]))[::-1]

def N():
	return int(inp())
from collections import defaultdict

def numberOfSetBits(i):
	i = i - (i >> 1 & 1431655765)
	i = (i & 858993459) + (i >> 2 & 858993459)
	return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24

def solve():
	n = N()
	ar = [inp() for _ in range(n)]
	c = 0
	ans = []
	if ar[0][1] == ar[1][0]:
		t = ar[0][1]
		if ar[n - 1][n - 2] == t:
			c += 1
			ans.append((n, n - 1))
		if ar[n - 2][n - 1] == t:
			c += 1
			ans.append((n - 1, n))
		print(c)
		for i in ans:
			print(*i)
		return
	if ar[n - 1][n - 2] == ar[n - 2][n - 1]:
		t = ar[n - 1][n - 2]
		if ar[0][1] == t:
			c += 1
			ans.append((1, 2))
		if ar[1][0] == t:
			c += 1
			ans.append((2, 1))
		print(c)
		for i in ans:
			print(*i)
		return
	if ar[1][0] != '0':
		c += 1
		ans.append((2, 1))
	if ar[0][1] != '0':
		c += 1
		ans.append((1, 2))
	if ar[n - 1][n - 2] != '1':
		c += 1
		ans.append((n, n - 1))
	if ar[n - 2][n - 1] != '1':
		c += 1
		ans.append((n - 1, n))
	print(c)
	for i in ans:
		print(*i)
	return
testcase(int(inp()))


import sys
import bisect as bi
import math
from collections import defaultdict as dd
import heapq
import itertools
import io
import os
input = sys.stdin.readline
import random
sys.setrecursionlimit(10 ** 7)
mo = 10 ** 9 + 7

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
for _ in range(inin()):
	n = inin()
	mat = []
	for i in range(n):
		l = sin().strip()
		mat += [l]
	ans = []
	tem = 0
	(a, b, c, d) = (mat[0][1], mat[1][0], mat[-2][-1], mat[-1][-2])
	p = [[1, 2], [2, 1], [n - 1, n], [n, n - 1]]
	if a == '1' and b == '1':
		if c == '1':
			ans += [p[2]]
			tem += 1
		if d == '1':
			ans += [p[3]]
			tem += 1
	elif a == '0' and b == '0':
		if c == '0':
			ans += [p[2]]
			tem += 1
		if d == '0':
			ans += [p[3]]
			tem += 1
	elif c == '0' and d == '0':
		if a == '0':
			ans += [p[0]]
			tem += 1
		else:
			ans += [p[1]]
			tem += 1
	else:
		if a == '1':
			ans += [p[0]]
			tem += 1
		if b == '1':
			ans += [p[1]]
			tem += 1
		if c == '0':
			ans += [p[2]]
			tem += 1
		if d == '0':
			ans += [p[3]]
			tem += 1
	print(tem)
	for i in ans:
		print(*i)


import sys
LI = lambda : list(map(int, sys.stdin.readline().strip('\n').split()))
MI = lambda : map(int, sys.stdin.readline().strip('\n').split())
SI = lambda : sys.stdin.readline().strip('\n')
II = lambda : int(sys.stdin.readline().strip('\n'))
for _ in range(II()):
	n = II()
	g = []
	for i in range(n):
		g.append(list(SI()))
	if g[0][1] == g[1][0] and g[-1][-2] == g[-2][-1] and (g[0][1] == g[-1][-2]):
		print(2)
		print(1, 2)
		print(2, 1)
	elif g[0][1] == g[1][0] and g[-1][-2] == g[-2][-1] and (g[0][1] != g[-1][-2]):
		print(0)
	elif g[0][1] != g[1][0] and g[-1][-2] == g[-2][-1]:
		print(1)
		if g[0][1] == g[-1][-2]:
			print(1, 2)
		else:
			print(2, 1)
	elif g[0][1] == g[1][0] and g[-1][-2] != g[-2][-1]:
		print(1)
		if g[0][1] == g[-1][-2]:
			print(n, n - 1)
		else:
			print(n - 1, n)
	elif g[0][1] != g[1][0] and g[-1][-2] != g[-2][-1]:
		print(2)
		print(2, 1)
		if g[0][1] == g[-1][-2]:
			print(n, n - 1)
		else:
			print(n - 1, n)


for _ in range(int(input())):
	ans = []
	n = int(input())
	X = []
	for i in range(n):
		X.append(list(input()))
	(s1, s2) = (int(X[0][1]), int(X[1][0]))
	(f1, f2) = (int(X[n - 2][n - 1]), int(X[n - 1][n - 2]))
	if s1 == s2 and f1 == f2 and (s1 != f1):
		ans = []
	elif s1 == s2:
		if f1 == s1:
			ans.append([n - 1, n])
		if f2 == s1:
			ans.append([n, n - 1])
	elif f1 == f2:
		if f1 == s1:
			ans.append([1, 2])
		if f1 == s2:
			ans.append([2, 1])
	elif s1 == 0:
		ans.append([2, 1])
		if f1 == 0:
			ans.append([n - 1, n])
		if f2 == 0:
			ans.append([n, n - 1])
	else:
		ans.append([1, 2])
		if f1 == 0:
			ans.append([n - 1, n])
		if f2 == 0:
			ans.append([n, n - 1])
	print(len(ans))
	for i in range(len(ans)):
		print(*ans[i])


for _ in range(int(input())):
	n = int(input())
	a = [[-1] * n for z in range(n)]
	for z in range(n):
		a[z] = list(input())
	ansx = []
	if a[0][1] == a[1][0]:
		v = a[0][1]
		if a[-1][-2] == v:
			ansx.append([n, n - 1])
		if a[-2][-1] == v:
			ansx.append([n - 1, n])
	elif a[-1][-2] == a[-2][-1]:
		v = a[-1][-2]
		if a[0][1] == v:
			ansx.append([1, 2])
		if a[1][0] == v:
			ansx.append([2, 1])
	else:
		v = a[0][1]
		ansx = [[2, 1]]
		if a[-1][-2] == v:
			ansx.append([n, n - 1])
		if a[-2][-1] == v:
			ansx.append([n - 1, n])
	print(len(ansx))
	for z in ansx:
		print(*z)


from bisect import *
from collections import *
from math import *
from heapq import *
from typing import List
from itertools import *
from operator import *
from functools import *
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

@lru_cache(None)
def fact(x):
	if x < 2:
		return 1
	return fact(x - 1) * x

@lru_cache(None)
def per(i, j):
	return fact(i) // fact(i - j)

@lru_cache(None)
def com(i, j):
	return per(i, j) // fact(j)

def linc(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t > f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rinc(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t < f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def ldec(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t < f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rdec(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t > f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def binfun(x):
	c = 0
	for w in arr:
		c += ceil(w / x)
	return c

def lowbit(n):
	return n & -n

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class smt:

	def __init__(self, l, r, arr):
		self.l = l
		self.r = r
		self.value = (1 << 31) - 1 if l < r else arr[l]
		mid = (l + r) // 2
		if l < r:
			self.left = smt(l, mid, arr)
			self.right = smt(mid + 1, r, arr)
			self.value &= self.left.value & self.right.value

	def setvalue(self, x, val):
		if self.l == self.r:
			self.value = val
			return
		mid = (self.l + self.r) // 2
		if x <= mid:
			self.left.setvalue(x, val)
		else:
			self.right.setvalue(x, val)
		self.value = self.left.value & self.right.value

	def ask(self, l, r):
		if l <= self.l and r >= self.r:
			return self.value
		val = (1 << 31) - 1
		mid = (self.l + self.r) // 2
		if l <= mid:
			val &= self.left.ask(l, r)
		if r > mid:
			val &= self.right.ask(l, r)
		return val

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return prime

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		for v in graph[u]:
			if v not in d or d[v] > d[u] + graph[u][v]:
				d[v] = d[u] + graph[u][v]
				heappush(heap, (d[v], v))
	return d
t = N()
for i in range(t):
	n = N()
	grid = []
	for j in range(n):
		grid.append(input())
	ans = []
	if grid[0][1] == grid[1][0]:
		if grid[n - 1][n - 2] == grid[0][1]:
			ans.append([n, n - 1])
		if grid[n - 2][n - 1] == grid[0][1]:
			ans.append([n - 1, n])
	elif grid[n - 1][n - 2] == grid[n - 2][n - 1]:
		if grid[n - 1][n - 2] == grid[0][1]:
			ans.append([1, 2])
		if grid[n - 1][n - 2] == grid[1][0]:
			ans.append([2, 1])
	else:
		if grid[0][1] == '1':
			ans.append([1, 2])
		else:
			ans.append([2, 1])
		if grid[n - 1][n - 2] == '0':
			ans.append([n, n - 1])
		else:
			ans.append([n - 1, n])
	print(len(ans))
	if ans:
		for a in ans:
			print(*a)


for i in range(int(input())):
	n = int(input())
	a = [input() for i in range(n)]
	(x, y, w, z) = (a[0][1], a[1][0], a[-1][-2], a[-2][-1])
	c = 0
	ans = []
	if x == '1' and y == '1':
		if w == '1':
			c += 1
			ans.append([n, n - 1])
		if z == '1':
			c += 1
			ans.append([n - 1, n])
	elif x == '0' and y == '0':
		if w == '0':
			c += 1
			ans.append([n, n - 1])
		if z == '0':
			c += 1
			ans.append([n - 1, n])
	elif w == '1' and z == '1':
		if x == '1':
			c += 1
			ans.append([1, 2])
		elif y == '1':
			c += 1
			ans.append([2, 1])
	elif w == '0' and z == '0':
		if x == '0':
			c += 1
			ans.append([1, 2])
		elif y == '0':
			c += 1
			ans.append([2, 1])
	elif w == '1' and z == '0':
		c += 1
		ans.append([n - 1, n])
		if x == '1':
			c += 1
			ans.append([1, 2])
		else:
			c += 1
			ans.append([2, 1])
	else:
		c += 1
		ans.append([n - 1, n])
		if x == '0':
			c += 1
			ans.append([1, 2])
		else:
			c += 1
			ans.append([2, 1])
	if c == 0:
		print(0)
	elif c == 1:
		print(1)
		print(*ans[0])
	else:
		print(2)
		ans.sort()
		print(*ans[0])
		print(*ans[1])


from math import *
import sys
from sys import stdin
from sys import stdout
for __ in range(int(input())):
	n = int(input())
	ar = []
	for i in range(n):
		ar.append(input())
	a = ar[0][1]
	b = ar[1][0]
	x = ar[n - 1][n - 2]
	y = ar[n - 2][n - 1]
	if a == b and x == y and (a != x):
		print(0)
	elif a == b == x == y:
		print(2)
		print(1, 2)
		print(2, 1)
	elif a != b and x != y:
		print(2)
		if a == x:
			print(1, 2)
			print(n - 1, n)
		else:
			print(1, 2)
			print(n, n - 1)
	elif a != b and x == y:
		print(1)
		if a == x:
			print(1, 2)
		else:
			print(2, 1)
	elif a == b and x != y:
		print(1)
		if a == x:
			print(n, n - 1)
		else:
			print(n - 1, n)


t = int(input())
for _ in range(t):
	n = int(input())
	l = []
	for i in range(n):
		s = str(input())
		l.append(s)
	try:
		(a, b, c, d) = (l[0][1], l[1][0], l[n - 1][n - 2], l[n - 2][n - 1])
	except:
		print(l)
		break
	arr = [a, b, c, d]
	temp = ['1', '1', '0', '0']
	key = ['0', '0', '1', '1']
	tempc = 0
	keyc = 0
	d = {}
	d[0] = [0, 1]
	d[1] = [1, 0]
	d[2] = [n - 1, n - 2]
	d[3] = [n - 2, n - 1]
	temparr = []
	keyarr = []
	for i in range(4):
		if arr[i] != temp[i]:
			tempc += 1
			temparr.append(i)
		if arr[i] != key[i]:
			keyc += 1
			keyarr.append(i)
	if tempc < keyc:
		print(len(temparr))
		for j in temparr:
			print(d[j][0] + 1, d[j][1] + 1)
	else:
		print(len(keyarr))
		for j in keyarr:
			print(d[j][0] + 1, d[j][1] + 1)


import sys
from collections import defaultdict as dd
from collections import Counter as cc
from queue import Queue
import math
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
for _ in range(int(input())):
	q = int(input())
	a = []
	for i in range(q):
		a.append(input())
	w = []
	if a[0][1] == '1':
		if a[1][0] == '1':
			if a[q - 1][q - 2] == '1':
				w.append([q, q - 1])
			if a[q - 2][q - 1] == '1':
				w.append([q - 1, q])
		elif a[q - 1][q - 2] == '1' and a[q - 2][q - 1] == '1':
			w.append([1, 2])
		elif a[q - 1][q - 2] == '1':
			w.append([2, 1])
			w.append([q, q - 1])
		elif a[q - 2][q - 1] == '1':
			w.append([2, 1])
			w.append([q - 1, q])
		else:
			w.append([2, 1])
	elif a[1][0] == '1':
		if a[q - 1][q - 2] == '1' and a[q - 2][q - 1] == '1':
			w.append([2, 1])
		elif a[q - 1][q - 2] == '1':
			w.append([1, 2])
			w.append([q, q - 1])
		elif a[q - 2][q - 1] == '1':
			w.append([1, 2])
			w.append([q - 1, q])
		else:
			w.append([1, 2])
	else:
		if a[q - 1][q - 2] == '0':
			w.append([q, q - 1])
		if a[q - 2][q - 1] == '0':
			w.append([q - 1, q])
	print(len(w))
	for i in w:
		print(*i)


def solve():
	n = int(input())
	grid = []
	for i in range(0, n):
		grid.append([x for x in input()])
	a = grid[0][1]
	b = grid[1][0]
	c = grid[n - 1][n - 2]
	d = grid[n - 2][n - 1]
	changes = []
	change = 0
	if a == b:
		if c == a:
			change += 1
			changes.append((n, n - 1))
		if d == a:
			change += 1
			changes.append((n - 1, n))
	elif d == c:
		change += 1
		if b == c:
			changes.append((2, 1))
		else:
			changes.append((1, 2))
	else:
		change += 2
		if a != c:
			changes.append((1, 2))
			changes.append((n, n - 1))
		elif a != d:
			changes.append((1, 2))
			changes.append((n - 1, n))
		elif b != c:
			changes.append((2, 1))
			changes.append((n, n - 1))
		else:
			changes.append((2, 1))
			changes.append((n - 1, n))
	print(change)
	for x in changes:
		print(x[0], x[1])
	return

def main():
	t = int(input())
	for i in range(t):
		solve()
	return
main()


t = int(input())
for _ in range(t):
	n = int(input())
	row = [None] * n
	for i in range(n):
		row[i] = input()
	(a_1, a_2) = ([row[0][1], row[1][0]], [row[n - 2][n - 1], row[n - 1][n - 2]])
	if a_1 == ['0', '0']:
		c = 2 - a_2.count('1')
		print(c)
		if c != 0:
			if a_2[0] != '1':
				print(f'{n - 1} {n}')
			if a_2[1] != '1':
				print(f'{n} {n - 1}')
	elif a_1 == ['1', '1']:
		c = 2 - a_2.count('0')
		print(c)
		if c != 0:
			if a_2[0] != '0':
				print(f'{n - 1} {n}')
			if a_2[1] != '0':
				print(f'{n} {n - 1}')
	elif a_2 == ['0', '0']:
		c = 2 - a_1.count('1')
		print(c)
		if c != 0:
			if a_1[0] != '1':
				print('1 2')
			if a_1[1] != '1':
				print('2 1')
	elif a_2 == ['1', '1']:
		c = 2 - a_1.count('0')
		print(c)
		if c != 0:
			if a_1[0] != '0':
				print('1 2')
			if a_1[1] != '0':
				print('2 1')
	else:
		print(2)
		print('1 2')
		if a_1[0] != a_2[0]:
			print(f'{n - 1} {n}')
		else:
			print(f'{n} {n - 1}')


for i1 in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		a.append(input())
	x = a[0][1]
	y = a[1][0]
	w = a[-1][-2]
	z = a[-2][-1]
	ans = []
	if x == y:
		if w == z:
			if w != x:
				pass
			else:
				ans.append((n, n - 1))
				ans.append((n - 1, n))
		elif w == x:
			ans.append((n, n - 1))
		else:
			ans.append((n - 1, n))
	elif w == z:
		if w == x:
			ans.append((1, 2))
		else:
			ans.append((2, 1))
	elif x == w:
		ans.append((1, 2))
		ans.append((n - 1, n))
	else:
		ans.append((1, 2))
		ans.append((n, n - 1))
	print(len(ans))
	for (l, r) in ans:
		print(l, r)


from collections import *
from itertools import *
from bisect import *

def inp():
	return int(input())

def arrinp():
	return [int(x) for x in input().split()]

def main():
	t = inp()
	for _ in range(t):
		n = inp()
		grid = []
		for i in range(n):
			grid.append([x for x in input()])
		(x, y) = (grid[1][0], grid[0][1])
		(p, q) = (grid[n - 1][n - 2], grid[n - 2][n - 1])
		ans_coordinates = []
		ans = 0
		if x == y:
			if x == '0':
				if p != '1':
					ans += 1
					ans_coordinates.append([n, n - 1])
				if q != '1':
					ans += 1
					ans_coordinates.append([n - 1, n])
			elif x == '1':
				if p != '0':
					ans += 1
					ans_coordinates.append([n, n - 1])
				if q != '0':
					ans += 1
					ans_coordinates.append([n - 1, n])
		elif x != y:
			if p == q:
				if p == '0':
					if x == '0' and y == '1':
						ans += 1
						ans_coordinates.append([2, 1])
					elif x == '1' and y == '0':
						ans += 1
						ans_coordinates.append([1, 2])
				elif p == '1':
					if x == '0' and y == '1':
						ans += 1
						ans_coordinates.append([1, 2])
					elif x == '1' and y == '0':
						ans += 1
						ans_coordinates.append([2, 1])
			elif p != q:
				if x == '1' and y == '0':
					ans += 1
					ans_coordinates.append([1, 2])
				elif x == '0' and y == '1':
					ans += 1
					ans_coordinates.append([2, 1])
				if p == '1' and q == '0':
					ans += 1
					ans_coordinates.append([n, n - 1])
				elif p == '0' and q == '1':
					ans += 1
					ans_coordinates.append([n - 1, n])
		print(ans)
		for co in ans_coordinates:
			print(*co, sep=' ')
main()


for _ in range(int(input())):
	n = int(input())
	mat = []
	for i in range(n):
		mat.append(input())
	res = []
	start = 0
	end = 0
	if mat[0][1] == mat[1][0] == mat[n - 1][n - 2] == mat[n - 2][n - 1]:
		print(2)
		print(1, 2)
		print(2, 1)
	elif mat[0][1] == mat[1][0] == mat[n - 1][n - 2] and mat[n - 1][n - 2] != mat[n - 2][n - 1]:
		print(1)
		print(n, n - 1)
	elif mat[0][1] == mat[1][0] == mat[n - 2][n - 1] and mat[n - 1][n - 2] != mat[n - 2][n - 1]:
		print(1)
		print(n - 1, n)
	elif mat[1][0] == mat[n - 1][n - 2] == mat[n - 2][n - 1] and mat[0][1] != mat[1][0]:
		print(1)
		print(2, 1)
	elif mat[0][1] == mat[n - 1][n - 2] == mat[n - 2][n - 1] and mat[0][1] != mat[1][0]:
		print(1)
		print(1, 2)
	elif mat[0][1] == mat[1][0] and mat[n - 1][n - 2] == mat[n - 2][n - 1]:
		print(0)
	elif mat[0][1] == mat[n - 2][n - 1] and mat[1][0] == mat[n - 1][n - 2]:
		print(2)
		print(1, 2)
		print(n, n - 1)
	elif mat[0][1] == mat[n - 1][n - 2] and mat[n - 2][n - 1] == mat[1][0]:
		print(2)
		print(1, 2)
		print(n - 1, n)


k = int(input())
for i in range(k):
	n = int(input())
	for j in range(1, n + 1):
		str = input()
		if j == 1:
			point_l1 = str[1]
		if j == 2:
			point_l2 = str[0]
		if j == n - 1:
			point_r1 = str[len(str) - 1]
		if j == n:
			point_r2 = str[len(str) - 2]
	if point_l1 == point_l2 and point_r1 == point_r2 and (point_l1 != point_r1):
		print(0)
	elif point_l1 == point_l2 and point_r1 == point_r2 and (point_l1 == point_r1):
		print(2)
		print(1, 2)
		print(2, 1)
	elif point_l1 != point_l2 and point_r1 != point_r2 and (point_l1 == point_r1):
		print(2)
		print(1, 2)
		print(len(str), len(str) - 1)
	elif point_l1 != point_l2 and point_r1 != point_r2 and (point_l1 == point_r2):
		print(2)
		print(1, 2)
		print(len(str) - 1, len(str))
	elif point_l1 != point_l2 and point_l1 == point_r1 and (point_r1 == point_r2):
		print(1)
		print(1, 2)
	elif point_l1 != point_l2 and point_l2 == point_r1 and (point_r1 == point_r2):
		print(1)
		print(2, 1)
	elif point_r1 != point_r2 and point_l2 == point_r1 and (point_l1 == point_l2):
		print(1)
		print(len(str) - 1, len(str))
	elif point_r1 != point_r2 and point_l2 == point_r2 and (point_l1 == point_l2):
		print(1)
		print(len(str), len(str) - 1)


import sys
import math
from functools import reduce
import bisect

def getN():
	return int(input())

def getNM():
	return map(int, input().split())

def getList():
	return list(map(int, input().split()))

def input():
	return sys.stdin.readline().rstrip()

def index(a, x):
	i = bisect.bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	return False
for _ in range(getN()):
	n = getN()
	s = []
	for _ in range(n):
		s.append(list(input()))
	if {s[0][1], s[1][0]} == {s[n - 1][n - 2], s[n - 2][n - 1]} and len({s[0][1], s[1][0]}) == 1 and (len({s[n - 1][n - 2], s[n - 2][n - 1]}) == 1):
		print(2)
		print('1 2')
		print('2 1')
	elif s[0][1] != s[1][0] and s[n - 1][n - 2] != s[n - 2][n - 1]:
		if s[0][1] == s[n - 2][n - 1] and s[1][0] == s[n - 1][n - 2]:
			print(2)
			print('1 2')
			print(f'{n} {n - 1}')
		elif s[0][1] != s[n - 2][n - 1] and s[1][0] != s[n - 1][n - 2]:
			print(2)
			print('1 2')
			print(f'{n - 1} {n}')
	elif {s[0][1], s[1][0]} != {s[n - 1][n - 2], s[n - 2][n - 1]} and len({s[0][1], s[1][0]}) == 1 and (len({s[n - 1][n - 2], s[n - 2][n - 1]}) == 1):
		print(0)
	else:
		if s[0][1] == s[n - 1][n - 2] == s[n - 2][n - 1]:
			print(1)
			print(1, 2)
		elif s[1][0] == s[n - 1][n - 2] == s[n - 2][n - 1]:
			print(1)
			print(2, 1)
		if s[n - 1][n - 2] == s[0][1] == s[1][0]:
			print(1)
			print(f'{n} {n - 1}')
		elif s[n - 2][n - 1] == s[0][1] == s[1][0]:
			print(1)
			print(f'{n - 1} {n}')


for _ in range(int(input())):
	n = int(input())
	l = []
	for i in range(n):
		l.append(list(input()))
	e = [l[0][1], l[1][0], l[n - 2][n - 1], l[n - 1][n - 2]]
	pos = [[1, 2], [2, 1], [n - 1, n], [n, n - 1]]
	moves = 0
	ans = []
	if e[0] == e[1]:
		if e[2] == e[3]:
			if e[0] == e[2]:
				moves = 2
				ans.append(pos[2])
				ans.append(pos[3])
			else:
				moves = 0
		else:
			moves = 1
			if e[2] == e[0]:
				ans.append(pos[2])
			else:
				ans.append(pos[3])
	elif e[2] == e[3]:
		moves = 1
		if e[0] == e[2]:
			ans.append(pos[0])
		else:
			ans.append(pos[1])
	else:
		moves = 2
		ans.append(pos[1])
		if e[2] == e[0]:
			ans.append(pos[2])
		else:
			ans.append(pos[3])
	print(moves)
	for i in ans:
		print(*i)


def mySolver(li, grid):
	g1 = int(li[0][0][1])
	g2 = int(li[1][0][0])
	g3 = int(li[grid - 2][0][grid - 1])
	g4 = int(li[grid - 1][0][grid - 2])
	count = 0
	ans = []
	if g2 == g1 and g3 == g4:
		if g1 == g3:
			ans.append([1, 2])
			ans.append([2, 1])
	elif g2 != g1 and g3 == g4:
		if g2 == g3:
			ans.append([2, 1])
		else:
			ans.append([1, 2])
	elif g2 == g1 and g3 != g4:
		if g3 == g2:
			ans.append([grid - 1, grid])
		else:
			ans.append([grid, grid - 1])
	elif g3 == g2:
		ans.append([1, 2])
		ans.append([grid - 1, grid])
	else:
		ans.append([2, 1])
		ans.append([grid - 1, grid])
	if not ans:
		print('0')
	else:
		print(len(ans))
		for i in ans:
			print(i[0], i[1])

def main():
	case = int(input())
	for i in range(0, case):
		grid = int(input())
		li = []
		for j in range(grid):
			li.append(list(map(str, input().split())))
		mySolver(li, grid)
main()


t = int(input())
while t:
	t += -1
	n = int(input())
	l = []
	for i in range(n):
		tmp = list(input())
		l.append(tmp)
	if l[n - 1][n - 2] == l[n - 2][n - 1]:
		if l[1][0] == l[0][1]:
			if l[1][0] == l[n - 1][n - 2]:
				print(2)
				print(2, 1)
				print(1, 2)
			else:
				print(0)
		elif l[1][0] == l[n - 1][n - 2]:
			print(1)
			print(2, 1)
		else:
			print(1)
			print(1, 2)
	elif l[0][1] == l[1][0]:
		if l[n - 1][n - 2] == l[0][1]:
			print(1)
			print(n, n - 1)
		else:
			print(1)
			print(n - 1, n)
	elif l[0][1] == l[n - 1][n - 2]:
		print(2)
		print(1, 2)
		print(n - 1, n)
	elif l[0][1] == l[n - 2][n - 1]:
		print(2)
		print(1, 2)
		print(n, n - 1)


import itertools
import sys
from typing import List
sys.setrecursionlimit(10 ** 9)

def lmi():
	return list(map(int, input().split()))

def main():
	for _ in range(int(input())):
		n = int(input())
		grid = [list(input()) for _ in range(n)]
		result = solve(n, grid)
		print(len(result))
		for point in result:
			print(*point)

def solve(n, grid) -> list:
	for pattern in itertools.product([False, True], repeat=4):
		if pattern[0]:
			grid[n - 1][n - 2] = reverse(grid[n - 1][n - 2])
		if pattern[1]:
			grid[n - 2][n - 1] = reverse(grid[n - 2][n - 1])
		if pattern[2]:
			grid[0][1] = reverse(grid[0][1])
		if pattern[3]:
			grid[1][0] = reverse(grid[1][0])
		ok = True
		for digit in ['0', '1']:
			stack = [(0, 0)]
			visited = set()
			while stack:
				(y, x) = stack.pop()
				if y < 0 or n <= y or x < 0 or (n <= x):
					continue
				if (y, x) in visited:
					continue
				if grid[y][x] == 'F':
					ok = False
					break
				if grid[y][x] not in (digit, 'S'):
					continue
				visited.add((y, x))
				for (yd, xd) in ((-1, 0), (+1, 0), (0, -1), (0, +1)):
					i = y + yd
					j = x + xd
					stack.append((i, j))
		if ok:
			ans = []
			if pattern[0]:
				ans.append((n, n - 1))
			if pattern[1]:
				ans.append((n - 1, n))
			if pattern[2]:
				ans.append((1, 2))
			if pattern[3]:
				ans.append((2, 1))
			return ans
		if pattern[0]:
			grid[n - 1][n - 2] = reverse(grid[n - 1][n - 2])
		if pattern[1]:
			grid[n - 2][n - 1] = reverse(grid[n - 2][n - 1])
		if pattern[2]:
			grid[0][1] = reverse(grid[0][1])
		if pattern[3]:
			grid[1][0] = reverse(grid[1][0])

def reverse(digit):
	if digit == '0':
		return '1'
	else:
		return '0'
main()


t = int(input())
for i in range(t):
	n = int(input())
	b = []
	for j in range(n):
		s = input()
		b.append(s)
	(p, q) = (int(b[0][1]), int(b[1][0]))
	(r, s) = (int(b[-1][-2]), int(b[-2][-1]))
	ans = []
	if p == q:
		if r == p:
			ans.append([n, n - 1])
		if s == p:
			ans.append([n - 1, n])
	elif r == s:
		if p == r:
			ans.append([1, 2])
		if q == r:
			ans.append([2, 1])
	else:
		ans.append([2, 1])
		if r == p:
			ans.append([n, n - 1])
		if s == p:
			ans.append([n - 1, n])
	print(len(ans))
	for j in ans:
		print(*j)


for _ in range(int(input())):
	N = int(input())
	grid = []
	for i in range(N):
		grid.append(list(input()))
	if grid[1][0] == grid[0][1] and grid[N - 2][N - 1] == grid[N - 1][N - 2] and (grid[1][0] != grid[N - 2][N - 1]):
		print(0)
	elif grid[1][0] == grid[0][1] and grid[N - 2][N - 1] == grid[N - 1][N - 2] and (grid[1][0] == grid[N - 2][N - 1]):
		print(2)
		print(1, 2)
		print(2, 1)
	elif grid[1][0] != grid[0][1] and grid[N - 2][N - 1] != grid[N - 1][N - 2]:
		if grid[1][0] == grid[N - 2][N - 1]:
			print(2)
			print(2, 1)
			print(N, N - 1)
		else:
			print(2)
			print(2, 1)
			print(N - 1, N)
	else:
		print(1)
		tobechecked = [grid[1][0], grid[0][1], grid[N - 2][N - 1], grid[N - 1][N - 2]]
		frequency = {}
		for i in tobechecked:
			if i in frequency:
				frequency[i] += 1
			else:
				frequency[i] = 1
		for i in frequency:
			if frequency[i] == 1:
				death = i
		for i in range(4):
			if tobechecked[i] == death:
				if i == 0:
					print(1, 2)
				elif i == 1:
					print(2, 1)
				elif i == 2:
					print(N, N - 1)
				else:
					print(N - 1, N)


ts = int(input())
for t in range(ts):
	n = int(input())
	l1 = []
	if n == 3:
		for j in range(n):
			l1.append(input())
		la = [int(l1[0][1]), int(l1[1][0]), int(l1[n - 1][n - 2]), int(l1[n - 2][n - 1])]
	else:
		l1.append(input())
		l1.append(input())
		for j in range(n - 4):
			axw = input()
		l1.append(input())
		l1.append(input())
		la = [int(l1[0][1]), int(l1[1][0]), int(l1[-1][-2]), int(l1[-2][-1])]
	l = ['1 2', '2 1', str(n) + ' ' + str(n - 1), str(n - 1) + ' ' + str(n)]
	if sum(la) in [0, 4]:
		print(2)
		print(l[0])
		print(l[1])
	elif sum(la) == 1:
		print(1)
		if sum(la[:2]) == 1:
			if la[0] == 0:
				print(l[0])
			else:
				print(l[1])
		elif la[2] == 0:
			print(l[2])
		else:
			print(l[3])
	elif sum(la) == 3:
		print(1)
		if sum(la[:2]) == 1:
			if la[0] == 1:
				print(l[0])
			else:
				print(l[1])
		elif la[2] == 1:
			print(l[2])
		else:
			print(l[3])
	elif sum(la) == 2:
		if sum(la[:2]) in [0, 2]:
			print(0)
		else:
			print(2)
			if la[0] == 1:
				print(l[0])
			else:
				print(l[1])
			if la[3] == 0:
				print(l[3])
			else:
				print(l[2])


import sys

def main(stream=sys.stdin):
	t = int(stream.readline())
	for _ in range(t):
		n = int(stream.readline())
		data = []
		for i in range(n):
			data.append([str(c) for c in stream.readline()])
		s = [data[0][1], data[1][0]]
		f = [data[n - 1][n - 2], data[n - 2][n - 1]]
		beg = s[0]
		end = str(1 - int(beg))
		if s[0] == s[1]:
			beg = s[0]
			end = str(1 - int(beg))
		elif f[0] == f[1]:
			end = f[0]
			beg = str(1 - int(end))
		points = []
		for i in range(2):
			for j in range(2):
				if i == j:
					continue
				if data[i][j] != beg:
					points.append((i + 1, j + 1))
				if data[n - i - 1][n - j - 1] != end:
					points.append((n - i, n - j))
		print(len(points))
		for p in points:
			print('{} {}'.format(*p))
main()


for _ in range(int(input())):
	n = int(input())
	l = [input() for i in range(n)]
	if l[0][1] == l[1][0]:
		if l[-1][-2] == l[-2][-1]:
			if l[-1][-2] != l[1][0]:
				print(0)
			else:
				print(2)
				print(1, 2)
				print(2, 1)
		elif l[0][1] == l[-1][-2]:
			print(1)
			print(n, n - 1)
		else:
			print(1)
			print(n - 1, n)
	elif l[-1][-2] == l[-2][-1]:
		if l[0][1] == l[-1][-2]:
			print(1)
			print(1, 2)
		else:
			print(1)
			print(2, 1)
	elif l[0][1] == l[-1][-2]:
		print(2)
		print(1, 2)
		print(n - 1, n)
	else:
		print(2)
		print(1, 2)
		print(n, n - 1)


import sys
T = int(input())
for _ in range(T):
	n = int(input())
	A = []
	for i in range(n):
		A.append(input())
	(a1, b1) = (int(A[0][1]), int(A[1][0]))
	(a2, b2) = (int(A[n - 1][n - 2]), int(A[n - 2][n - 1]))
	if a1 == b1:
		c = 0
		ans = []
		if a2 == a1:
			c = c + 1
			ans.append([n, n - 1])
		if b2 == a1:
			c = c + 1
			ans.append([n - 1, n])
		print(c)
		for i in ans:
			print(*i)
	elif a2 == b2:
		c = 0
		ans = []
		if a2 == a1:
			c = c + 1
			ans.append([1, 2])
		if b2 == b1:
			c = c + 1
			ans.append([2, 1])
		print(c)
		for i in ans:
			print(*i)
	else:
		c = 0
		ans = []
		if a1 == 1:
			c = c + 1
			ans.append([1, 2])
		if b1 == 1:
			c = c + 1
			ans.append([2, 1])
		if a2 == 0:
			c = c + 1
			ans.append([n, n - 1])
		if b2 == 0:
			c = c + 1
			ans.append([n - 1, n])
		print(c)
		for i in ans:
			print(*i)


def ans(N, grid):
	grid = [list(row) for row in grid]
	a = grid[0][1]
	b = grid[1][0]
	c = grid[N - 2][N - 1]
	d = grid[N - 1][N - 2]
	a = int(a)
	b = int(b)
	c = int(c)
	d = int(d)

	def flipa():
		grid[0][1] = 1 - a
		print(1, 2)

	def flipb():
		grid[1][0] = 1 - b
		print(2, 1)

	def flipc():
		grid[N - 2][N - 1] = 1 - c
		print(N - 1, N)

	def flipd():
		grid[N - 1][N - 2] = 1 - d
		print(N, N - 1)

	def check():
		a = grid[0][1]
		b = grid[1][0]
		c = grid[N - 2][N - 1]
		d = grid[N - 1][N - 2]
		a = int(a)
		b = int(b)
		c = int(c)
		d = int(d)
		assert a == b
		assert c == d
		assert b != c
	if a == b and c == d:
		if b == c:
			print(2)
			flipa()
			flipb()
			check()
			return
		else:
			print(0)
			check()
			return
	if a == b:
		if c == a:
			print(1)
			flipc()
			check()
			return
		elif d == a:
			print(1)
			flipd()
			check()
			return
		else:
			assert False
	if c == d:
		if a == c:
			print(1)
			flipa()
			check()
			return
		elif b == c:
			print(1)
			flipb()
			check()
			return
	if a == d:
		assert b == c
		print(2)
		flipa()
		flipc()
		check()
		return
	if a == c:
		assert b == d
		print(2)
		flipa()
		flipd()
		check()
		return
	assert False

def random_grid():
	import random
	return [['S', random.choice('01'), random.choice('01')], [random.choice('01'), random.choice('01'), random.choice('01')], [random.choice('01'), random.choice('01'), 'F']]
for _ in range(int(input())):
	N = int(input())
	grid = []
	for _ in range(N):
		row = input()
		grid += [row]
	ans(N, grid)


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	A = []
	for _ in range(n):
		A.append(sys.stdin.readline().strip())
	a = A[0][1]
	b = A[1][0]
	c = A[-1][-2]
	d = A[-2][-1]
	cells = []
	if a == b:
		if c == a:
			cells.append((n, n - 1))
		if d == a:
			cells.append((n - 1, n))
	elif c == d:
		if a == c:
			cells.append((1, 2))
		else:
			cells.append((2, 1))
	else:
		cells.append((1, 2))
		if b == c:
			cells.append((n, n - 1))
		else:
			cells.append((n - 1, n))
	print(len(cells))
	for cell in cells:
		print(cell[0], cell[1])


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
from typing import List

def solve(A, N):
	a = [(0, 1), (1, 0)]
	b = [(N - 1, N - 2), (N - 2, N - 1)]
	for (x, y) in [(0, 1), (1, 0)]:
		invert = 0
		for (r, c) in a:
			if A[r][c] != x:
				invert += 1
		for (r, c) in b:
			if A[r][c] != y:
				invert += 1
		if invert <= 2:
			print(invert)
			for (r, c) in a:
				if A[r][c] != x:
					print('{} {}'.format(r + 1, c + 1))
			for (r, c) in b:
				if A[r][c] != y:
					print('{} {}'.format(r + 1, c + 1))
			return
T = int(input())
for _ in range(T):
	N = int(input())
	A = []
	for _ in range(N):
		row = [int(x) if x not in {'S', 'F'} else 0 for x in input()]
		A.append(row)
	solve(A, N)


tc = int(input())
for _ in range(tc):
	n = int(input())
	mat = []
	for i in range(n):
		x = input()
		mat.append([j for j in x])
	count = []
	if mat[1][0] == mat[0][1]:
		if mat[n - 1][n - 2] == mat[n - 2][n - 1]:
			if mat[1][0] == mat[n - 1][n - 2]:
				count.append([1, 2])
				count.append([2, 1])
		elif mat[n - 1][n - 2] == mat[1][0]:
			count.append([n, n - 1])
		else:
			count.append([n - 1, n])
	elif mat[n - 1][n - 2] == mat[n - 2][n - 1]:
		if mat[0][1] == mat[n - 1][n - 2]:
			count.append([1, 2])
		else:
			count.append([2, 1])
	elif mat[n - 1][n - 2] == mat[1][0]:
		count.append([1, 2])
		count.append([n, n - 1])
	else:
		count.append([1, 2])
		count.append([n - 1, n])
	print(len(count))
	for i in count:
		print(i[0], i[1])


T = int(input())
for t in range(T):
	n = int(input())
	g = [input() for i in range(n)]
	(a, b, c, d) = (g[0][1], g[1][0], g[-1][-2], g[-2][-1])
	ans = 0
	if a == b == '0' and c == d == '1':
		ans = 0
		print(0)
	elif a == b == '1' and c == d == '0':
		ans = 0
		print(ans)
	elif a == b == c == d:
		ans = 2
		print(ans)
		print(1, 2)
		print(2, 1)
	elif a != b and c != d:
		if a == c:
			print(2)
			print(2, 1)
			print(n, n - 1)
		elif a == d:
			print(2)
			print(2, 1)
			print(n - 1, n)
	elif a != b and c == d:
		ans = 1
		print(ans)
		if a == c:
			print(1, 2)
		else:
			print(2, 1)
	elif a == b and c != d:
		ans = 1
		print(ans)
		if a == c:
			print(n, n - 1)
		else:
			print(n - 1, n)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [input() for i in range(n)]
	a = arr[0][1]
	b = arr[1][0]
	c = arr[n - 2][n - 1]
	d = arr[n - 1][n - 2]
	if a == b:
		ans = []
		if c == a:
			ans.append([n - 1, n])
		if d == a:
			ans.append([n, n - 1])
		print(len(ans))
		for item in ans:
			print(item[0], item[1])
	elif c == d:
		ans = []
		if c == a:
			ans.append([1, 2])
		if c == b:
			ans.append([2, 1])
		print(len(ans))
		for item in ans:
			print(item[0], item[1])
	elif a == c and b == d:
		print(2)
		print(1, 2)
		print(n, n - 1)
	else:
		print(2)
		print(2, 1)
		print(n, n - 1)


for _ in range(int(input())):
	n = int(input())
	grid = [input() for i in range(n)]
	(a, b, c, d) = (grid[0][1], grid[1][0], grid[-2][-1], grid[-1][-2])
	e = []
	f = []
	if a != '0':
		e.append((1, 2))
	if b != '0':
		e.append((2, 1))
	if c != '1':
		e.append((n - 1, n))
	if d != '1':
		e.append((n, n - 1))
	if c != '0':
		f.append((n - 1, n))
	if d != '0':
		f.append((n, n - 1))
	if a != '1':
		f.append((1, 2))
	if b != '1':
		f.append((2, 1))
	if len(e) < len(f):
		print(len(e))
		for i in e:
			print(*i)
	else:
		print(len(f))
		for i in f:
			print(*i)


cases = int(input())
for _ in range(cases):
	n = int(input())
	s = []
	for i in range(n):
		s.append(list(input()))
	l1 = [s[0][1], s[1][0]]
	l2 = [s[n - 2][n - 1], s[n - 1][n - 2]]
	if l1[0] == '0' and l1[1] == '0' and (l2[0] == '0') and (l2[1] == '0'):
		print(2)
		print(0 + 1, 1 + 1)
		print(1 + 1, 0 + 1)
	if l1[0] == '0' and l1[1] == '1' and (l2[0] == '0') and (l2[1] == '0'):
		print(1)
		print(0 + 1, 1 + 1)
	if l1[0] == '1' and l1[1] == '0' and (l2[0] == '0') and (l2[1] == '0'):
		print(1)
		print(1 + 1, 0 + 1)
	if l1[0] == '1' and l1[1] == '1' and (l2[0] == '0') and (l2[1] == '0'):
		print(0)
	if l1[0] == '0' and l1[1] == '0' and (l2[0] == '0') and (l2[1] == '1'):
		print(1)
		print(n - 2 + 1, n - 1 + 1)
	if l1[0] == '0' and l1[1] == '1' and (l2[0] == '0') and (l2[1] == '1'):
		print(2)
		print(0 + 1, 1 + 1)
		print(n - 1 + 1, n - 2 + 1)
	if l1[0] == '1' and l1[1] == '0' and (l2[0] == '0') and (l2[1] == '1'):
		print(2)
		print(0 + 1, 1 + 1)
		print(n - 2 + 1, n - 1 + 1)
	if l1[0] == '1' and l1[1] == '1' and (l2[0] == '0') and (l2[1] == '1'):
		print(1)
		print(n - 1 + 1, n - 2 + 1)
	if l1[0] == '0' and l1[1] == '0' and (l2[0] == '1') and (l2[1] == '0'):
		print(1)
		print(n - 1 + 1, n - 2 + 1)
	if l1[0] == '0' and l1[1] == '1' and (l2[0] == '1') and (l2[1] == '0'):
		print(2)
		print(0 + 1, 1 + 1)
		print(n - 2 + 1, n - 1 + 1)
	if l1[0] == '1' and l1[1] == '0' and (l2[0] == '1') and (l2[1] == '0'):
		print(2)
		print(0 + 1, 1 + 1)
		print(n - 1 + 1, n - 2 + 1)
	if l1[0] == '1' and l1[1] == '1' and (l2[0] == '1') and (l2[1] == '0'):
		print(1)
		print(n - 2 + 1, n - 1 + 1)
	if l1[0] == '0' and l1[1] == '0' and (l2[0] == '1') and (l2[1] == '1'):
		print(0)
	if l1[0] == '0' and l1[1] == '1' and (l2[0] == '1') and (l2[1] == '1'):
		print(1)
		print(1 + 1, 0 + 1)
	if l1[0] == '1' and l1[1] == '0' and (l2[0] == '1') and (l2[1] == '1'):
		print(1)
		print(0 + 1, 1 + 1)
	if l1[0] == '1' and l1[1] == '1' and (l2[0] == '1') and (l2[1] == '1'):
		print(2)
		print(0 + 1, 1 + 1)
		print(1 + 1, 0 + 1)


t = int(input())
for i in range(0, t):
	n = int(input())
	a = []
	for j in range(0, n):
		b = input()
		q = [b[k] for k in range(0, n)]
		a.append(q)
	if n != 0:
		c = [a[0][1], a[1][0], a[n - 1][n - 2], a[n - 2][n - 1]]
		x1 = int(a[0][1]) + int(a[1][0])
		x2 = int(a[n - 1][n - 2]) + int(a[n - 2][n - 1])
		if x1 == 2:
			if x2 == 0:
				print(0)
				continue
			if x2 == 2:
				print(2)
				print(n, n - 1)
				print(n - 1, n)
				continue
			if x2 == 1:
				if c[2] == '1':
					print(1)
					print(n, n - 1)
					continue
				if c[3] == '1':
					print(1)
					print(n - 1, n)
					continue
		if x1 == 0:
			if x2 == 2:
				print(0)
				continue
			if x2 == 0:
				print(2)
				print(n - 0, n - 1)
				print(n - 1, n - 0)
				continue
			if x2 == 1:
				if c[2] == '0':
					print(1)
					print(n - 0, n - 1)
					continue
				if c[3] == '0':
					print(1)
					print(n - 1, n)
					continue
		if x2 == 0:
			if x1 == 2:
				print(0)
				continue
			if x1 == 0:
				print(2)
				print(1, 2)
				print(2, 1)
				continue
			if x1 == 1:
				if c[0] == '0':
					print(1)
					print(1, 2)
					continue
				if c[1] == '0':
					print(1)
					print(2, 1)
					continue
		if x2 == 2:
			if x1 == 0:
				print(0)
				continue
			if x1 == 2:
				print(2)
				print(1, 2)
				print(2, 1)
				continue
			if x1 == 1:
				if c[0] == '1':
					print(1)
					print(1, 2)
					continue
				if c[1] == '1':
					print(1)
					print(2, 1)
					continue
		if x1 == 1 and x2 == 1:
			print(2)
			if c[0] == '1':
				print(1, 2)
			if c[1] == '1':
				print(2, 1)
			if c[2] == '0':
				print(n, n - 1)
			if c[3] == '0':
				print(n - 1, n - 0)
	else:
		print(0)


I = input
exec(int(I()) * "n=int(I());a=[[*map(ord,I())]for _ in[0]*n];a=a[0][1],a[1][0],a[-2][-1]^1,a[-1][-2]^1;a=*zip(map(a.count,a),a,('1 2','2 1',f'{n-1} {n}',f'{n} {n-1}')),;r=[z for x,y,z in a if y!=max(a)[1]];print(len(r),*r);")


import sys
import math
from collections import defaultdict, deque
input = sys.stdin.readline

def inar():
	return [int(el) for el in input().split()]

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		matrix = []
		for i in range(n):
			matrix.append(input().strip())
		count1 = 0
		ans1 = []
		if matrix[1][0] != '1':
			count1 += 1
			ans1.append([2, 1])
		if matrix[0][1] != '1':
			count1 += 1
			ans1.append([1, 2])
		if matrix[n - 1][n - 2] != '0':
			count1 += 1
			ans1.append([n, n - 1])
		if matrix[n - 2][n - 1] != '0':
			count1 += 1
			ans1.append([n - 1, n])
		count2 = 0
		ans2 = []
		if matrix[1][0] != '0':
			count2 += 1
			ans2.append([2, 1])
		if matrix[0][1] != '0':
			count2 += 1
			ans2.append([1, 2])
		if matrix[n - 1][n - 2] != '1':
			count2 += 1
			ans2.append([n, n - 1])
		if matrix[n - 2][n - 1] != '1':
			count2 += 1
			ans2.append([n - 1, n])
		if count1 < count2:
			print(len(ans1))
			for i in range(len(ans1)):
				print(*ans1[i])
		else:
			print(len(ans2))
			for i in range(len(ans2)):
				print(*ans2[i])
main()


n = int(input())
for i in range(0, n):
	o = int(input())
	N = 0
	A = 0
	L = []
	B = 0
	C = 0
	D = 0
	for j in range(0, o):
		s = input().rstrip()
		x = list(s)
		if j == 0:
			A = int(x[1])
		if j == 1:
			B = int(x[0])
		if j == o - 2:
			C = int(x[len(x) - 1])
		if j == o - 1:
			D = int(x[len(x) - 2])
	if A == B:
		ans = 0
		if A == 0:
			if C != 1:
				ans += 1
				L.append(o - 1)
				L.append(o)
			if D != 1:
				ans += 1
				L.append(o)
				L.append(o - 1)
		else:
			if C != 0:
				ans += 1
				L.append(o - 1)
				L.append(o)
			if D != 0:
				ans += 1
				L.append(o)
				L.append(o - 1)
	elif C == D:
		ans = 0
		if C == 0:
			if A != 1:
				ans += 1
				L.append(1)
				L.append(2)
			if B != 1:
				ans += 1
				L.append(2)
				L.append(1)
		else:
			if A != 0:
				ans += 1
				L.append(1)
				L.append(2)
			if B != 0:
				ans += 1
				L.append(2)
				L.append(1)
	else:
		ans = 0
		if A == 0:
			ans += 1
			L.append(1)
			L.append(2)
			if C == 1:
				ans += 1
				L.append(o - 1)
				L.append(o)
			else:
				ans += 1
				L.append(o)
				L.append(o - 1)
		else:
			ans += 1
			L.append(1)
			L.append(2)
			if C == 0:
				ans += 1
				L.append(o - 1)
				L.append(o)
			else:
				ans += 1
				L.append(o)
				L.append(o - 1)
	print(ans)
	for j in range(0, len(L), 2):
		print(L[j], L[j + 1])


def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
n = inp()
for _ in range(n):
	x = inp()
	l = []
	for j in range(x):
		l.append(insr())
	if l[0][1] == '1' and l[1][0] == '1' and (l[-1][-2] == '1') and (l[-2][-1] == '1'):
		print(2)
		print('1 2')
		print('2 1')
	elif l[0][1] == '0' and l[1][0] == '0' and (l[-1][-2] == '0') and (l[-2][-1] == '0'):
		print(2)
		print('1 2')
		print('2 1')
	elif l[0][1] == '1' and l[1][0] == '1' and (l[-1][-2] == '0') and (l[-2][-1] == '0'):
		print(0)
	elif l[0][1] == '0' and l[1][0] == '0' and (l[-1][-2] == '1') and (l[-2][-1] == '1'):
		print(0)
	elif l[0][1] == '1' and l[1][0] == '0' and (l[-1][-2] == '1') and (l[-2][-1] == '1'):
		print(1)
		print('1 2')
	elif l[0][1] == '0' and l[1][0] == '1' and (l[-1][-2] == '1') and (l[-2][-1] == '1'):
		print(1)
		print('2 1')
	elif l[0][1] == '1' and l[1][0] == '1' and (l[-1][-2] == '1') and (l[-2][-1] == '0'):
		print(1)
		print(str(x) + ' ' + str(x - 1))
	elif l[0][1] == '1' and l[1][0] == '1' and (l[-1][-2] == '0') and (l[-2][-1] == '1'):
		print(1)
		print(str(x - 1) + ' ' + str(x))
	elif l[0][1] == '0' and l[1][0] == '1' and (l[-1][-2] == '0') and (l[-2][-1] == '0'):
		print(1)
		print('1 2')
	elif l[0][1] == '1' and l[1][0] == '0' and (l[-1][-2] == '0') and (l[-2][-1] == '0'):
		print(1)
		print('2 1')
	elif l[0][1] == '0' and l[1][0] == '0' and (l[-1][-2] == '1') and (l[-2][-1] == '0'):
		print(1)
		print(str(x - 1) + ' ' + str(x))
	elif l[0][1] == '0' and l[1][0] == '0' and (l[-1][-2] == '0') and (l[-2][-1] == '1'):
		print(1)
		print(str(x) + ' ' + str(x - 1))
	elif l[0][1] == '1' and l[1][0] == '0' and (l[-1][-2] == '0') and (l[-2][-1] == '1'):
		print(2)
		print(str(x) + ' ' + str(x - 1))
		print('1 2')
	elif l[0][1] == '0' and l[1][0] == '1' and (l[-1][-2] == '0') and (l[-2][-1] == '1'):
		print(2)
		print(str(x) + ' ' + str(x - 1))
		print('2 1')
	elif l[0][1] == '0' and l[1][0] == '1' and (l[-1][-2] == '1') and (l[-2][-1] == '0'):
		print(2)
		print(str(x) + ' ' + str(x - 1))
		print('1 2')
	elif l[0][1] == '1' and l[1][0] == '0' and (l[-1][-2] == '1') and (l[-2][-1] == '0'):
		print(2)
		print(str(x) + ' ' + str(x - 1))
		print('2 1')


t = int(input())
for j in range(t):
	n = int(input())
	a = ['0'] * n
	for i in range(n):
		a[i] = str(input())
		a[i] = list(a[i])
	if a[0][1] == a[1][0]:
		if a[n - 1][n - 2] == a[n - 2][n - 1]:
			if a[0][1] == a[n - 1][n - 2]:
				print(2)
				if a[0][1] == '0':
					print(0 + 1, 1 + 1)
					print(1 + 1, 0 + 1)
				else:
					print(0 + 1, 1 + 1)
					print(1 + 1, 0 + 1)
			else:
				print(0)
		else:
			print(1)
			if a[0][1] == '0':
				if a[n - 1][n - 2] == '0':
					print(n - 1 + 1, n - 2 + 1)
				else:
					print(n - 2 + 1, n - 1 + 1)
			elif a[n - 1][n - 2] == '1':
				print(n - 1 + 1, n - 2 + 1)
			else:
				print(n - 2 + 1, n - 1 + 1)
	elif a[n - 1][n - 2] == a[n - 2][n - 1]:
		if a[n - 1][n - 2] == '0':
			print(1)
			if a[0][1] == '0':
				print(0 + 1, 1 + 1)
			else:
				print(1 + 1, 0 + 1)
		else:
			print(1)
			if a[0][1] == '1':
				print(0 + 1, 1 + 1)
			else:
				print(1 + 1, 0 + 1)
	else:
		print(2)
		if a[0][1] != a[n - 1][n - 2]:
			print(0 + 1, 1 + 1)
			print(n - 1 + 1, n - 2 + 1)
		else:
			print(0 + 1, 1 + 1)
			print(n - 2 + 1, n - 1 + 1)


import sys
inp = sys.stdin.buffer.readline
inar = lambda : list(map(int, inp().split()))
inin = lambda : int(inp())
inst = lambda : inp().decode().strip()
wrt = sys.stdout.write
pr = lambda *args, end='\n': wrt(' '.join([str(x) for x in args]) + end)
enum = enumerate
inf = float('inf')
cdiv = lambda x, y: -(-x // y)
mod = 1000000007
_T_ = inin()
for _t_ in range(_T_):
	n = inin()
	gr = []
	for i in range(n):
		gr.append(inst())
	p01 = []
	p10 = []
	fr = [(-1, -3), (-2, -2), (-3, -1)]
	sr = [(-1, -2), (-2, -1)]
	for (i, j) in fr:
		if gr[i][j] == '1':
			p01.append((i, j))
		else:
			p10.append((i, j))
	for (i, j) in sr:
		if gr[i][j] == '1':
			p10.append((i, j))
		else:
			p01.append((i, j))
	if len(p01) <= 2 and len(p10) <= 2:
		if len(p01) > len(p10):
			pr(len(p01))
			for (i, j) in p01:
				pr(n + i + 1, n + j + 1)
		else:
			pr(len(p10))
			for (i, j) in p10:
				pr(n + i + 1, n + j + 1)
	elif len(p01) < len(p10):
		pr(len(p01))
		for (i, j) in p01:
			pr(n + i + 1, n + j + 1)
	else:
		pr(len(p10))
		for (i, j) in p10:
			pr(n + i + 1, n + j + 1)


from sys import stdin, stdout
ans = []

def main():
	n = int(stdin.readline())
	arr = [list(stdin.readline())[:-1] for _ in range(n)]
	(sr, sb, fl, ft) = [int(arr[0][1]), int(arr[1][0]), int(arr[-1][-2]), int(arr[-2][-1])]
	count = 0
	sumval = int(sr) + int(sb) + int(fl) + int(ft)
	if sumval == 4 or sumval == 0:
		ans.append(str(2))
		ans.append('1 2')
		ans.append('2 1')
		return
	if sumval == 2:
		if sr == sb:
			ans.append('0')
			return
		if sr == fl:
			ans.append('2')
			ans.append('1 2')
			ans.append(str(n - 1) + ' ' + str(n))
		else:
			ans.append('2')
			ans.append('1 2')
			ans.append(str(n) + ' ' + str(n - 1))
	if sumval == 1 or sumval == 3:
		check = 1 if sumval == 1 else 0
		ans.append('1')
		if sr == check:
			ans.append('2 1')
		if sb == check:
			ans.append('1 2')
		if fl == check:
			ans.append(str(n - 1) + ' ' + str(n))
		if ft == check:
			ans.append(str(n) + ' ' + str(n - 1))
		return
for i in range(int(stdin.readline())):
	main()
stdout.write('\n'.join(ans))


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
t = ip()
for _ in range(t):
	n = ip()
	arr = []
	for i in range(n):
		arr.append(list(ips()))
	path = [arr[0][1], arr[1][0], arr[n - 1][n - 2], arr[n - 2][n - 1]]
	one = path.count('1')
	zero = 4 - one
	ans = []
	if one == 0 and zero == 4:
		ans.append([1, 2])
		ans.append([2, 1])
	elif one == 1 and zero == 3:
		if arr[0][1] == '0' and arr[1][0] == '0':
			if arr[n - 1][n - 2] == '0':
				ans.append([n, n - 1])
			else:
				ans.append([n - 1, n])
		elif arr[0][1] == '0':
			ans.append([1, 2])
		else:
			ans.append([2, 1])
	elif one == 2 and zero == 2:
		if len(set([arr[0][1], arr[1][0]])) == 1:
			pass
		else:
			if arr[0][1] == '1':
				ans.append([1, 2])
			if arr[1][0] == '1':
				ans.append([2, 1])
			if arr[n - 1][n - 2] == '0':
				ans.append([n, n - 1])
			if arr[n - 2][n - 1] == '0':
				ans.append([n - 1, n])
	elif one == 3 and zero == 1:
		if arr[0][1] == '1' and arr[1][0] == '1':
			if arr[n - 1][n - 2] == '1':
				ans.append([n, n - 1])
			else:
				ans.append([n - 1, n])
		elif arr[0][1] == '1':
			ans.append([1, 2])
		else:
			ans.append([2, 1])
	else:
		ans.append([1, 2])
		ans.append([2, 1])
	print(len(ans))
	for i in ans:
		print(*i)


import sys, os.path
from collections import *
from copy import *
import math
import heapq
mod = 10 ** 9 + 7
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for t in range(int(input())):
	n = int(input())
	s = []
	for i in range(n):
		k = input()
		s.append(k)
	a = s[0][1]
	b = s[1][0]
	c = s[n - 2][n - 1]
	d = s[n - 1][n - 2]
	if a == b == '1' and c == d == '0':
		print(0)
	elif a == b == '0' and c == d == '1':
		print(0)
	elif a == '0' and b == '0' and (c == '0') and (d == '0'):
		print(2)
		print(1, 2)
		print(2, 1)
	elif a == '0' and b == '0' and (c == '0') and (d == '1'):
		print(1)
		print(n - 1, n)
	elif a == '0' and b == '0' and (c == '1') and (d == '0'):
		print(1)
		print(n, n - 1)
	elif a == '0' and b == '1' and (c == '0') and (d == '0'):
		print(1)
		print(1, 2)
	elif a == '0' and b == '1' and (c == '0') and (d == '1'):
		print(2)
		print(1, 2)
		print(n, n - 1)
	elif a == '0' and b == '1' and (c == '1') and (d == '0'):
		print(2)
		print(1, 2)
		print(n - 1, n)
	elif a == '0' and b == '1' and (c == '1') and (d == '1'):
		print(1)
		print(2, 1)
	elif a == '1' and b == '0' and (c == '0') and (d == '0'):
		print(1)
		print(2, 1)
	elif a == '1' and b == '0' and (c == '0') and (d == '1'):
		print(2)
		print(2, 1)
		print(n, n - 1)
	elif a == '1' and b == '0' and (c == '1') and (d == '0'):
		print(2)
		print(2, 1)
		print(n - 1, n)
	elif a == '1' and b == '0' and (c == '1') and (d == '1'):
		print(1)
		print(1, 2)
	elif a == '1' and b == '1' and (c == '0') and (d == '1'):
		print(1)
		print(n, n - 1)
	elif a == '1' and b == '1' and (c == '1') and (d == '0'):
		print(1)
		print(n - 1, n)
	elif a == '1' and b == '1' and (c == '1') and (d == '1'):
		print(2)
		print(1, 2)
		print(2, 1)


import sys
from random import *
pl = 1
from copy import *
if pl:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('outpt.txt', 'w')

def li():
	return [int(xxx) for xxx in input().split()]

def fi():
	return int(input())

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())
t = fi()
while t > 0:
	t -= 1
	n = fi()
	a = []
	for i in range(n):
		a.append(si())
	p = a[0][1]
	q = a[1][0]
	r = a[n - 1][n - 2]
	s = a[n - 2][n - 1]
	ans = []
	if len(set([p, q])) == 1:
		if r == p:
			ans.append([n, n - 1])
		if s == p:
			ans.append([n - 1, n])
	elif len(set([r, s])) == 1:
		if r == p:
			ans.append([1, 2])
		if s == q:
			ans.append([2, 1])
	else:
		if p == '0':
			ans.append([1, 2])
		if q == '0':
			ans.append([2, 1])
		if r == '1':
			ans.append([n, n - 1])
		if s == '1':
			ans.append([n - 1, n])
	print(len(ans))
	for i in ans:
		print(*i)


t = int(input())
for i in range(t):
	l = []
	nl = []
	c = 0
	n = int(input())
	zc = 0
	oc = 0
	k = 0
	a = ''
	b = ''
	c = ''
	d = ''
	for i2 in range(n):
		ml = ''
		mlt = []
		ml = input()
		l.append(ml)
	a = l[n - 1][n - 3]
	b = l[n - 2][n - 2]
	c = l[n - 3][n - 1]
	e = l[n - 1][n - 2]
	f = l[n - 2][n - 1]
	while k == 0:
		if a == b and a == c:
			if a == '1':
				oc = 3
			else:
				zc = 3
		elif a == b and a != c:
			d = 'c'
			if a == '1':
				oc = 2
				zc = 1
			else:
				oc = 1
				zc = 2
		elif a == c and a != b:
			d = 'b'
			if a == '1':
				oc = 2
				zc = 1
			else:
				oc = 1
				zc = 2
		elif c == b and a != c:
			d = 'a'
			if c == '1':
				oc = 2
				zc = 1
			else:
				oc = 1
				zc = 2
		k = 1
	if 1 > 0:
		if e == f and e == '1':
			if oc == 3:
				c = 2
				nl = [n, n - 1, n - 1, n]
			elif oc == 0:
				c = 0
			elif oc == 2:
				c = 2
				if d == 'a':
					nl = [n - 1, n - 1, n - 2, n]
				elif d == 'b':
					nl = [n, n - 2, n - 2, n]
				elif d == 'c':
					nl = [n, n - 2, n - 1, n - 1]
			elif oc == 1:
				c = 1
				if d == 'a':
					nl = [n, n - 2]
				elif d == 'b':
					nl = [n - 1, n - 1]
				elif d == 'c':
					nl = [n - 2, n]
		elif e == f and e == '0':
			if zc == 3:
				c = 2
				nl = [n, n - 1, n - 1, n]
			elif zc == 0:
				c = 0
			elif zc == 2:
				c = 2
				if d == 'a':
					nl = [n - 1, n - 1, n - 2, n]
				elif d == 'b':
					nl = [n, n - 2, n - 2, n]
				elif d == 'c':
					nl = [n, n - 2, n - 1, n - 1]
			elif zc == 1:
				c = 1
				if d == 'a':
					nl = [n, n - 2]
				elif d == 'b':
					nl = [n - 1, n - 1]
				elif d == 'c':
					nl = [n - 2, n]
		elif e != f and e == '1':
			if oc == 3:
				c = 1
				nl = [n, n - 1]
			elif oc == 0:
				c = 1
				nl = [n - 1, n]
			elif oc == 2:
				c = 2
				if d == 'a':
					nl = [n, n - 1, n, n - 2]
				elif d == 'b':
					nl = [n, n - 1, n - 1, n - 1]
				elif d == 'c':
					nl = [n, n - 1, n - 2, n]
			elif oc == 1:
				c = 2
				if d == 'a':
					nl = [n - 1, n, n, n - 2]
				elif d == 'b':
					nl = [n - 1, n, n - 1, n - 1]
				elif d == 'c':
					nl = [n - 1, n, n - 2, n]
		elif e != f and e == '0':
			if zc == 3:
				c = 1
				nl = [n, n - 1]
			elif zc == 0:
				c = 1
				nl = [n - 1, n]
			elif zc == 2:
				c = 2
				if d == 'a':
					nl = [n, n - 1, n, n - 2]
				elif d == 'b':
					nl = [n, n - 1, n - 1, n - 1]
				elif d == 'c':
					nl = [n, n - 1, n - 2, n]
			elif zc == 1:
				c = 2
				if d == 'a':
					nl = [n - 1, n, n, n - 2]
				elif d == 'b':
					nl = [n - 1, n, n - 1, n - 1]
				elif d == 'c':
					nl = [n - 1, n, n - 2, n]
	print(c)
	if c > 0:
		for i4 in range(c):
			print(f'{nl[2 * i4]} {nl[2 * i4 + 1]}')


for _ in range(int(input())):
	n = int(input())
	arr = list()
	for _ in range(n):
		arr.append(input())
	ss = arr[0][1]
	sd = arr[1][0]
	fu = arr[n - 2][n - 1]
	fl = arr[n - 1][n - 2]
	if ss == sd:
		if fu == fl:
			if ss != fu:
				print(0)
			else:
				print(2)
				print(1, 2)
				print(2, 1)
		elif ss == fu:
			print(1)
			print(n - 1, n)
		else:
			print(1)
			print(n, n - 1)
	elif fu == fl:
		print(1)
		if ss == fu:
			print(1, 2)
		else:
			print(2, 1)
	else:
		print(2)
		if ss == fl:
			print(2, 1)
			print(n, n - 1)
		if ss == fu:
			print(2, 1)
			print(n - 1, n)


import sys
for i in range(int(sys.stdin.readline())):
	a = []
	for z in range(int(sys.stdin.readline())):
		a.append(str(sys.stdin.readline().strip()))
	g1 = a[1][0]
	g2 = a[0][1]
	c1 = a[len(a) - 2][len(a) - 1]
	c2 = a[len(a) - 1][len(a) - 2]
	stat = False
	stat2 = False
	gstat = None
	cstat = None
	if g1 == g2:
		stat = True
		gstat = g1
	if c1 == c2:
		stat2 = True
		cstat = c1
	if gstat != None and cstat != None:
		if gstat == cstat:
			print(2)
			print(1, 2)
			print(2, 1)
		else:
			print(0)
	elif gstat == None and cstat != None:
		if g1 == cstat:
			print(1)
			print(2, 1)
		else:
			print(1)
			print(1, 2)
	elif cstat == None and gstat != None:
		if c1 == gstat:
			print(1)
			print(len(a) - 1, len(a))
		else:
			print(1)
			print(len(a), len(a) - 1)
	elif g1 == c1:
		print(2)
		print(1, 2)
		print(len(a) - 1, len(a))
	else:
		print(2)
		print(1, 2)
		print(len(a), len(a) - 1)


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import random
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		n = I()
		l = []
		for x in range(n):
			l.append(input())
		ans = []
		if l[0][1] == '1' and l[1][0] == '1':
			if l[n - 1][n - 2] != '0':
				ans.append([n, n - 1])
			if l[n - 2][n - 1] != '0':
				ans.append([n - 1, n])
		elif l[0][1] == '0' and l[1][0] == '0':
			if l[n - 1][n - 2] != '1':
				ans.append([n, n - 1])
			if l[n - 2][n - 1] != '1':
				ans.append([n - 1, n])
		elif l[0][1] == '1':
			if l[n - 1][n - 2] == '1' and l[n - 2][n - 1] == '1':
				ans.append([1, 2])
			else:
				ans.append([2, 1])
				if l[n - 2][n - 1] != '0':
					ans.append([n - 1, n])
				elif l[n - 1][n - 2] != '0':
					ans.append([n, n - 1])
		elif l[n - 2][n - 1] == '0' and l[n - 1][n - 2] == '0':
			ans.append([1, 2])
		else:
			ans.append([2, 1])
			if l[n - 2][n - 1] != '1':
				ans.append([n - 1, n])
			elif l[n - 1][n - 2] != '1':
				ans.append([n, n - 1])
		print(len(ans))
		if len(ans):
			for x in ans:
				print(*x)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


import sys
input = sys.stdin.readline
import math
for _ in range(int(input())):
	n = int(input())
	lis = []
	for i in range(n):
		tmp = list(input())
		lis.append(tmp)
	if lis[0][1] == lis[1][0]:
		if lis[n - 1][n - 2] == lis[n - 2][n - 1]:
			if lis[0][1] != lis[n - 1][n - 2]:
				print(0)
			else:
				print(2)
				print(1, 2)
				print(2, 1)
		else:
			print(1)
			if lis[n - 1][n - 2] != lis[1][0]:
				print(n - 1, n)
			else:
				print(n, n - 1)
	elif lis[n - 1][n - 2] == lis[n - 2][n - 1]:
		print(1)
		if lis[n - 1][n - 2] != lis[1][0]:
			print(1, 2)
		else:
			print(2, 1)
	else:
		print(2)
		if lis[0][1] == '1':
			print(1, 2)
		if lis[1][0] == '1':
			print(2, 1)
		if lis[n - 1][n - 2] == '0':
			print(n, n - 1)
		if lis[n - 2][n - 1] == '0':
			print(n - 1, n)


for _ in range(int(input())):
	n = int(input())
	grid = []
	ans = 0
	for i in range(n):
		grid.append([j for j in str(input())])
	first_left = [1, 2]
	col_ah = [2, 1]
	last_right = [n, n - 1]
	col_pre = [n - 1, n]
	ans = []
	if grid[0][1] == grid[n - 1][n - 2] == grid[1][0] == grid[n - 2][n - 1]:
		ans.append(last_right)
		ans.append(col_pre)
	elif grid[0][1] == grid[1][0] and grid[n - 1][n - 2] == grid[n - 2][n - 1] and (grid[n - 2][n - 1] != grid[0][1]):
		pass
	elif grid[0][1] != grid[1][0] and grid[n - 1][n - 2] != grid[n - 2][n - 1]:
		if grid[0][1] != grid[n - 1][n - 2]:
			ans = [first_left, last_right]
		else:
			ans = [first_left, col_pre]
	elif grid[0][1] == grid[1][0] and grid[n - 1][n - 2] != grid[n - 2][n - 1]:
		if grid[0][1] == grid[n - 1][n - 2]:
			ans = [last_right]
		else:
			ans = [col_pre]
	elif grid[0][1] != grid[1][0] and grid[n - 1][n - 2] == grid[n - 2][n - 1]:
		if grid[0][1] == grid[n - 1][n - 2]:
			ans = [first_left]
		else:
			ans = [col_ah]
	print(len(ans))
	for z in ans:
		print(' '.join([str(b) for b in z]))


t = int(input())
for _ in range(t):
	a = int(input())
	lis = []
	for j in range(a):
		if j == 0:
			sh = list(input())
			sh[0] = '7'
			sh = list(map(int, sh))
		elif j == a - 1:
			sh = list(input())
			sh[-1] = '7'
			sh = list(map(int, sh))
		else:
			sh = list(input())
			sh = list(map(int, sh))
		lis.append(sh)
	if lis[0][1] == 0 and lis[1][0] == 0 and (lis[-1][-2] == 0) and (lis[-2][-1] == 0):
		print(2)
		print('1 2')
		print('2 1')
	elif lis[0][1] == 1 and lis[1][0] == 0 and (lis[-1][-2] == 0) and (lis[-2][-1] == 0):
		print(1)
		print('2 1')
	elif lis[0][1] == 0 and lis[1][0] == 1 and (lis[-1][-2] == 0) and (lis[-2][-1] == 0):
		print(1)
		print('1 2')
	elif lis[0][1] == 1 and lis[1][0] == 1 and (lis[-1][-2] == 0) and (lis[-2][-1] == 0):
		print(0)
	elif lis[0][1] == 0 and lis[1][0] == 0 and (lis[-1][-2] == 1) and (lis[-2][-1] == 1):
		print(0)
	elif lis[0][1] == 1 and lis[1][0] == 0 and (lis[-1][-2] == 1) and (lis[-2][-1] == 1):
		print(1)
		print('1 2')
	elif lis[0][1] == 0 and lis[1][0] == 1 and (lis[-1][-2] == 1) and (lis[-2][-1] == 1):
		print(1)
		print('2 1')
	elif lis[0][1] == 1 and lis[1][0] == 1 and (lis[-1][-2] == 1) and (lis[-2][-1] == 1):
		print(2)
		print('1 2')
		print('2 1')
	elif lis[0][1] == 0 and lis[1][0] == 0 and (lis[-1][-2] == 1) and (lis[-2][-1] == 0):
		print(1)
		print('{} {}'.format(a - 1, a))
	elif lis[0][1] == 1 and lis[1][0] == 0 and (lis[-1][-2] == 1) and (lis[-2][-1] == 0):
		print(2)
		print('1 2')
		print('{} {}'.format(a - 1, a))
	elif lis[0][1] == 0 and lis[1][0] == 1 and (lis[-1][-2] == 1) and (lis[-2][-1] == 0):
		print(2)
		print('1 2')
		print('{} {}'.format(a, a - 1))
	elif lis[0][1] == 1 and lis[1][0] == 1 and (lis[-1][-2] == 1) and (lis[-2][-1] == 0):
		print(1)
		print('{} {}'.format(a, a - 1))
	elif lis[0][1] == 0 and lis[1][0] == 0 and (lis[-1][-2] == 0) and (lis[-2][-1] == 1):
		print(1)
		print('{} {}'.format(a, a - 1))
	elif lis[0][1] == 1 and lis[1][0] == 0 and (lis[-1][-2] == 0) and (lis[-2][-1] == 1):
		print(2)
		print('1 2')
		print('{} {}'.format(a, a - 1))
	elif lis[0][1] == 0 and lis[1][0] == 1 and (lis[-1][-2] == 0) and (lis[-2][-1] == 1):
		print(2)
		print('{} {}'.format(a, a - 1))
		print('2 1')
	elif lis[0][1] == 1 and lis[1][0] == 1 and (lis[-1][-2] == 0) and (lis[-2][-1] == 1):
		print(1)
		print('{} {}'.format(a - 1, a))


for _ in range(int(input())):
	n = int(input())
	s = [input() for i in range(n)]
	ans = []
	if s[0][2] == s[1][1] == s[2][0]:
		if s[0][1] == s[0][2]:
			ans += ['1 2']
		if s[1][0] == s[0][2]:
			ans += ['2 1']
	else:
		x = 0
		if s[0][1] != s[1][0]:
			if s[0][2] == s[1][1]:
				ans += ['3 1']
			elif s[0][2] == s[2][0]:
				ans += ['2 2']
			else:
				ans += ['1 3']
				x = 1
			if x == 0:
				if s[0][2] == s[0][1]:
					ans += ['1 2']
				else:
					ans += ['2 1']
			elif s[1][1] == s[0][1]:
				ans += ['1 2']
			else:
				ans += ['2 1']
		else:
			if s[0][2] == s[0][1]:
				ans += ['1 3']
			if s[1][1] == s[0][1]:
				ans += ['2 2']
			if s[2][0] == s[0][1]:
				ans += ['3 1']
	print(len(ans))
	for a in ans:
		print(a)


t = int(input())
for _ in range(t):
	n = int(input())
	for w in range(n):
		s = input()
		if w == 0:
			a = s[1]
		if w == 1:
			b = s[0]
		if w == n - 2:
			c = s[n - 1]
		if w == n - 1:
			d = s[n - 2]
	e = 0
	if a == b:
		if c == a and d == a:
			print(2)
			print(n - 1, n)
			print(n, n - 1)
		elif c == a and d != a:
			print(1)
			print(n - 1, n)
		elif c != a and d == a:
			print(1)
			print(n, n - 1)
		else:
			print(0)
	elif c == d:
		if a == c:
			print(1)
			print(1, 2)
		else:
			print(1)
			print(2, 1)
	elif a == d:
		print(2)
		print(n, n - 1)
		print(2, 1)
	else:
		print(2)
		print(n, n - 1)
		print(1, 2)


for _ in range(int(input())):
	n = int(input())
	string = []
	for i in range(n):
		l = input()
		string.append(l)
	c = 0
	(p, q) = (len(string) - 2, len(string[0]) - 1)
	(r, s) = (len(string) - 1, len(string[0]) - 2)
	x = string[0][1] + string[1][0]
	y = string[p][q] + string[r][s]
	tempx = x
	tempy = y
	if x[0] == x[1]:
		if x[0] == '0':
			y = '11'
		else:
			y = '00'
	elif y[0] == y[1]:
		if y[0] == '0':
			x = '11'
		else:
			x = '00'
	else:
		x = '00'
		y = '11'
	output = []
	if x[0] != string[0][1]:
		output.append((0, 1))
	if x[1] != string[1][0]:
		output.append((1, 0))
	if y[0] != string[p][q]:
		output.append((p, q))
	if y[1] != string[r][s]:
		output.append((r, s))
	print(len(output))
	for (x, y) in output:
		print(x + 1, y + 1)


for _ in range(int(input())):
	n = int(input())
	grid = []
	for i in range(n):
		grid.append(input())
	(s_bottom, s_right, f_left, f_top) = (grid[1][0], grid[0][1], grid[n - 1][n - 2], grid[n - 2][n - 1])
	if s_bottom == s_right == f_left == f_top:
		print(2)
		print(1, 2)
		print(2, 1)
	elif s_bottom == s_right == f_left:
		print(1)
		print(n, n - 1)
	elif s_bottom == s_right == f_top:
		print(1)
		print(n - 1, n)
	elif f_top == f_left == s_bottom:
		print(1)
		print(2, 1)
	elif f_top == f_left == s_right:
		print(1)
		print(1, 2)
	elif f_top == s_right and f_left == s_bottom:
		print(2)
		print(n - 1, n)
		print(2, 1)
	elif f_top == s_bottom and f_left == s_right:
		print(2)
		print(n - 1, n)
		print(1, 2)
	else:
		print(0)


t = int(input())
while t > 0:
	n = int(input())
	for i in range(n):
		l = input()
		if i == 0:
			a = l[1]
		if i == 1:
			b = l[0]
		if i == n - 2:
			c = l[-1]
		if i == n - 1:
			d = l[-2]
	if a == b and c == d:
		if a != c:
			print(0)
		else:
			print(2)
			print(1, 2)
			print(2, 1)
	elif a == b:
		print(1)
		if c != a:
			print(n, n - 1)
		else:
			print(n - 1, n)
	elif c == d:
		print(1)
		if a != c:
			print(2, 1)
		else:
			print(1, 2)
	else:
		print(2)
		if a == '1':
			print(2, 1)
		else:
			print(1, 2)
		if c == '0':
			print(n, n - 1)
		else:
			print(n - 1, n)
	t -= 1


def main():
	for _ in range(int(input())):
		n = int(input())
		a = []
		for i in range(n):
			a.append(input())
		ans = []
		if a[0][1] == a[1][0]:
			if a[n - 1][n - 2] == a[0][1]:
				ans.append((n, n - 1))
			if a[n - 2][n - 1] == a[0][1]:
				ans.append((n - 1, n))
		elif a[n - 1][n - 2] == a[n - 2][n - 1]:
			if a[0][1] == a[n - 1][n - 2]:
				ans.append((1, 2))
			if a[1][0] == a[n - 1][n - 2]:
				ans.append((2, 1))
		else:
			ans.append((1, 2))
			if a[n - 1][n - 2] == a[1][0]:
				ans.append((n, n - 1))
			if a[n - 2][n - 1] == a[1][0]:
				ans.append((n - 1, n))
		print(len(ans))
		for (a, b) in ans:
			print('%d %d' % (a, b))
main()


t = int(input())
for _ in range(t):
	n = int(input())
	l = []
	i = int(0)
	for i in range(n):
		l.append(input())
	x1 = l[0][1]
	x2 = l[1][0]
	(y1, y2) = (l[-2][-1], l[-1][-2])
	if x1 == x2 and x2 == y1 and (y1 == y2):
		print('2')
		print('1 2')
		print('2 1')
	elif x1 == x2 and y1 == y2:
		print('0')
	elif x1 == x2 and y1 != y2:
		if x1 == '0' and y1 == '0':
			print('1')
			print(n - 1, n)
		elif x1 == '0' and y2 == '0':
			print('1')
			print(n, n - 1)
		elif x1 == '1' and y1 == '1':
			print('1')
			print(n - 1, n)
		elif x1 == '1' and y2 == '1':
			print('1')
			print(n, n - 1)
	elif x1 != x2 and y1 == y2:
		if y1 == '0' and x1 == '0':
			print('1')
			print('1 2')
		elif y1 == '0' and x2 == '0':
			print('1')
			print('2 1')
		elif y1 == '1' and x1 == '1':
			print('1')
			print('1 2')
		elif y1 == '1' and x2 == '1':
			print('1')
			print('2 1')
	elif x1 != x2 and y1 != y2:
		if x1 == '1' and y1 == '1':
			print('2')
			print('2 1')
			print(n - 1, n)
		elif x1 == '1' and y2 == '1':
			print('2')
			print('2 1')
			print(n, n - 1)
		elif x1 == '0' and y1 == '0':
			print('2')
			print('2 1')
			print(n - 1, n)
		elif x1 == '0' and y2 == '0':
			print('2')
			print('2 1')
			print(n, n - 1)


t = int(input())
for j in range(t):
	ans = []
	n = int(input())
	li = []
	for i in range(n):
		s = input()
		k = len(s)
		li.append(s)
	if li[0][1] == li[1][0]:
		if li[k - 2][n - 1] == li[k - 1][n - 2]:
			if li[0][1] == li[k - 2][n - 1]:
				r = []
				r.append(1)
				r.append(2)
				ans.append(r)
				r = []
				r.append(2)
				r.append(1)
				ans.append(r)
		elif li[0][1] == li[k - 2][n - 1]:
			r = []
			r.append(k - 1)
			r.append(n)
			ans.append(r)
		else:
			r = []
			r.append(k)
			r.append(n - 1)
			ans.append(r)
	elif li[k - 2][n - 1] == li[k - 1][n - 2]:
		if li[0][1] == li[k - 2][n - 1]:
			r = []
			r.append(1)
			r.append(2)
			ans.append(r)
		else:
			r = []
			r.append(2)
			r.append(1)
			ans.append(r)
	elif li[0][1] == li[k - 2][n - 1]:
		r = []
		r.append(1)
		r.append(2)
		ans.append(r)
		r = []
		r.append(k)
		r.append(n - 1)
		ans.append(r)
	else:
		r = []
		r.append(1)
		r.append(2)
		ans.append(r)
		r = []
		r.append(k - 1)
		r.append(n)
		ans.append(r)
	print(len(ans))
	for k in range(len(ans)):
		print(ans[k][0], end=' ')
		print(ans[k][1])


a = int(input())
for i in range(a):
	b = int(input())
	c = []
	d = 0
	for j in range(b):
		c.append(input())
	e = [int(c[0][1]), '1 2', int(c[1][0]), '2 1', int(c[-2][-1]), str(b - 1) + ' ' + str(b), int(c[-1][-2]), str(b) + ' ' + str(b - 1)]
	f = e.count(0)
	if not f:
		print(2)
		print(e[1])
		print(e[3])
	elif f == 1:
		if e[0] != e[2]:
			if e[0]:
				print(1)
				print(e[1])
			else:
				print(1)
				print(e[3])
		elif e[4]:
			print(1)
			print(e[5])
		else:
			print(1)
			print(e[7])
	elif f == 2:
		if e[0] == e[2]:
			print(0)
		else:
			print(2)
			print(e[1])
			if e[4] == e[2]:
				print(e[5])
			else:
				print(e[7])
	elif f == 3:
		if e[0] != e[2]:
			if not e[0]:
				print(1)
				print(e[1])
			else:
				print(1)
				print(e[3])
		elif not e[4]:
			print(1)
			print(e[5])
		else:
			print(1)
			print(e[7])
	else:
		print(2)
		print(e[1])
		print(e[3])


def problem_sol(n, arr_field):
	num_changes = 0
	sol_list = []
	s_right = int(arr_field[0][1])
	s_down = int(arr_field[1][0])
	f_left = int(arr_field[n - 1][n - 2])
	f_up = int(arr_field[n - 2][n - 1])
	if f_left == f_up:
		if f_left == s_right:
			sol_list.append('1 2')
			num_changes += 1
		if f_left == s_down:
			sol_list.append('2 1')
			num_changes += 1
	elif s_right == s_down:
		if s_right == f_left:
			sol_list.append(str(n) + ' ' + str(n - 1))
			num_changes += 1
		if s_right == f_up:
			sol_list.append(str(n - 1) + ' ' + str(n))
			num_changes += 1
	else:
		if f_left == 1:
			sol_list.append(str(n) + ' ' + str(n - 1))
			num_changes += 1
		else:
			sol_list.append(str(n - 1) + ' ' + str(n))
			num_changes += 1
		if s_right == 0:
			sol_list.append('1 2')
			num_changes += 1
		else:
			sol_list.append('2 1')
			num_changes += 1
	print(num_changes)
	for entry in sol_list:
		print(entry)
no_inp = int(input())
list_of_var1 = []
while no_inp > 0:
	n = int(input())
	arr_field = [input() for i in range(n)]
	list_of_var1.append([n, arr_field])
	no_inp -= 1
for entry in list_of_var1:
	problem_sol(entry[0], entry[1])


t = int(input())
import itertools
for _ in range(t):
	n = int(input())
	S = [list(str(input())) for _ in range(n)]
	flag = False
	s = []
	s.append((0, 0))
	visit0 = [[-1] * n for _ in range(n)]
	while s:
		(i, j) = s.pop()
		for (di, dj) in ((-1, 0), (1, 0), (0, -1), (0, 1)):
			(ni, nj) = (i + di, j + dj)
			if 0 <= ni < n and 0 <= nj < n:
				if S[ni][nj] == '0' or S[ni][nj] == 'F':
					if visit0[ni][nj] == -1:
						visit0[ni][nj] = 0
						s.append((ni, nj))
	s.append((0, 0))
	visit1 = [[-1] * n for _ in range(n)]
	while s:
		(i, j) = s.pop()
		for (di, dj) in ((-1, 0), (1, 0), (0, -1), (0, 1)):
			(ni, nj) = (i + di, j + dj)
			if 0 <= ni < n and 0 <= nj < n:
				if S[ni][nj] == '1' or S[ni][nj] == 'F':
					if visit1[ni][nj] == -1:
						visit1[ni][nj] = 0
						s.append((ni, nj))
	if visit0[n - 1][n - 1] == -1 and visit1[n - 1][n - 1] == -1:
		print(0)
		continue
	if S[0][1] == '0' and S[1][0] == '0' and (S[n - 1][n - 2] == '0') and (S[n - 2][n - 1] == '0'):
		print(2)
		print(1, 2)
		print(2, 1)
	elif S[0][1] == '0' and S[1][0] == '0' and (S[n - 1][n - 2] == '1') and (S[n - 2][n - 1] == '0'):
		print(1)
		print(n - 1, n)
	elif S[0][1] == '0' and S[1][0] == '0' and (S[n - 1][n - 2] == '0') and (S[n - 2][n - 1] == '1'):
		print(1)
		print(n, n - 1)
	elif S[0][1] == '0' and S[1][0] == '0' and (S[n - 1][n - 2] == '1') and (S[n - 2][n - 1] == '1'):
		print(0)
	elif S[0][1] == '1' and S[1][0] == '0' and (S[n - 1][n - 2] == '0') and (S[n - 2][n - 1] == '0'):
		print(1)
		print(2, 1)
	elif S[0][1] == '1' and S[1][0] == '0' and (S[n - 1][n - 2] == '1') and (S[n - 2][n - 1] == '0'):
		print(2)
		print(1, 2)
		print(n - 1, n)
	elif S[0][1] == '1' and S[1][0] == '0' and (S[n - 1][n - 2] == '0') and (S[n - 2][n - 1] == '1'):
		print(2)
		print(1, 2)
		print(n, n - 1)
	elif S[0][1] == '1' and S[1][0] == '0' and (S[n - 1][n - 2] == '1') and (S[n - 2][n - 1] == '1'):
		print(1)
		print(1, 2)
	elif S[0][1] == '0' and S[1][0] == '1' and (S[n - 1][n - 2] == '0') and (S[n - 2][n - 1] == '0'):
		print(1)
		print(1, 2)
	elif S[0][1] == '0' and S[1][0] == '1' and (S[n - 1][n - 2] == '1') and (S[n - 2][n - 1] == '0'):
		print(2)
		print(2, 1)
		print(n - 1, n)
	elif S[0][1] == '0' and S[1][0] == '1' and (S[n - 1][n - 2] == '0') and (S[n - 2][n - 1] == '1'):
		print(2)
		print(2, 1)
		print(n, n - 1)
	elif S[0][1] == '0' and S[1][0] == '1' and (S[n - 1][n - 2] == '1') and (S[n - 2][n - 1] == '1'):
		print(1)
		print(2, 1)
	elif S[0][1] == '1' and S[1][0] == '1' and (S[n - 1][n - 2] == '0') and (S[n - 2][n - 1] == '0'):
		print(0)
	elif S[0][1] == '1' and S[1][0] == '1' and (S[n - 1][n - 2] == '1') and (S[n - 2][n - 1] == '0'):
		print(1)
		print(n, n - 1)
	elif S[0][1] == '1' and S[1][0] == '1' and (S[n - 1][n - 2] == '0') and (S[n - 2][n - 1] == '1'):
		print(1)
		print(n - 1, n)
	elif S[0][1] == '1' and S[1][0] == '1' and (S[n - 1][n - 2] == '1') and (S[n - 2][n - 1] == '1'):
		print(2)
		print(1, 2)
		print(2, 1)


T = int(input())
for _ in range(T):
	n = int(input())
	matrix = []
	for i in range(n):
		s = input()
		matrix.append(s)
	if matrix[0][1] != matrix[1][0] and matrix[n - 2][n - 1] != matrix[n - 1][n - 2]:
		lis = []
		if matrix[0][1] == '0':
			lis.append([1, 2])
		else:
			lis.append([2, 1])
		if matrix[n - 2][n - 1] == '1':
			lis.append([n - 1, n])
		else:
			lis.append([n, n - 1])
		print(2)
		for i in lis:
			print(*i)
	elif matrix[0][1] == matrix[1][0] and matrix[n - 2][n - 1] != matrix[n - 1][n - 2]:
		print(1)
		if matrix[0][1] != matrix[n - 1][n - 2]:
			print(n - 1, n)
		else:
			print(n, n - 1)
	elif matrix[0][1] != matrix[1][0] and matrix[n - 2][n - 1] == matrix[n - 1][n - 2]:
		print(1)
		if matrix[0][1] != matrix[n - 1][n - 2]:
			print(2, 1)
		else:
			print(1, 2)
	elif matrix[0][1] == matrix[1][0] and matrix[n - 2][n - 1] == matrix[n - 1][n - 2] and (matrix[0][1] == matrix[n - 2][n - 1]):
		print(2)
		print(1, 2)
		print(2, 1)
	elif matrix[0][1] == matrix[1][0] and matrix[n - 2][n - 1] == matrix[n - 1][n - 2] and (matrix[0][1] != matrix[n - 2][n - 1]):
		print(0)


for _ in range(int(input())):
	n = int(input())
	data = []
	for q in range(n):
		data.append(input())
	start_right = data[0][1]
	start_down = data[1][0]
	end_left = data[-1][-2]
	end_top = data[-2][-1]
	if start_right == start_down:
		if end_left == end_top:
			if start_down == end_left:
				ans = [[n, n - 1], [n - 1, n]]
			else:
				ans = []
		elif start_down == end_left:
			ans = [[n, n - 1]]
		else:
			ans = [[n - 1, n]]
	elif end_left == end_top:
		if end_top == start_down:
			ans = [[2, 1]]
		else:
			ans = [[1, 2]]
	elif start_down == end_top:
		ans = [[2, 1], [n, n - 1]]
	else:
		ans = [[2, 1], [n - 1, n]]
	print(len(ans))
	for q in range(len(ans)):
		print(ans[q][0], ans[q][1])


t = int(input())
for _ in range(t):
	n = int(input())
	g = []
	for i in range(n):
		g.append(input())
	(a, b, c, d) = (g[0][1], g[1][0], g[n - 1][n - 2], g[n - 2][n - 1])
	if a == b and c == d and (a != c):
		print(0)
	elif a == b and c != d:
		print(1)
		if c == a:
			print(n, n - 1)
		elif d == a:
			print(n - 1, n)
	elif c == d and a != b:
		print(1)
		if a == c:
			print(1, 2)
		elif b == c:
			print(2, 1)
	elif a == b and c == d and (a == c):
		print(2)
		print(1, 2)
		print(2, 1)
	elif a != b and c != d:
		print(2)
		if a == c:
			print(1, 2)
			print(n - 1, n)
		elif a == d:
			print(1, 2)
			print(n, n - 1)


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math
from collections import defaultdict
for _ in range(ri()):
	n = ri()
	l = []
	for __ in range(n):
		l.append(list(input()))
	ans = []
	x = [l[0][1], l[1][0]]
	y = [l[n - 2][n - 1], l[n - 1][n - 2]]
	z = x.count('0') + y.count('0')
	if x.count('1') == 0 and y.count('0') == 0 or (x.count('0') == 0 and y.count('1') == 0):
		wi(0)
	elif z == 4 or z == 0:
		wi(2)
		print(1, 2)
		print(2, 1)
	elif z == 1:
		if '0' in x:
			if x[0] == '0':
				wi(1)
				print(2, 1)
			else:
				wi(1)
				print(1, 2)
		elif y[0] == '0':
			wi(1)
			print(n, n - 1)
		else:
			wi(1)
			print(n - 1, n)
	elif z == 2:
		wi(2)
		if x[0] == '1':
			print(1, 2)
		else:
			print(2, 1)
		if y[0] == '0':
			print(n - 1, n)
		else:
			print(n, n - 1)
	elif '1' in x:
		if x[0] == '1':
			wi(1)
			print(2, 1)
		else:
			wi(1)
			print(1, 2)
	elif y[0] == '1':
		wi(1)
		print(n, n - 1)
	else:
		wi(1)
		print(n - 1, n)


import sys, math, cmath, time
start_time = time.time()

def solve():
	n = inp()
	a = []
	for i in range(n):
		s = insr()
		a.append(list(s))
	(q, w) = (a[0][1], a[1][0])
	(qq, ww) = (a[-1][-2], a[-2][-1])
	qw = []
	if len(set([q, w, qq, ww])) == 1:
		qw = [[1, 2], [2, 1]]
	elif q == w and qq == ww:
		qw = []
	elif q != w and qq != ww:
		if q == '0':
			qw.append([1, 2])
		if w == '0':
			qw.append([2, 1])
		if qq == '1':
			qw.append([len(a), len(a) - 1])
		if ww == '1':
			qw.append([len(a) - 1, len(a)])
	elif q == w:
		if qq == q:
			qw.append([len(a), len(a) - 1])
		else:
			qw.append([len(a) - 1, len(a)])
	elif q == qq:
		qw.append([1, 2])
	else:
		qw.append([2, 1])
	print(len(qw))
	for i in range(len(qw)):
		print(*qw[i])

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = inp()
	for tt in range(1, t + 1):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	return input().strip()

def invr():
	return map(int, input().split())

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def counter_elements(a):
	q = dict()
	for i in range(len(a)):
		if a[i] not in q:
			q[a[i]] = 0
		q[a[i]] = q[a[i]] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def factorial(n, m=1000000007):
	q = 1
	for i in range(n):
		q = q * (i + 1) % m
	return q

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def prime_factors(n):
	q = []
	while n % 2 == 0:
		q.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			q.append(i)
			n = n // i
	if n > 2:
		q.append(n)
	return list(sorted(q))

def transpose(a):
	(n, m) = (len(a), len(a[0]))
	b = [[0] * n for i in range(m)]
	for i in range(m):
		for j in range(n):
			b[i][j] = a[j][i]
	return b

def power_two(x):
	return x and (not x & x - 1)

def ceil(a, b):
	return -(-a // b)

def seive(n):
	a = [1]
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p ** 2, n + 1, p):
				prime[i] = False
		p = p + 1
	for p in range(2, n + 1):
		if prime[p]:
			a.append(p)
	return a
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


for _ in range(int(input())):
	n = int(input())
	l = []
	for i in range(n):
		s = str(input())
		l.append(s)
	a = int(l[0][1])
	b = int(l[1][0])
	c = int(l[n - 1][n - 2])
	d = int(l[n - 2][n - 1])
	if a == 0 and b == 0:
		if c == 1 and d == 1:
			print(0)
		elif c == 1 and d == 0:
			print(1)
			print(n - 1, n)
		elif c == 0 and d == 1:
			print(1)
			print(n, n - 1)
		elif c == 0 and d == 0:
			print(2)
			print(1, 2)
			print(2, 1)
	elif a == 1 and b == 0:
		if c == 1 and d == 1:
			print(1)
			print(1, 2)
		elif c == 1 and d == 0:
			print(2)
			print(1, 2)
			print(n - 1, n)
		elif c == 0 and d == 1:
			print(2)
			print(1, 2)
			print(n, n - 1)
		elif c == 0 and d == 0:
			print(1)
			print(2, 1)
	elif a == 0 and b == 1:
		if c == 0 and d == 0:
			print(1)
			print(1, 2)
		elif c == 1 and d == 0:
			print(2)
			print(1, 2)
			print(n, n - 1)
		elif c == 0 and d == 1:
			print(2)
			print(1, 2)
			print(n - 1, n)
		elif c == 1 and d == 1:
			print(1)
			print(2, 1)
	elif a == 1 and b == 1:
		if c == 0 and d == 0:
			print(0)
		elif c == 1 and d == 0:
			print(1)
			print(n, n - 1)
		elif c == 0 and d == 1:
			print(1)
			print(n - 1, n)
		elif c == 1 and d == 1:
			print(2)
			print(n, n - 1)
			print(n - 1, n)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from heapq import *
from math import gcd, factorial, floor, ceil
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 10 ** 9 + 7

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve(case):
	n = int(inp())
	g = []
	for i in range(n):
		temp = list(inp())
		g.append(temp)
	a = [g[0][1], g[1][0], g[n - 1][n - 2], g[n - 2][n - 1]]
	if a[0] == a[1]:
		if a[2] == a[3]:
			if a[0] == a[2]:
				print(2)
				print(1, 2)
				print(2, 1)
			else:
				print(0)
		elif a[2] == a[0]:
			print(1)
			print(n, n - 1)
		else:
			print(1)
			print(n - 1, n)
	elif a[2] == a[3]:
		if a[0] == a[2]:
			print(1)
			print(1, 2)
		else:
			print(1)
			print(2, 1)
	elif a[0] == a[2]:
		print(2)
		print(2, 1)
		print(n, n - 1)
	else:
		print(2)
		print(1, 2)
		print(n, n - 1)
testcase(int(inp()))


from math import *
from bisect import *
from collections import *
from random import *
from decimal import *
from itertools import *
import sys
input = sys.stdin.readline

def inp():
	return int(input())

def st():
	return input().rstrip('\n')

def lis():
	return list(map(int, input().split()))

def ma():
	return map(int, input().split())
t = inp()
while t:
	t -= 1
	n = inp()
	re = []
	r = []
	for i in range(n):
		s = st()
		s = list(s)
		re.append(s)
	li = [re[0][1], re[0][2], re[1][1], re[1][0], re[2][0]]
	for i in range(32):
		x = bin(i)[2:]
		x = x.zfill(5)
		inc = 0
		for j in range(5):
			if li[j] != x[j]:
				inc += 1
		if inc <= 2 and (x[2] != x[0] and x[0] != x[1]) and (x[3] != x[2] and x[4] != x[3]):
			print(inc)
			for j in range(5):
				if li[j] != x[j]:
					if j == 0:
						print(1, 2)
					if j == 1:
						print(1, 3)
					if j == 2:
						print(2, 2)
					if j == 3:
						print(2, 1)
					if j == 4:
						print(3, 1)


for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		d = list(input())
		a.append(d)
	c = 0
	if a[0][1] == a[1][0]:
		if a[n - 1][n - 2] == a[0][1]:
			c += 1
			if a[n - 2][n - 1] == a[0][1]:
				c += 1
				print(c)
				print(n - 1, n)
				print(n, n - 1)
			else:
				print(c)
				print(n, n - 1)
		elif a[n - 2][n - 1] == a[1][0]:
			c += 1
			print(c)
			print(n - 1, n)
		else:
			print('0')
	else:
		c += 1
		if a[n - 1][n - 2] == a[n - 2][n - 1]:
			if a[n - 1][n - 2] == a[0][1]:
				print(c)
				print(1, 2)
			else:
				print(c)
				print(2, 1)
		else:
			c += 1
			if a[0][1] == a[n - 1][n - 2]:
				print(c)
				print(1, 2)
				print(n - 1, n)
			else:
				print(c)
				print(1, 2)
				print(n, n - 1)


import sys as _sys
ZERO = '0'
ONE = '1'

def main():
	t = int(input())
	for i_t in range(t):
		(n,) = _read_ints()
		a = tuple((tuple(_read_line()) for i_row in range(n)))
		result = tuple(find_cells_to_invert(a))
		print(len(result))
		for (x, y) in result:
			if x < 0:
				x += n
			if y < 0:
				y += n
			x += 1
			y += 1
			print(y, x)

def _read_line():
	result = _sys.stdin.readline()
	assert result[-1] == '\n'
	return result[:-1]

def _read_ints():
	return map(int, _read_line().split())

def find_cells_to_invert(matrix):
	assert len(matrix) == len(matrix[0])
	n = len(matrix)
	assert n >= 3
	get_by_pos = lambda pos: matrix[pos[1]][pos[0]]
	(cell_a, cell_b) = ((0, 1), (1, 0))
	(cell_c, cell_d) = ((-1, -2), (-2, -1))
	(value_a, value_b) = (get_by_pos(cell_a), get_by_pos(cell_b))
	(value_c, value_d) = (get_by_pos(cell_c), get_by_pos(cell_d))
	if value_a != value_b and value_c != value_d:
		if get_by_pos(cell_a) == ONE:
			yield cell_a
		else:
			yield cell_b
		if get_by_pos(cell_c) == ZERO:
			yield cell_c
		else:
			yield cell_d
	elif value_a == value_b:
		value_to_avoid = value_a
		if value_c == value_to_avoid:
			yield cell_c
		if value_d == value_to_avoid:
			yield cell_d
	else:
		assert value_c == value_d
		value_to_avoid = value_c
		if value_a == value_to_avoid:
			yield cell_a
		if value_b == value_to_avoid:
			yield cell_b
main()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	g = []
	(ans, ans1) = ([], [])
	for i in range(n):
		g.append(input())
	(s1, s2) = (g[0][1], g[1][0])
	(e1, e2) = (g[n - 1][n - 2], g[n - 2][n - 1])
	if s1 == s2 == '0':
		if e1 == '0':
			ans.append((n - 1, n - 2))
		if e2 == '0':
			ans.append((n - 2, n - 1))
	elif s1 == s2 == '1':
		if e1 == '1':
			ans.append((n - 1, n - 2))
		if e2 == '1':
			ans.append((n - 2, n - 1))
	elif e1 == e2 == '0':
		if s1 == '0':
			ans.append((0, 1))
		if s2 == '0':
			ans.append((1, 0))
	elif e1 == e2 == '1':
		if s1 == '1':
			ans.append((0, 1))
		if s2 == '1':
			ans.append((1, 0))
	elif s1 == '0':
		ans.append((1, 0))
		if e1 == '0':
			ans.append((n - 1, n - 2))
		if e2 == '0':
			ans.append((n - 2, n - 1))
	else:
		ans.append((1, 0))
		if e1 == '1':
			ans.append((n - 1, n - 2))
		if e2 == '1':
			ans.append((n - 2, n - 1))
	print(len(ans))
	for (i, j) in ans:
		print(i + 1, j + 1)


for _ in range(int(input())):
	n = int(input())
	s = []
	for __ in range(n):
		s.append([int(x) for x in input() if x.isdigit()])
	s[0].insert(0, 0)
	s[n - 1].insert(n - 1, 0)
	c = 0
	ans = []
	if s[0][1] and s[1][0]:
		if s[n - 1][n - 2]:
			c += 1
			ans.append([n, n - 1])
		if s[n - 2][n - 1]:
			c += 1
			ans.append([n - 1, n])
		print(c)
		for i in ans:
			print(*i)
		continue
	elif not (s[0][1] or s[1][0]):
		if not s[n - 1][n - 2]:
			c += 1
			ans.append([n, n - 1])
		if not s[n - 2][n - 1]:
			c += 1
			ans.append([n - 1, n])
		print(c)
		for i in ans:
			print(*i)
		continue
	elif s[n - 1][n - 2] and s[n - 2][n - 1]:
		if s[0][1]:
			c += 1
			ans.append([1, 2])
		if s[1][0]:
			c += 1
			ans.append([2, 1])
		print(c)
		for i in ans:
			print(*i)
		continue
	elif not (s[n - 1][n - 2] or s[n - 2][n - 1]):
		if not s[0][1]:
			c += 1
			ans.append([1, 2])
		if not s[1][0]:
			c += 1
			ans.append([2, 1])
		print(c)
		for i in ans:
			print(*i)
		continue
	elif s[n - 1][n - 2] or s[n - 2][n - 1]:
		if s[n - 1][n - 2]:
			if s[0][1]:
				print(2)
				print(1, 2)
				print(n - 1, n)
				continue
			else:
				print(2)
				print(2, 1)
				print(n - 1, n)
				continue
		elif s[0][1]:
			print(2)
			print(1, 2)
			print(n, n - 1)
			continue
		else:
			print(2)
			print(2, 1)
			print(n, n - 1)
			continue
	elif not s[0][1]:
		print(1)
		print(0, 1)
		continue
	else:
		print(1)
		print(1, 1)
		continue


import sys
input = sys.stdin.readline
t = int(input())

def f(mat):
	c = [['0' for i in range(n)] for j in range(n)]
	for i in range(n):
		for j in range(n):
			c[i][j] = mat[i][j]
	return c
from collections import deque

def check(mat, l):
	for i in range(len(l)):
		if mat[l[i][0]][l[i][1]] == '0':
			mat[l[i][0]][l[i][1]] = '1'
		else:
			mat[l[i][0]][l[i][1]] = '0'
	q = [(0, 0)]
	q = deque(q)
	visited = [[0 for i in range(n)] for j in range(n)]
	visited[0][0] = 1
	while len(q) != 0:
		(i, j) = q[0]
		temp1 = [-1, +1, 0, 0]
		temp2 = [0, 0, -1, +1]
		for k in range(4):
			if i + temp1[k] >= 0 and i + temp1[k] < n and (j + temp2[k] >= 0) and (j + temp2[k] < n):
				if visited[i + temp1[k]][j + temp2[k]] == 0 and (mat[i + temp1[k]][j + temp2[k]] == '0' or mat[i + temp1[k]][j + temp2[k]] == 'F'):
					visited[i + temp1[k]][j + temp2[k]] = 1
					q.append((i + temp1[k], j + temp2[k]))
		q.popleft()
	if visited[-1][-1] == 1:
		return True
	q = [(0, 0)]
	q = deque(q)
	visited = [[0 for i in range(n)] for j in range(n)]
	visited[0][0] = 1
	while len(q) != 0:
		(i, j) = q[0]
		temp1 = [-1, +1, 0, 0]
		temp2 = [0, 0, -1, +1]
		for k in range(4):
			if i + temp1[k] >= 0 and i + temp1[k] < n and (j + temp2[k] >= 0) and (j + temp2[k] < n):
				if visited[i + temp1[k]][j + temp2[k]] == 0 and (mat[i + temp1[k]][j + temp2[k]] == '1' or mat[i + temp1[k]][j + temp2[k]] == 'F'):
					visited[i + temp1[k]][j + temp2[k]] = 1
					q.append((i + temp1[k], j + temp2[k]))
		q.popleft()
	if visited[-1][-1] == 1:
		return True
	return False
for t1 in range(t):
	n = int(input())
	mat1 = []
	for i in range(n):
		s = input().strip()
		l = []
		for j in range(n):
			l.append(s[j])
		mat1.append(l)
	l = [(n - 1, n - 2), (n - 2, n - 2), (n - 2, n - 1), (n - 1, n - 3), (n - 3, n - 1)]
	if check(f(mat1), []) == False:
		print(0)
	else:
		f1 = 0
		for i in range(5):
			if f1 == 1:
				break
			if check(f(mat1), [l[i]]) == False:
				print(1)
				print(l[i][0] + 1, l[i][1] + 1)
				break
			for j in range(5):
				c = f(mat1)
				if check(f(mat1), [l[i], l[j]]) == False:
					print(2)
					print(l[i][0] + 1, l[i][1] + 1)
					print(l[j][0] + 1, l[j][1] + 1)
					f1 = 1
					break


for _ in range(int(input())):
	l = []
	n = int(input())
	for _ in range(n):
		l.append(input())
	if (l[0][1] == '0' and l[1][0] == '0') and (l[-1][-2] == '0' and l[-2][-1] == '0'):
		print(2)
		print(1, 2)
		print(2, 1)
	elif (l[0][1] == '1' and l[1][0] == '1') and (l[-1][-2] == '1' and l[-2][-1] == '1'):
		print(2)
		print(1, 2)
		print(2, 1)
	elif (l[0][1] == '1' and l[1][0] == '1') and (l[-1][-2] == '0' and l[-2][-1] == '0'):
		print(0)
	elif (l[0][1] == '0' and l[1][0] == '0') and (l[-1][-2] == '1' and l[-2][-1] == '1'):
		print(0)
	elif (l[0][1] == '1' and l[1][0] == '0') and (l[-1][-2] == '1' and l[-2][-1] == '1'):
		print(1)
		print(1, 2)
	elif (l[0][1] == '0' and l[1][0] == '1') and (l[-1][-2] == '1' and l[-2][-1] == '1'):
		print(1)
		print(2, 1)
	elif (l[0][1] == '0' and l[1][0] == '1') and (l[-1][-2] == '0' and l[-2][-1] == '0'):
		print(1)
		print(1, 2)
	elif (l[0][1] == '1' and l[1][0] == '0') and (l[-1][-2] == '0' and l[-2][-1] == '0'):
		print(1)
		print(2, 1)
	elif (l[0][1] == '1' and l[1][0] == '1') and (l[-1][-2] == '0' and l[-2][-1] == '1'):
		print(1)
		print(n - 1, n)
	elif (l[0][1] == '1' and l[1][0] == '1') and (l[-1][-2] == '1' and l[-2][-1] == '0'):
		print(1)
		print(n, n - 1)
	elif (l[0][1] == '0' and l[1][0] == '0') and (l[-1][-2] == '1' and l[-2][-1] == '0'):
		print(1)
		print(n - 1, n)
	elif (l[0][1] == '0' and l[1][0] == '0') and (l[-1][-2] == '0' and l[-2][-1] == '1'):
		print(1)
		print(n, n - 1)
	elif (l[0][1] == '1' and l[1][0] == '0') and (l[-1][-2] == '1' and l[-2][-1] == '0'):
		print(2)
		print(1, 2)
		print(n - 1, n)
	elif (l[0][1] == '1' and l[1][0] == '0') and (l[-1][-2] == '0' and l[-2][-1] == '1'):
		print(2)
		print(1, 2)
		print(n, n - 1)
	elif (l[0][1] == '0' and l[1][0] == '1') and (l[-1][-2] == '1' and l[-2][-1] == '0'):
		print(2)
		print(1, 2)
		print(n, n - 1)
	elif (l[0][1] == '0' and l[1][0] == '1') and (l[-1][-2] == '0' and l[-2][-1] == '1'):
		print(2)
		print(1, 2)
		print(n - 1, n)


t = int(input())
for _ in range(t):
	n = int(input())
	l = [None] * n
	for i in range(n):
		l[i] = list(input().split())
	if int(l[n - 1][0][n - 2]) ^ int(l[n - 2][0][n - 1]):
		if int(l[0][0][1]) ^ int(l[1][0][0]):
			print(2)
			if int(l[n - 1][0][n - 2]) ^ int(l[0][0][1]):
				print(str(n) + ' ' + str(n - 1))
				print(str(1) + ' ' + str(2))
			else:
				print(str(n) + ' ' + str(n - 1))
				print(str(2) + ' ' + str(1))
		else:
			print(1)
			if int(l[1][0][0]) ^ int(l[n - 1][0][n - 2]):
				print(str(n - 1) + ' ' + str(n))
			else:
				print(str(n) + ' ' + str(n - 1))
	elif int(l[0][0][1]) ^ int(l[1][0][0]):
		print(1)
		if int(l[n - 1][0][n - 2]) ^ int(l[1][0][0]):
			print(str(1) + ' ' + str(2))
		else:
			print(str(2) + ' ' + str(1))
	elif int(l[0][0][1]) ^ int(l[n - 1][0][n - 2]):
		print(0)
	else:
		print(2)
		print(str(1) + ' ' + str(2))
		print(str(2) + ' ' + str(1))


import math, sys, os
from collections import defaultdict, deque, OrderedDict, Counter
import bisect as bi
from io import BytesIO, IOBase
mod = 10 ** 9 + 7
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def minp():
	return map(int, sys.stdin.readline().rstrip().split())

def linp():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def inp():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))

def BinarySearch(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	else:
		return -1

def gcd(a, b):
	return math.gcd(a, b)

def is_prime(n):
	if n < 5 or n & 1 == 0 or n % 3 == 0:
		return 2 <= n <= 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			p = p * p % n
			if p == n - 1:
				break
		else:
			return False
	return True

def mulinverse(a):
	return pow(a, mod - 2, mod)
for _ in range(inp()):
	n = inp()
	a = []
	for i in range(n):
		a.append(list(input()))
	for i in range(n):
		for j in range(n):
			if i == 0 and j == 0 or (i == n - 1 and j == n - 1):
				continue
			a[i][j] = int(a[i][j])
	xs = a[0][1]
	ys = a[1][0]
	xf = a[n - 1][n - 2]
	yf = a[n - 2][n - 1]
	if xs == ys and ys == xf and (xf == yf):
		print(2)
		print(n, n - 1)
		print(n - 1, n)
	elif xs == ys and xf == yf:
		print(0)
	elif xs == yf and ys == xf:
		print(2)
		print(1, 2)
		print(n, n - 1)
	elif xs == xf and ys == yf:
		print(2)
		print(1, 2)
		print(n - 1, n)
	elif xs == ys:
		print(1)
		if xf == xs:
			print(n, n - 1)
		else:
			print(n - 1, n)
	else:
		print(1)
		if xf == xs:
			print(1, 2)
		else:
			print(2, 1)


for _ in range(int(input())):
	a = []
	n = int(input())
	for i in range(n):
		s = input()
		if i == 0:
			a.append(int(s[1]))
		if i == 1:
			a.append(int(s[0]))
		if i == n - 2:
			a.append(int(s[n - 1]))
		if i == n - 1:
			a.append(int(s[n - 2]))
	x = sum(a)
	if a[0] == a[1] == a[2] == a[3]:
		print(2)
		print(1, 2)
		print(2, 1)
	elif (a[0] + a[1]) % 2 == 0 and (a[2] + a[3]) % 2 == 0:
		print(0)
	elif x % 2 == 1:
		print(1)
		if a[0] == 1 and x == 1 or (a[0] == 0 and x == 3):
			print(2, 1)
		elif a[1] == 1 and x == 1 or (a[1] == 0 and x == 3):
			print(1, 2)
		elif a[2] == 1 and x == 1 or (a[2] == 0 and x == 3):
			print(n, n - 1)
		else:
			print(n - 1, n)
	else:
		print(2)
		if a[0] == 1:
			print(1, 2)
		else:
			print(2, 1)
		if a[2] == 0:
			print(n - 1, n)
		else:
			print(n, n - 1)


my_input = int(input())
my_num = []
my_list = []
for i in range(my_input):
	temp_list = []
	inp = int(input())
	my_num.append(inp)
	my_list.append([])
	for j in range(inp):
		my_list[i].append(input())
	if my_list[i][0][1] == '1':
		temp_list.append([1, 2])
	if my_list[i][1][0] == '1':
		temp_list.append([2, 1])
	if my_list[i][inp - 1][-2] == '0':
		temp_list.append([inp, inp - 1])
	if my_list[i][inp - 2][-1] == '0':
		temp_list.append([inp - 1, inp])
	if len(temp_list) > 2:
		temp_list2 = []
		if my_list[i][0][1] == '0':
			temp_list2.append([1, 2])
		if my_list[i][1][0] == '0':
			temp_list2.append([2, 1])
		if my_list[i][inp - 1][-2] == '1':
			temp_list2.append([inp, inp - 1])
		if my_list[i][inp - 2][-1] == '1':
			temp_list2.append([inp - 1, inp])
		print(len(temp_list2))
		for k in range(len(temp_list2)):
			print(temp_list2[k][0], temp_list2[k][1])
	else:
		print(len(temp_list))
		for k in range(len(temp_list)):
			print(temp_list[k][0], temp_list[k][1])


def answer():
	n = int(input())
	a = []
	for i in range(n):
		z = input()
		a.append([x for x in str(z)])
	b1 = {a[0][1], a[1][0]}
	b2 = {a[n - 1][n - 2], a[n - 2][n - 1]}
	c = b1 & b2
	if len(c) == 0:
		print('0')
		return
	else:
		if len(c) == 1:
			if int(a[0][1]) ^ int(a[1][0]):
				if int(a[0][1]) ^ int(a[n - 1][n - 2]):
					print(len(c))
					print('2 1')
					return
				else:
					print(len(c))
					print('1 2')
					return
			if int(a[n - 1][n - 2]) ^ int(a[n - 2][n - 1]):
				if int(a[0][1]) ^ int(a[n - 1][n - 2]):
					print(len(c))
					print(n - 1, n)
					return
				else:
					print(len(c))
					print(n, n - 1)
					return
			if int(a[0][1]) == int(a[1][0]):
				print(len(c) + 1)
				print('1 2')
				print('2 1')
				return
		if len(c) == 2:
			if int(a[0][1]) ^ int(a[1][0]):
				if int(a[0][1]) ^ int(a[n - 1][n - 2]):
					print(len(c))
					print('1 2')
					print(n, n - 1)
					return
				else:
					print(len(c))
					print('1 2')
					print(n - 1, n)
					return
test = int(input())
i = 0
while i < test:
	answer()
	i += 1


for _ in range(int(input())):
	n = int(input())
	arr = []
	for row in range(n):
		arr.append(input())
	n = n + 1
	if arr[0][1] == arr[1][0] == arr[-2][-1] == arr[-1][-2]:
		print(2)
		print(n - 2, n - 1)
		print(n - 1, n - 2)
		continue
	elif arr[0][1] == arr[1][0]:
		if arr[-2][-1] == arr[-1][-2]:
			print(0)
		else:
			print(1)
			if arr[-2][-1] == arr[0][1]:
				print(n - 2, n - 1)
			else:
				print(n - 1, n - 2)
	elif arr[-2][-1] == arr[-1][-2]:
		if arr[0][1] == arr[1][0]:
			print(0)
		else:
			print(1)
			if arr[0][1] == arr[-2][-1]:
				print(1, 2)
			else:
				print(2, 1)
	else:
		ref = arr[0][1]
		print(2)
		print(2, 1)
		if arr[-2][-1] == ref:
			print(n - 2, n - 1)
		elif arr[-1][-2] == ref:
			print(n - 1, n - 2)


t = int(input())
while t:
	t -= 1
	n = int(input())
	g = []
	for i in range(n):
		l = list(map(str, input()))
		ln = len(l)
		g.append(l)
	s = [int(g[0][1]), int(g[1][0])]
	s1 = s[0]
	s2 = s[1]
	f = [int(g[n - 1][ln - 2]), int(g[n - 2][ln - 1])]
	f1 = f[0]
	f2 = f[1]
	if len(set(s)) == 1:
		if s1 == 1:
			if f1 == f2 == 1:
				print(2)
				print(n, ln - 1)
				print(n - 1, ln)
			elif f1 == f2 == 0:
				print(0)
			elif f2 == 1:
				print(1)
				print(n - 1, ln)
			else:
				print(1)
				print(n, ln - 1)
		elif f1 == f2 == 0:
			print(2)
			print(n, ln - 1)
			print(n - 1, ln)
		elif f1 == f2 == 1:
			print(0)
		elif f2 == 0:
			print(1)
			print(n - 1, ln)
		else:
			print(1)
			print(n, ln - 1)
	elif s1 == 0 and s2 == 1:
		if f1 == f2 == 1:
			print(1)
			print(2, 1)
		elif f1 == f2 == 0:
			print(1)
			print(1, 2)
		elif f2 == 1:
			print(2)
			print(1, 2)
			print(n - 1, ln)
		else:
			print(2)
			print(1, 2)
			print(n, ln - 1)
	elif f1 == f2 == 1:
		print(1)
		print(1, 2)
	elif f1 == f2 == 0:
		print(1)
		print(2, 1)
	elif f2 == 1:
		print(2)
		print(2, 1)
		print(n - 1, ln)
	else:
		print(2)
		print(2, 1)
		print(n, ln - 1)


from collections import defaultdict
T = int(input())
ans_c = [0] * T
ans_ls = [0] * T
for t in range(T):
	N = int(input())
	grid = [list(input()) for i in range(N)]
	d = defaultdict(int)
	ls = []
	for (y, x) in [[0, 1], [1, 0], [N - 1, N - 2], [N - 2, N - 1]]:
		d[grid[y][x]] += 1
	same_on_left = True
	if grid[0][1] != grid[1][0]:
		same_on_left = False
	same_on_right = True
	if grid[-1][-2] != grid[-2][-1]:
		same_on_right = False
	if len(d) == 1:
		ans_c[t] = 2
		ans_ls[t] = [[1, 2], [2, 1]]
		continue
	if d['0'] == d['1']:
		if same_on_left and same_on_right:
			ans_c[t] = 0
		else:
			ans_c[t] = 2
			for (y, x) in [[0, 1], [1, 0]]:
				if grid[y][x] == '0':
					ls.append([y + 1, x + 1])
			for (y, x) in [[N - 1, N - 2], [N - 2, N - 1]]:
				if grid[y][x] == '1':
					ls.append([y + 1, x + 1])
	else:
		ans_c[t] = 1
		if same_on_left:
			right = str(int(grid[0][1]) ^ 1)
			for (y, x) in [[N - 1, N - 2], [N - 2, N - 1]]:
				if grid[y][x] != right:
					ls.append([y + 1, x + 1])
		else:
			left = str(int(grid[N - 1][N - 2]) ^ 1)
			for (y, x) in [[0, 1], [1, 0]]:
				if grid[y][x] != left:
					ls.append([y + 1, x + 1])
	ans_ls[t] = ls
for t in range(T):
	print(ans_c[t])
	for ans in ans_ls[t]:
		print(*ans)


import os
import sys
from io import BytesIO, IOBase
import math

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def countcon(s, i):
	c = 0
	ch = s[i]
	for i in range(i, len(s)):
		if s[i] == ch:
			c += 1
		else:
			break
	return c

def change(c1, c2, c3, c4):
	if c1 != c2:
		if c3 == c4:
			if c3 != c1:
				return [[2, 1]]
			else:
				return [[1, 2]]
		elif c1 == c3:
			return [[2, 1], [n, n - 1]]
		else:
			return [[2, 1], [n - 1, n]]
	elif c3 == c4:
		if c3 != c1:
			return []
		else:
			return [[1, 2], [2, 1]]
	elif c3 != c1:
		return [[n - 1, n]]
	else:
		return [[n, n - 1]]
for xyz in range(0, int(input())):
	n = int(input())
	l = []
	for i in range(0, n):
		l.append(input())
	ans = change(l[0][1], l[1][0], l[-1][-2], l[-2][-1])
	print(len(ans))
	for i in ans:
		print(*i)


ncases = int(input())
for tcase in range(ncases):
	n = int(input())
	arr = [input() for i in range(n)]
	n1 = arr[0][1]
	n2 = arr[1][0]
	n3 = arr[n - 2][n - 1]
	n4 = arr[n - 1][n - 2]
	if n1 == n2 and n3 == n4:
		if not n1 == n3:
			print(0)
		else:
			print(2)
			print('1 2')
			print('2 1')
	elif not n1 == n2 and n3 == n4:
		if n1 == n3:
			print(1)
			print('1 2')
		else:
			print(1)
			print('2 1')
	elif n1 == n2 and (not n3 == n4):
		if n1 == n3:
			print(1)
			print(n - 1, n)
		else:
			print(1)
			print(n, n - 1)
	elif n1 == n3:
		print(2)
		print('1 2')
		print(n, n - 1)
	else:
		print(2)
		print('2 1')
		print(n, n - 1)


def process():
	n = int(input())
	li = []
	for i in range(n):
		li.append(list(input()))
	ans = []
	if li[0][1] != li[1][0] and li[n - 1][n - 2] != li[n - 2][n - 1]:
		if li[0][1] != '0':
			ans.append((0, 1))
		if li[1][0] != '0':
			ans.append((1, 0))
		if li[n - 1][n - 2] != '1':
			ans.append((n - 1, n - 2))
		if li[n - 2][n - 1] != '1':
			ans.append((n - 2, n - 1))
	elif li[0][1] == li[1][0] and li[n - 1][n - 2] == li[n - 2][n - 1]:
		if li[0][1] == li[n - 1][n - 2]:
			ans.append((0, 1))
		if li[1][0] == li[n - 1][n - 2]:
			ans.append((1, 0))
	elif li[0][1] == li[1][0]:
		if li[n - 1][n - 2] == li[1][0]:
			ans.append((n - 1, n - 2))
		if li[n - 2][n - 1] == li[1][0]:
			ans.append((n - 2, n - 1))
	elif li[n - 1][n - 2] == li[n - 2][n - 1]:
		if li[0][1] == li[n - 1][n - 2]:
			ans.append((0, 1))
		if li[1][0] == li[n - 1][n - 2]:
			ans.append((1, 0))
	print(len(ans))
	for i in ans:
		print(i[0] + 1, i[1] + 1)
tests = int(input())
for i in range(tests):
	process()


for _ in range(int(input())):
	n = int(input())
	g = []
	for _ in range(n):
		g.append([num for num in input()])
	a = g[0][1]
	b = g[1][0]
	p = 0
	c = g[n - 1][n - 2]
	d = g[n - 2][n - 1]
	ans = []
	if a == b:
		if c == d:
			if c == a:
				p = p + 2
				ans.append([n - 1, n])
				ans.append([n, n - 1])
			else:
				p = 0
		elif c != d:
			if c == a:
				p = p + 1
				ans.append([n, n - 1])
			elif a == d:
				p = p + 1
				ans.append([n - 1, n])
	if a != b:
		if c == d:
			if c == a:
				p = p + 1
				ans.append([1, 2])
			elif c == b:
				p = p + 1
				ans.append([2, 1])
		elif c != d:
			if c == a:
				p = p + 2
				ans.append([1, 2])
				ans.append([n - 1, n])
			if c == b:
				p = p + 2
				ans.append([2, 1])
				ans.append([n - 1, n])
	print(p)
	for i in range(p):
		print(ans[i][0], ans[i][1])


cases = int(input())
for _ in range(cases):
	n = int(input())
	grid = []
	for _ in range(n):
		grid.append(list(input()))
	op = cl = None
	perms = []
	if grid[0][1] == grid[1][0]:
		op = grid[0][1]
	if grid[-1][-2] == grid[-2][-1]:
		cl = grid[-1][-2]
	if op and cl and (op == cl):
		print(2)
		print(1, 2)
		print(2, 1)
	elif op and cl:
		print(0)
	elif op:
		print(1)
		if grid[-1][-2] == op:
			print(n, n - 1)
		else:
			print(n - 1, n)
	elif cl:
		print(1)
		if grid[0][1] == cl:
			print(1, 2)
		else:
			print(2, 1)
	else:
		print(2)
		print(1, 2)
		if grid[0][1] == grid[-1][-2]:
			print(n - 1, n)
		else:
			print(n, n - 1)


t = int(input())
for i in range(t):
	n = int(input())
	arr = []
	for i in range(n):
		temp = list(input())
		arr.append(temp)
	res = []
	cnt = 0
	if arr[0][1] == '0' and arr[1][0] == '0':
		if arr[n - 1][n - 2] == '0':
			cnt += 1
			res.append([n, n - 1])
		if arr[n - 2][n - 1] == '0':
			cnt += 1
			res.append([n - 1, n])
	if arr[0][1] == '1' and arr[1][0] == '1':
		if arr[n - 1][n - 2] == '1':
			cnt += 1
			res.append([n, n - 1])
		if arr[n - 2][n - 1] == '1':
			cnt += 1
			res.append([n - 1, n])
	if arr[0][1] == '0' and arr[1][0] == '1':
		if arr[n - 1][n - 2] == '0' and arr[n - 2][n - 1] == '0':
			cnt += 1
			res.append([1, 2])
		if arr[n - 1][n - 2] == '1' and arr[n - 2][n - 1] == '1':
			cnt += 1
			res.append([2, 1])
		if arr[n - 1][n - 2] == '1' and arr[n - 2][n - 1] == '0':
			cnt += 2
			res.append([2, 1])
			res.append([n - 1, n])
		if arr[n - 1][n - 2] == '0' and arr[n - 2][n - 1] == '1':
			cnt += 2
			res.append([2, 1])
			res.append([n, n - 1])
	if arr[0][1] == '1' and arr[1][0] == '0':
		if arr[n - 1][n - 2] == '0' and arr[n - 2][n - 1] == '0':
			cnt += 1
			res.append([2, 1])
		if arr[n - 1][n - 2] == '1' and arr[n - 2][n - 1] == '1':
			cnt += 1
			res.append([1, 2])
		if arr[n - 1][n - 2] == '1' and arr[n - 2][n - 1] == '0':
			cnt += 2
			res.append([2, 1])
			res.append([n, n - 1])
		if arr[n - 1][n - 2] == '0' and arr[n - 2][n - 1] == '1':
			cnt += 2
			res.append([2, 1])
			res.append([n - 1, n])
	if cnt == 0:
		print(0)
	else:
		print(cnt)
		for i in res:
			print(*i)


for _ in range(int(input())):
	n = int(input())
	arr = []
	for i in range(n):
		arr.append(input())
	s1 = arr[0][1]
	s2 = arr[1][0]
	e1 = arr[n - 2][n - 1]
	e2 = arr[n - 1][n - 2]
	ans = []
	if s1 == s2:
		if e1 == s1:
			ans.append((n - 2, n - 1))
		if e2 == s1:
			ans.append((n - 1, n - 2))
	elif e1 == e2:
		if s1 == e1:
			ans.append((0, 1))
		if s2 == e1:
			ans.append((1, 0))
	else:
		ans.append((0, 1))
		if e1 == s2:
			ans.append((n - 2, n - 1))
		else:
			ans.append((n - 1, n - 2))
	print(len(ans))
	for point in ans:
		print(point[0] + 1, point[1] + 1)


import sys
ans = 0

def fun(p, key1, key2):
	k = 0
	global ans
	ans = 0
	for i in range(1, -1, -1):
		if int(st[k][i]) != key1:
			ans += 1
			p.append((k + 1, i + 1))
		k += 1
	k = n - 2
	for i in range(n - 1, n - 3, -1):
		if int(st[k][i]) != key2:
			ans += 1
			p.append((k + 1, i + 1))
		k += 1
t = int(input())
for tc in range(t):
	n = int(input())
	st = list()
	for i in range(n):
		k = input()
		st.append(k)
	p = list()
	fun(p, 0, 1)
	if ans < 3:
		print(ans)
		for i in p:
			print(*i)
		continue
	p = list()
	fun(p, 1, 0)
	print(ans)
	for i in p:
		print(*i)


from sys import stdin, stdout
import bisect
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
from collections import Counter
from math import sqrt
import collections
import math
import heapq
import re

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def most_frequent(list):
	return max(set(list), key=list.count)

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def Convert(string):
	li = list(string.split(''))
	return li

def SieveOfEratosthenes(n):
	global prime
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
prime = []
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j

def main():
	for _ in range(int(input())):
		n = inin()
		a = []
		z1 = 0
		o1 = 0
		z2 = 0
		o2 = 0
		o = []
		z = []
		x = []
		for i in range(n):
			a.append(sin())
		if a[0][1] == '0':
			z1 += 1
			x.append(1)
		else:
			o1 += 1
		if a[1][0] == '0':
			z1 += 1
			x.append(2)
		else:
			o1 += 1
		if a[n - 2][n - 1] == '0':
			z2 += 1
			z.append(1)
		else:
			o2 += 1
			o.append(1)
		if a[n - 1][n - 2] == '0':
			z2 += 1
			z.append(2)
		else:
			o2 += 1
			o.append(2)
		if z1 == 0 and o2 == 0 or (z2 == 0 and o1 == 0):
			print('0')
			continue
		if z1 == 2:
			if z2 == 2:
				print('2')
				print(n, n - 1)
				print(n - 1, n)
			elif z2 == 1:
				print('1')
				if z[-1] == 2:
					print(n, n - 1)
				else:
					print(n - 1, n)
			continue
		if o1 == 2:
			if o2 == 2:
				print('2')
				print(n, n - 1)
				print(n - 1, n)
			elif z2 == 1:
				print('1')
				if o[-1] == 2:
					print(n, n - 1)
				else:
					print(n - 1, n)
			continue
		if o1 == 1:
			if z2 == 1:
				print(2)
				if x[-1] == 1:
					print(1, 2)
				else:
					print(2, 1)
				if o[-1] == 1:
					print(n - 1, n)
				else:
					print(n, n - 1)
			elif z2 == 0:
				print(1)
				if x[-1] == 1:
					print(2, 1)
				else:
					print(1, 2)
			else:
				print(1)
				if x[-1] == 1:
					print(1, 2)
				else:
					print(2, 1)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for i in range(t):
	n = int(input())
	a1 = 0
	a2 = 0
	a3 = 0
	a4 = 0
	for j in range(n):
		test = list(input())
		if j == 0:
			a1 = test[1]
		if j == 1:
			a2 = test[0]
		if j == n - 2:
			a3 = test[-1]
		if j == n - 1:
			a4 = test[-2]
	s = 8 * int(a4) + 4 * int(a3) + 2 * int(a2) + int(a1)
	if s == 15:
		print(2)
		print(2, 1)
		print(1, 2)
	if s == 14:
		print(1)
		print(2, 1)
	if s == 13:
		print(1)
		print(1, 2)
	if s == 12:
		print(0)
	if s == 11:
		print(1)
		print(n, n - 1)
	if s == 10:
		print(2)
		print(n, n - 1)
		print(1, 2)
	if s == 9:
		print(2)
		print(2, 1)
		print(n, n - 1)
	if s == 8:
		print(1)
		print(n - 1, n)
	if s == 7:
		print(1)
		print(n - 1, n)
	if s == 6:
		print(2)
		print(1, 2)
		print(n - 1, n)
	if s == 5:
		print(2)
		print(2, 1)
		print(n - 1, n)
	if s == 4:
		print(1)
		print(n, n - 1)
	if s == 3:
		print(0)
	if s == 2:
		print(1)
		print(1, 2)
	if s == 1:
		print(1)
		print(2, 1)
	if s == 0:
		print(2)
		print(1, 2)
		print(2, 1)


from sys import *
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	matrix = []
	for i in range(n):
		a = []
		s = input()
		for em in s[:-1]:
			if em == 'S' or em == 'F':
				a.append(em)
			else:
				a.append(int(em))
		matrix.append(a)
	ans = []
	if matrix[0][1] == matrix[1][0]:
		if matrix[n - 1][n - 2] == matrix[0][1]:
			ans.append((n, n - 1))
		if matrix[n - 2][n - 1] == matrix[0][1]:
			ans.append((n - 1, n))
	elif matrix[n - 1][n - 2] == matrix[n - 2][n - 1]:
		if matrix[n - 1][n - 2] == matrix[0][1]:
			ans.append((1, 2))
		if matrix[n - 2][n - 1] == matrix[1][0]:
			ans.append((2, 1))
	else:
		sn = matrix[n - 1][n - 2] + matrix[n - 2][n - 1] + matrix[1][0] + matrix[0][1]
		flag = -1
		if sn <= 2:
			flag = 1
		else:
			flag = 0
		if matrix[0][1] != flag and matrix[1][0] != flag:
			if matrix[n - 1][n - 2] == flag:
				ans.append((n, n - 1))
			if matrix[n - 2][n - 1] == flag:
				ans.append((n - 1, n))
		elif matrix[n - 1][n - 2] != flag and matrix[n - 2][n - 1] != flag:
			if matrix[0][1] == flag:
				ans.append((1, 2))
			if matrix[1][0] == flag:
				ans.append((2, 1))
		else:
			if matrix[n - 1][n - 2] == flag:
				matrix[n - 1][n - 2] = 1 - flag
				ans.append((n, n - 1))
			if matrix[n - 2][n - 1] == flag:
				matrix[n - 2][n - 1] = 1 - flag
				ans.append((n - 1, n))
			if matrix[0][1] != flag:
				matrix[0][1] = flag
				ans.append((1, 2))
			if matrix[1][0] != flag:
				matrix[1][0] = flag
				ans.append((2, 1))
	stdout.write(str(len(ans)) + '\n')
	for (x, y) in ans:
		stdout.write(str(x) + ' ' + str(y) + '\n')


for _ in range(int(input())):
	n = int(input())
	s = input()
	c1 = s[1]
	s = input()
	c2 = s[0]
	for i in range(max(n - 4, 0)):
		s = input()
	if n == 3:
		c3 = s[n - 1]
		s = input()
		c4 = s[n - 2]
	else:
		s = input()
		c3 = s[n - 1]
		s = input()
		c4 = s[n - 2]
	if c1 == c2:
		if c3 == c4:
			if c3 == c1:
				print(2)
				print(n - 1, n)
				print(n, n - 1)
			else:
				print(0)
		elif c3 == c1:
			print(1)
			print(n - 1, n)
		else:
			print(1)
			print(n, n - 1)
	elif c4 == c3:
		if c1 == c3:
			print(1)
			print(1, 2)
		else:
			print(1)
			print(2, 1)
	elif c1 == c3:
		print(2)
		print(1, 2)
		print(n, n - 1)
	else:
		print(2)
		print(1, 2)
		print(n - 1, n)


def solve():
	n = int(input())
	a = []
	for i in range(n):
		a.append(list(input()))
	s1 = int(a[0][1])
	s2 = int(a[1][0])
	f1 = int(a[n - 2][n - 1])
	f2 = int(a[n - 1][n - 2])
	c = 0
	d = []
	if s1 == s2:
		p = s1 ^ 1
		if f1 != p:
			c += 1
			d.append((n - 1, n))
		if f2 != p:
			c += 1
			d.append((n, n - 1))
	elif f1 == f2:
		p = f1 ^ 1
		if s1 != p:
			c += 1
			d.append((1, 2))
		if s2 != p:
			c += 1
			d.append((2, 1))
	else:
		if s1 != 0:
			c += 1
			d.append((1, 2))
		if s2 != 0:
			c += 1
			d.append((2, 1))
		if f1 != 1:
			c += 1
			d.append((n - 1, n))
		if f2 != 1:
			c += 1
			d.append((n, n - 1))
	print(c)
	for (x, y) in d:
		print(x, y)
t = int(input())
i = 0
while i < t:
	solve()
	i += 1


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(ri()):
		n = ri()
		z = []
		for i in range(n):
			z.append(list(rs()))
		(a, b, c, d) = (z[0][1], z[1][0], z[n - 1][n - 2], z[n - 2][n - 1])
		if a == b and c == d and (a != c):
			print(0)
		else:
			no = 0
			z1 = ['0', '0', '1', '1']
			z2 = ['1', '1', '0', '0']
			abcd = [a, b, c, d]
			i1 = 0
			i2 = 0
			ind1 = []
			ind2 = []
			for i in range(4):
				if z1[i] != abcd[i]:
					i1 += 1
					ind1.append(i)
				if z2[i] != abcd[i]:
					i2 += 1
					ind2.append(i)
			if i1 <= 2:
				print(i1)
				for i in ind1:
					if i == 0:
						print(1, 2)
					if i == 1:
						print(2, 1)
					if i == 2:
						print(n, n - 1)
					if i == 3:
						print(n - 1, n)
			else:
				print(i2)
				for i in ind2:
					if i == 0:
						print(1, 2)
					if i == 1:
						print(2, 1)
					if i == 2:
						print(n, n - 1)
					if i == 3:
						print(n - 1, n)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	N = int(input())
	a = [list(input())[:-1] for _ in range(N)]
	res = []
	if a[0][1] == a[1][0]:
		x = a[0][1]
		if a[-1][-2] == x:
			res.append((N, N - 1))
		if a[-2][-1] == x:
			res.append((N - 1, N))
	elif a[-1][-2] == a[-2][-1]:
		x = a[-1][-2]
		if a[0][1] == x:
			res.append((1, 2))
		if a[1][0] == x:
			res.append((2, 1))
	else:
		x = a[0][1]
		res.append((2, 1))
		if a[-1][-2] == x:
			res.append((N, N - 1))
		if a[-2][-1] == x:
			res.append((N - 1, N))
	print(len(res))
	for r in res:
		print(*r)


for _ in range(int(input())):
	n = int(input())
	mat = []
	for i in range(n):
		s = list(map(str, input().split()))
		slist = [j for j in s[0]]
		mat.append(slist)
	(a, b, c, d) = (mat[0][1], mat[1][0], mat[n - 2][n - 1], mat[n - 1][n - 2])
	(ai, bi, ci, di) = ([1, 2], [2, 1], [n - 1, n], [n, n - 1])
	if a == '1' and b == '1':
		if c == '0' and d == '0':
			print(0)
			continue
		elif c == '0' and d == '1':
			print(1)
			print(*di)
		elif c == '1' and d == '0':
			print(1)
			print(*ci)
		else:
			print(2)
			print(*ci)
			print(*di)
	elif a == '0' and b == '0':
		if c == '1' and d == '1':
			print(0)
			continue
		elif c == '0' and d == '1':
			print(1)
			print(*ci)
		elif c == '1' and d == '0':
			print(1)
			print(*di)
		else:
			print(2)
			print(*ci)
			print(*di)
	elif a == '0' and b == '1':
		if c == '1' and d == '1':
			print(1)
			print(*bi)
			continue
		elif c == '0' and d == '1':
			print(2)
			print(*ai)
			print(*di)
		elif c == '1' and d == '0':
			print(2)
			print(*ai)
			print(*ci)
		else:
			print(1)
			print(*ai)
	elif c == '1' and d == '1':
		print(1)
		print(*ai)
		continue
	elif c == '0' and d == '1':
		print(2)
		print(*bi)
		print(*di)
	elif c == '1' and d == '0':
		print(2)
		print(*bi)
		print(*ci)
	else:
		print(1)
		print(*bi)


import sys
input = lambda : sys.stdin.readline().rstrip()
from math import log
for _ in range(int(input())):
	n = int(input())
	a = [input() for _ in range(n)]
	ans = []
	if a[0][1] == a[1][0]:
		if a[n - 1][n - 2] == a[n - 2][n - 1]:
			if a[n - 1][n - 2] == a[0][1]:
				ans.append([n - 1, n])
				ans.append([n, n - 1])
		elif int(a[n - 1][n - 2]) != 1 - int(a[0][1]):
			ans.append([n, n - 1])
		else:
			ans.append([n - 1, n])
	elif a[n - 1][n - 2] == a[n - 2][n - 1]:
		if int(a[0][1]) != 1 - int(a[n - 1][n - 2]):
			ans.append([1, 2])
		else:
			ans.append([2, 1])
	else:
		if a[0][1] == '0':
			ans.append([1, 2])
		else:
			ans.append([2, 1])
		if a[n - 1][n - 2] == '0':
			ans.append([n - 1, n])
		else:
			ans.append([n, n - 1])
	print(len(ans))
	for x in ans:
		print(*x)


import sys
input = sys.stdin.readline
T = int(input())
for case in range(T):
	n = int(input())
	M = [[0 for i in range(n)] for j in range(n)]
	for i in range(n):
		s = input()
		s = s[:len(s) - 1]
		M[i] = s
	if M[1][0] != M[0][1] and M[n - 1][n - 2] != M[n - 2][n - 1]:
		if M[1][0] != M[n - 2][n - 1]:
			print(2)
			print(2, 1)
			print(n - 1, n)
		else:
			print(2)
			print(2, 1)
			print(n, n - 1)
	elif M[1][0] == M[0][1] and M[n - 1][n - 2] == M[n - 2][n - 1]:
		if M[1][0] == M[n - 1][n - 2]:
			print(2)
			print(n, n - 1)
			print(n - 1, n)
		else:
			print(0)
	elif M[1][0] == M[0][1] and M[n - 1][n - 2] != M[n - 2][n - 1]:
		if M[1][0] == M[n - 1][n - 2]:
			print(1)
			print(n, n - 1)
		else:
			print(1)
			print(n - 1, n)
	elif M[1][0] != M[0][1] and M[n - 1][n - 2] == M[n - 2][n - 1]:
		if M[1][0] == M[n - 1][n - 2]:
			print(1)
			print(2, 1)
		else:
			print(1)
			print(1, 2)


def sa():
	return map(int, input().split())

def ra():
	return list(map(int, input().split()))

def mati(n):
	return [ra() for i in range(n)]

def ri():
	return int(input())
for _ in range(ri()):
	n = ri()
	g = [input() for i in range(n)]
	if g[0][1] == g[1][0] == g[-2][-1] == g[-1][-2]:
		print('2\n1 2\n2 1')
	elif g[0][1] == g[1][0] and g[-2][-1] != g[-1][-2]:
		if g[-2][-1] == g[1][0]:
			print('1\n{} {}'.format(n - 1, n))
		else:
			print('1\n{} {}'.format(n, n - 1))
	elif g[0][1] != g[1][0] and g[-2][-1] == g[-1][-2]:
		if g[-2][-1] == g[1][0]:
			print('1\n{} {}'.format(2, 1))
		else:
			print('1\n{} {}'.format(1, 2))
	elif g[0][1] != g[1][0] and g[-2][-1] != g[-1][-2]:
		if g[0][1] != g[-2][-1]:
			print('2\n{} {}\n{} {}'.format(1, 2, n - 1, n))
		else:
			print('2\n{} {}\n{} {}'.format(1, 2, n, n - 1))
	else:
		print(0)


t = int(input())
for q in range(0, t):
	n = int(input())
	a = []
	for i in range(0, n):
		a.append(list(input()))
	ans = []
	if a[0][1] == a[1][0] and a[n - 1][n - 2] == a[n - 2][n - 1] and (a[0][1] != a[n - 1][n - 2]):
		print(0)
	elif a[0][1] == a[1][0] and a[n - 1][n - 2] != a[n - 2][n - 1]:
		if a[0][1] == '1' and a[n - 1][n - 2] == '1':
			print(1)
			print(n, n - 1)
		elif a[0][1] == '1' and a[n - 2][n - 1] == '1':
			print(1)
			print(n - 1, n)
		elif a[0][1] == '0' and a[n - 1][n - 2] == '0':
			print(1)
			print(n, n - 1)
		elif a[0][1] == '0' and a[n - 2][n - 1] == '0':
			print(1)
			print(n - 1, n)
	elif a[0][1] != a[1][0] and a[n - 1][n - 2] == a[n - 2][n - 1]:
		if a[0][1] == '1' and a[n - 1][n - 2] == '1':
			print(1)
			print(1, 2)
		elif a[0][1] == '0' and a[n - 1][n - 2] == '0':
			print(1)
			print(1, 2)
		elif a[1][0] == '1' and a[n - 1][n - 2] == '1':
			print(1)
			print(2, 1)
		elif a[1][0] == '0' and a[n - 1][n - 2] == '0':
			print(1)
			print(2, 1)
	elif a[0][1] == a[1][0] and a[n - 1][n - 2] == a[n - 2][n - 1] and (a[0][1] == a[n - 1][n - 2]):
		print(2)
		print(1, 2)
		print(2, 1)
	else:
		print(2)
		if a[0][1] != a[n - 1][n - 2]:
			print(1, 2)
			print(n, n - 1)
		elif a[0][1] != a[n - 2][n - 1]:
			print(1, 2)
			print(n - 1, n)
		elif a[1][0] != a[n - 1][n - 2]:
			print(2, 1)
			print(n, n - 1)
		else:
			print(2, 1)
			print(n - 1, n)


import math
t = int(input())
for w in range(t):
	n = int(input())
	l = []
	for i in range(n):
		l.append(list(input()))
	c = 0
	l1 = []
	if l[0][1] == '0' and l[1][0] == '0':
		if l[-1][-2] == '0':
			c += 1
			l1.append((n, n - 1))
		if l[-2][-1] == '0':
			c += 1
			l1.append((n - 1, n))
	elif l[0][1] == '1' and l[1][0] == '1':
		if l[-1][-2] == '1':
			c += 1
			l1.append((n, n - 1))
		if l[-2][-1] == '1':
			c += 1
			l1.append((n - 1, n))
	elif l[0][1] == '0' and l[1][0] == '1':
		if l[-1][-2] == '0' and l[-2][-1] == '0':
			c += 1
			l1.append((1, 2))
		elif l[-1][-2] == '1' and l[-2][-1] == '1':
			c += 1
			l1.append((2, 1))
		elif l[-1][-2] == '0' and l[-2][-1] == '1':
			c += 2
			l1.append((1, 2))
			l1.append((n - 1, n))
		else:
			c += 2
			l1.append((1, 2))
			l1.append((n, n - 1))
	elif l[-1][-2] == '0' and l[-2][-1] == '0':
		c += 1
		l1.append((2, 1))
	elif l[-1][-2] == '1' and l[-2][-1] == '1':
		c += 1
		l1.append((1, 2))
	elif l[-1][-2] == '0' and l[-2][-1] == '1':
		c += 2
		l1.append((2, 1))
		l1.append((n - 1, n))
	else:
		c += 2
		l1.append((2, 1))
		l1.append((n, n - 1))
	print(c)
	for i in l1:
		print(i[0], i[1])


import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
from bisect import *
from math import sqrt, pi, ceil
import math
from itertools import permutations
from copy import deepcopy

def main():
	for t in range(int(input())):
		n = int(input())
		a = []
		for i in range(n):
			a.append(list(input().rstrip()))
		f = [a[n - 1][-2], a[n - 2][-1]]
		s = [a[0][1], a[1][0]]
		if f[0] == '0' and f[1] == '0':
			if s[0] == '1' and s[1] == '1':
				print(0)
			elif s[0] == '1' and s[1] == '0':
				print(1)
				print(2, 1)
			elif s[0] == '0' and s[1] == '0':
				print(2)
				print(1, 2)
				print(2, 1)
			else:
				print(1)
				print(1, 2)
		elif f[0] == '1' and f[1] == '1':
			if s[0] == '1' and s[1] == '1':
				print(2)
				print(1, 2)
				print(2, 1)
			elif s[0] == '1' and s[1] == '0':
				print(1)
				print(1, 2)
			elif s[0] == '0' and s[1] == '1':
				print(1)
				print(2, 1)
			else:
				print(0)
		elif f[0] == '1' and f[1] == '0':
			if s[0] == '1' and s[1] == '1':
				print(1)
				print(n, n - 1)
			elif s[0] == '1' and s[1] == '0':
				print(2)
				print(2, 1)
				print(n, n - 1)
			elif s[0] == '0' and s[1] == '1':
				print(2)
				print(2, 1)
				print(n - 1, n)
			else:
				print(1)
				print(n - 1, n)
		elif s[0] == '1' and s[1] == '1':
			print(1)
			print(n - 1, n)
		elif s[0] == '1' and s[1] == '0':
			print(2)
			print(2, 1)
			print(n - 1, n)
		elif s[0] == '0' and s[1] == '1':
			print(2)
			print(2, 1)
			print(n, n - 1)
		else:
			print(1)
			print(n, n - 1)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for ii in range(int(input())):
	n = int(input())
	(a, c, ans) = ([], 0, '')
	for jj in range(n):
		a.append(input())
	(sr, sd, eu, el) = (a[0][1], a[1][0], a[n - 2][n - 1], a[n - 1][n - 2])
	if sr == sd:
		if el == sr:
			c += 1
			ans += str(n) + ' ' + str(n - 1) + '\n'
		if eu == sr:
			c += 1
			ans += str(n - 1) + ' ' + str(n) + '\n'
	elif sr == '0' and sd == '1':
		if eu == '1' and el == '1':
			c += 1
			ans += str(2) + ' ' + str(1) + '\n'
		elif eu == '0' and el == '0':
			c += 1
			ans += str(1) + ' ' + str(2) + '\n'
		elif eu == '0' and el == '1':
			c += 2
			ans += str(1) + ' ' + str(2) + '\n'
			ans += str(n) + ' ' + str(n - 1) + '\n'
		else:
			c += 2
			ans += str(1) + ' ' + str(2) + '\n'
			ans += str(n - 1) + ' ' + str(n) + '\n'
	elif eu == '1' and el == '1':
		c += 1
		ans += str(1) + ' ' + str(2) + '\n'
	elif eu == '0' and el == '0':
		c += 1
		ans += str(2) + ' ' + str(1) + '\n'
	elif eu == '0' and el == '1':
		c += 2
		ans += str(1) + ' ' + str(2) + '\n'
		ans += str(n - 1) + ' ' + str(n) + '\n'
	else:
		c += 2
		ans += str(1) + ' ' + str(2) + '\n'
		ans += str(n) + ' ' + str(n - 1) + '\n'
	print(c)
	print(ans.rstrip())


t = int(input())
for ti in range(t):
	n = int(input())
	for i in range(n):
		s = input()
		if i == 0:
			k1 = int(s[1])
		if i == 1:
			k2 = int(s[0])
		if i == n - 2:
			k3 = int(s[-1])
		if i == n - 1:
			k4 = int(s[-2])
	if k1 == k2:
		if k3 == k4 == k1:
			print(2)
			print(1, 2)
			print(2, 1)
		elif k3 == k4 == 1 - k1:
			print(0)
		elif k3 == k1:
			print(1)
			print(n - 1, n)
		else:
			print(1)
			print(n, n - 1)
	elif k3 == k4:
		if k1 == k3 == 1 - k2:
			print(1)
			print(1, 2)
		elif k2 == k3 == 1 - k1:
			print(1)
			print(2, 1)
	elif k2 == k3:
		print(2)
		print(1, 2)
		print(n - 1, n)
	else:
		print(2)
		print(2, 1)
		print(n - 1, n)


rn = lambda : int(input())
rl = lambda : list(map(int, input().split()))
rns = lambda : map(int, input().split())
rs = lambda : input()
yn = lambda x: print('Yes') if x else print('No')
YN = lambda x: print('YES') if x else print('NO')
for _ in range(rn()):
	n = rn()
	l = []
	for i in range(n):
		l.append(input())
	if l[0][1] == l[1][0]:
		res = 0
		ans = []
		if l[-1][-2] == l[0][1]:
			ans.append([n, n - 1])
			res += 1
		if l[-2][-1] == l[0][1]:
			ans.append([n - 1, n])
			res += 1
		print(res)
		for i in ans:
			print(*i)
	elif l[-1][-2] == l[-2][-1]:
		res = 0
		ans = []
		if l[-1][-2] == l[0][1]:
			ans.append([1, 2])
			res += 1
		if l[-2][-1] == l[1][0]:
			ans.append([2, 1])
			res += 1
		print(res)
		for i in ans:
			print(*i)
	else:
		print(2)
		print(2, 1)
		if l[-1][-2] == l[0][1]:
			print(n, n - 1)
		else:
			print(n - 1, n)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	plan = [[char for char in input().strip()] for i in range(n)]
	(count_a, inv_a, count_b, inv_b) = (0, [], 0, [])
	if plan[0][1] == '1':
		inv_a.append([1, 2])
		count_a += 1
	if plan[1][0] == '1':
		inv_a.append([2, 1])
		count_a += 1
	if plan[n - 2][n - 1] == '0':
		inv_a.append([n - 1, n])
		count_a += 1
	if plan[n - 1][n - 2] == '0':
		inv_a.append([n, n - 1])
		count_a += 1
	if plan[0][1] == '0':
		inv_b.append([1, 2])
		count_b += 1
	if plan[1][0] == '0':
		inv_b.append([2, 1])
		count_b += 1
	if plan[n - 2][n - 1] == '1':
		inv_b.append([n - 1, n])
		count_b += 1
	if plan[n - 1][n - 2] == '1':
		inv_b.append([n, n - 1])
		count_b += 1
	if count_a <= count_b:
		print(count_a)
		for inv in inv_a:
			print(*inv)
	else:
		print(count_b)
		for inv in inv_b:
			print(*inv)


def testcase():
	n = int(input())
	grid = []
	for _ in range(n):
		grid.append(input())
	(s1, s2) = (grid[0][1], grid[1][0])
	(f1, f2) = (grid[-1][-2], grid[-2][-1])
	if s1 == s2:
		if f1 == f2:
			if s1 == f1:
				print(2)
				print(1, 2)
				print(2, 1)
				return
			else:
				print(0)
				return
		else:
			if s1 == f1:
				print(1)
				print(n, n - 1)
				return
			if s2 == f2:
				print(1)
				print(n - 1, n)
				return
	elif f1 == f2:
		if s1 == f1:
			print(1)
			print(1, 2)
			return
		if s2 == f2:
			print(1)
			print(2, 1)
			return
	else:
		x = s2
		print(2)
		print(2, 1)
		if f1 == x:
			print(n - 1, n)
		else:
			print(n, n - 1)
	return
t = int(input())
for _ in range(t):
	testcase()


import sys
import math

def get_line():
	return list(map(str, sys.stdin.readline()))

def in1():
	return int(input())
for _ in range(in1()):
	n = in1()
	b = [[0 for i in range(n)] for j in range(n)]
	for j in range(n):
		c = list(get_line())
		for k in range(n):
			b[j][k] = c[k]
	x1 = b[0][1]
	y1 = b[1][0]
	x2 = b[n - 2][n - 1]
	y2 = b[n - 1][n - 2]
	if x1 == y1 and x2 == y2 and (x1 != x2):
		print(0)
	elif x1 == y1 and x2 == y2 and (x1 == x2):
		print(2)
		print(1, 2)
		print(2, 1)
	elif x1 == y1 and x2 != y2:
		print(1)
		if x2 == x1:
			print(n - 1, n)
		else:
			print(n, n - 1)
	elif x1 != y1 and x2 == y2:
		print(1)
		if x2 == x1:
			print(1, 2)
		else:
			print(2, 1)
	elif x1 != y1 and x2 != y2:
		print(2)
		if x1 == x2:
			print(1, 2)
			print(n, n - 1)
		else:
			print(1, 2)
			print(n - 1, n)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [0] * n
	for i in range(n):
		a[i] = input()
	if a[0][1] == a[1][0]:
		if a[n - 1][n - 2] == a[n - 2][n - 1]:
			if a[n - 2][n - 1] == a[1][0]:
				print(2)
				print(*[2, 1])
				print(*[1, 2])
			else:
				print(0)
		else:
			print(1)
			if a[n - 1][n - 2] == a[1][0]:
				print(*[n, n - 1])
			else:
				print(*[n - 1, n])
	elif a[n - 1][n - 2] == a[n - 2][n - 1]:
		print(1)
		if a[n - 1][n - 2] == a[1][0]:
			print(*[2, 1])
		else:
			print(*[1, 2])
	else:
		print(2)
		print(1, 2)
		if a[n - 1][n - 2] == a[1][0]:
			print(*[n, n - 1])
		else:
			print(*[n - 1, n])


t = int(input())
for _ in range(t):
	n = int(input())
	f = []
	for i in range(n):
		f.append(str(input()))
	a = f[1][0]
	b = f[0][1]
	c = f[-1][-2]
	d = f[-2][-1]
	if a == b:
		if c == d:
			if a != c:
				print(0)
			else:
				print(2)
				print(1, 2)
				print(2, 1)
		else:
			print(1)
			if c == a:
				print(n, n - 1)
			else:
				print(n - 1, n)
	elif c == d:
		print(1)
		if a == c:
			print(2, 1)
		else:
			print(1, 2)
	else:
		print(2)
		if a == c:
			print(2, 1)
			print(n - 1, n)
		else:
			print(1, 2)
			print(n - 1, n)


import sys
import math
import random
from typing import List
input = sys.stdin.readline

class Cell:

	def __init__(self, a, row, col):
		self.a = a
		self.row = row
		self.col = col

	def value(self):
		return self.a[self.row][self.col]

def solve(n, c1, c2, c3, c4) -> List[Cell]:

	def convert(c1: Cell, c2: Cell, char):
		ans = []
		if c1.value() != char:
			ans.append(c1)
		if c2.value() != char:
			ans.append(c2)
		return ans
	sol1 = convert(c1, c2, '0') + convert(c3, c4, '1')
	sol2 = convert(c1, c2, '1') + convert(c3, c4, '0')
	return sol1 if len(sol1) < len(sol2) else sol2
T = int(input())
for t in range(T):
	N = int(input())
	A = []
	for i in range(N):
		A.append(input())
	solution = solve(N, Cell(A, 1, 0), Cell(A, 0, 1), Cell(A, N - 1, N - 2), Cell(A, N - 2, N - 1))
	print(len(solution))
	for cell in solution:
		print(cell.row + 1, cell.col + 1)


for _ in range(int(input())):
	nn = input()
	if nn == '':
		n = int(input())
	else:
		n = int(nn)
	l = []
	for _ in range(n):
		aa = input()
		if aa == '':
			a = list(input())
		else:
			a = list(aa)
		l.append(a)
	s1 = l[0][1]
	s2 = l[1][0]
	f1 = l[n - 2][n - 1]
	f2 = l[n - 1][n - 2]
	if s1 == '0' and s2 == '0':
		if f1 == '0' and f2 == '0':
			print(2)
			print(1, 2)
			print(2, 1)
		elif f1 == '0' and f2 == '1':
			print(1)
			print(n - 1, n)
		elif f1 == '1' and f2 == '0':
			print(1)
			print(n, n - 1)
		elif f1 == '1' and f2 == '1':
			print(0)
	elif s1 == '0' and s2 == '1':
		if f1 == '0' and f2 == '0':
			print(1)
			print(1, 2)
		elif f1 == '0' and f2 == '1':
			print(2)
			print(1, 2)
			print(n, n - 1)
		elif f1 == '1' and f2 == '0':
			print(2)
			print(1, 2)
			print(n - 1, n)
		elif f1 == '1' and f2 == '1':
			print(1)
			print(2, 1)
	elif s1 == '1' and s2 == '0':
		if f1 == '0' and f2 == '0':
			print(1)
			print(2, 1)
		elif f1 == '0' and f2 == '1':
			print(2)
			print(1, 2)
			print(n - 1, n)
		elif f1 == '1' and f2 == '0':
			print(2)
			print(1, 2)
			print(n, n - 1)
		elif f1 == '1' and f2 == '1':
			print(1)
			print(1, 2)
	elif s1 == '1' and s2 == '1':
		if f1 == '0' and f2 == '0':
			print(0)
		elif f1 == '0' and f2 == '1':
			print(1)
			print(n, n - 1)
		elif f1 == '1' and f2 == '0':
			print(1)
			print(n - 1, n)
		elif f1 == '1' and f2 == '1':
			print(2)
			print(1, 2)
			print(2, 1)


for _ in range(int(input())):
	n = int(input())
	a = [input() for i in range(n)]
	a1 = []
	a2 = []
	if a[0][1] != '0':
		a1.append([0, 1])
	if a[1][0] != '0':
		a1.append([1, 0])
	if a[n - 1][n - 2] != '1':
		a1.append([n - 1, n - 2])
	if a[n - 2][n - 1] != '1':
		a1.append([n - 2, n - 1])
	if a[0][1] != '1':
		a2.append([0, 1])
	if a[1][0] != '1':
		a2.append([1, 0])
	if a[n - 1][n - 2] != '0':
		a2.append([n - 1, n - 2])
	if a[n - 2][n - 1] != '0':
		a2.append([n - 2, n - 1])
	if len(a1) <= 2:
		print(len(a1))
		for (i, j) in a1:
			print(i + 1, j + 1)
	else:
		print(len(a2))
		for (i, j) in a2:
			print(i + 1, j + 1)


t = int(input())
for _ in range(t):
	ans = []
	final = []
	n = int(input())
	for i in range(n):
		s = input()
		lol = list(s)
		ans.append(s)
	a = ans[0][1]
	b = ans[1][0]
	x = ans[n - 2][n - 1]
	y = ans[n - 1][n - 2]
	if b != '0':
		final.append([2, 1])
	if a != '0':
		final.append([1, 2])
	if y != '1':
		final.append([n, n - 1])
	if x != '1':
		final.append([n - 1, n])
	if len(final) <= 2:
		print(len(final))
		for i in final:
			print(*i, end='\n')
	else:
		final = []
		if b != '1':
			final.append([2, 1])
		if a != '1':
			final.append([1, 2])
		if y != '0':
			final.append([n, n - 1])
		if x != '0':
			final.append([n - 1, n])
		print(len(final))
		for i in final:
			print(*i, end='\n')


for _ in range(int(input())):
	n = int(input())
	a = []
	s = ''
	for i in range(n):
		a.append(input())
		if i == 0:
			s += a[i][1] + a[i][2]
		if i == 1:
			s += a[i][0] + a[i][1]
		if i == 2:
			s += a[i][0]
	count = 0
	x = '01011'
	y = '10100'
	xl = []
	yl = []
	for i in range(5):
		if s[i] != x[i]:
			xl.append(i)
		else:
			yl.append(i)
	if len(xl) < len(yl):
		print(len(xl))
		for i in range(len(xl)):
			if xl[i] == 0:
				print(1, 2)
			elif xl[i] == 1:
				print(1, 3)
			elif xl[i] == 2:
				print(2, 1)
			elif xl[i] == 3:
				print(2, 2)
			else:
				print(3, 1)
	else:
		print(len(yl))
		for i in range(len(yl)):
			if yl[i] == 0:
				print(1, 2)
			elif yl[i] == 1:
				print(1, 3)
			elif yl[i] == 2:
				print(2, 1)
			elif yl[i] == 3:
				print(2, 2)
			else:
				print(3, 1)


def main():
	for i in range(int(input())):
		n = int(input())
		matx = []
		for i in range(n):
			x = list(input())
			matx.append(x)
		x = matx[n - 2][n - 1]
		y = matx[n - 1][n - 2]
		a = matx[0][1]
		b = matx[1][0]
		v = a + b + x + y
		if v == '0100' or v == '1011':
			print(1)
			print(1, 2)
		elif v == '0011' or v == '1100':
			print(0)
		elif v == '0111' or v == '1000':
			print(1)
			print(2, 1)
		elif v == '0110' or v == '1001':
			print(2)
			print(2, 1)
			print(n, n - 1)
		elif v == '0000' or v == '1111':
			print(2)
			print(1, 2)
			print(2, 1)
		elif v == '0101' or v == '1010':
			print(2)
			print(2, 1)
			print(n - 1, n)
		elif v == '1110' or v == '0001':
			print(1)
			print(n - 1, n)
		elif v == '0010' or v == '1101':
			print(1)
			print(n, n - 1)
main()


t = int(input())
for _ in range(t):
	n = int(input())
	matrix = []
	for i in range(n):
		arr = list(input())
		matrix.append(arr)
	ans = []
	if matrix[0][1] == '1' and matrix[1][0] == '1':
		if matrix[n - 1][n - 2] == '1':
			ans.append((n - 1, n - 2))
		if matrix[n - 2][n - 1] == '1':
			ans.append((n - 2, n - 1))
	elif matrix[0][1] == '0' and matrix[1][0] == '0':
		if matrix[n - 1][n - 2] == '0':
			ans.append((n - 1, n - 2))
		if matrix[n - 2][n - 1] == '0':
			ans.append((n - 2, n - 1))
	elif matrix[0][1] != matrix[1][0]:
		if matrix[n - 1][n - 2] == '1' and matrix[n - 2][n - 1] == '1':
			if matrix[0][1] == '1':
				ans.append((0, 1))
			else:
				ans.append((1, 0))
		elif matrix[n - 1][n - 2] == '0' and matrix[n - 2][n - 1] == '0':
			if matrix[0][1] == '0':
				ans.append((0, 1))
			else:
				ans.append((1, 0))
		else:
			if matrix[0][1] == '1':
				ans.append((0, 1))
			else:
				ans.append((1, 0))
			if matrix[n - 1][n - 2] == '0':
				ans.append((n - 1, n - 2))
			else:
				ans.append((n - 2, n - 1))
	length = len(ans)
	print(length)
	for i in range(length):
		print(f'{ans[i][0] + 1} {ans[i][1] + 1}')


def rl():
	return list(map(int, input().split()))

def arp(arr):
	return ' '.join([str(i) for i in arr])
from collections import deque, Counter
from math import ceil, sqrt, log2, log, floor
for _ in range(int(input())):
	(n,) = rl()
	i = 0
	ans = []
	while i < n:
		s = input()
		if i <= 1:
			if i == 0:
				ans.append(s[1])
			else:
				ans.append(s[0])
		if i >= n - 2:
			if i == n - 2:
				ans.append(s[-1])
			else:
				ans.append(s[-2])
		i += 1
	cout = []
	l = [(1, 2), (2, 1), (n - 1, n), (n, n - 1)]
	if ans[0] == ans[1] == ans[2] == ans[3]:
		cout.append((1, 2))
		cout.append((2, 1))
	elif ans[0] == '0' and ans[1] == '0' and (ans[2] == '0') and (ans[3] == '1'):
		cout.append(l[2])
	elif ans[0] == '0' and ans[1] == '0' and (ans[2] == '1') and (ans[3] == '0'):
		cout.append(l[3])
	elif ans[0] == '0' and ans[1] == '0' and (ans[2] == '1') and (ans[3] == '1'):
		pass
	elif ans[0] == '0' and ans[1] == '1' and (ans[2] == '0') and (ans[3] == '0'):
		cout.append(l[0])
	elif ans[0] == '0' and ans[1] == '1' and (ans[2] == '0') and (ans[3] == '1'):
		cout.append(l[0])
		cout.append(l[-1])
	elif ans[0] == '0' and ans[1] == '1' and (ans[2] == '1') and (ans[3] == '0'):
		cout.append(l[1])
		cout.append(l[-1])
	elif ans[0] == '0' and ans[1] == '1' and (ans[2] == '1') and (ans[3] == '1'):
		cout.append(l[1])
	elif ans[0] == '1' and ans[1] == '0' and (ans[2] == '0') and (ans[3] == '0'):
		cout.append(l[1])
	elif ans[0] == '1' and ans[1] == '0' and (ans[2] == '0') and (ans[3] == '1'):
		cout.append(l[0])
		cout.append(l[2])
	elif ans[0] == '1' and ans[1] == '0' and (ans[2] == '1') and (ans[3] == '0'):
		cout.append(l[0])
		cout.append(l[-1])
	elif ans[0] == '1' and ans[1] == '0' and (ans[2] == '1') and (ans[3] == '1'):
		cout.append(l[0])
	elif ans[0] == '1' and ans[1] == '1' and (ans[2] == '0') and (ans[3] == '0'):
		pass
	elif ans[0] == '1' and ans[1] == '1' and (ans[2] == '0') and (ans[3] == '1'):
		cout.append(l[-1])
	elif ans[0] == '1' and ans[1] == '1' and (ans[2] == '1') and (ans[3] == '0'):
		cout.append(l[2])
	elif ans[0] == '1' and ans[1] == '1' and (ans[2] == '1') and (ans[3] == '1'):
		cout.append(l[2])
		cout.append(l[-1])
	print(len(cout))
	for i in cout:
		print(*i)


t = int(input())
for _ in range(t):
	n = int(input())
	a = []
	for i in range(n):
		a += [input()]
	(s1, s2, f1, f2) = (a[0][1], a[1][0], a[n - 1][n - 2], a[n - 2][n - 1])
	if s1 == s2:
		if f1 != f2:
			if f1 == s1:
				print(1)
				print(n, n - 1)
			elif f2 == s1:
				print(1)
				print(n - 1, n)
		elif f1 != s1:
			print(0)
		else:
			print(2)
			print(n, n - 1)
			print(n - 1, n)
	elif f1 != f2:
		print(2)
		if f1 == s1:
			print(n, n - 1)
			print(2, 1)
		else:
			print(n - 1, n)
			print(2, 1)
	else:
		print(1)
		if f1 == s1:
			print(1, 2)
		else:
			print(2, 1)


T = int(input())
for z in range(T):
	n = int(input())
	l = list()
	for i in range(n):
		s = input()
		l.append(s)
	det1 = l[n - 1][n - 3] + l[n - 2][n - 2] + l[n - 3][n - 1]
	det2 = l[n - 1][n - 2] + l[n - 2][n - 1]
	if det2 == '11':
		if det1 == '111':
			print(2)
			print(n - 1, n)
			print(n, n - 1)
		elif det1 == '110':
			print(2)
			print(n, n - 2)
			print(n - 1, n - 1)
		elif det1 == '101':
			print(2)
			print(n, n - 2)
			print(n - 2, n)
		elif det1 == '100':
			print(1)
			print(n, n - 2)
		elif det1 == '011':
			print(2)
			print(n - 1, n - 1)
			print(n - 2, n)
		elif det1 == '010':
			print(1)
			print(n - 1, n - 1)
		elif det1 == '001':
			print(1)
			print(n - 2, n)
		elif det1 == '000':
			print(0)
	elif det2 == '00':
		if det1 == '000':
			print(2)
			print(n - 1, n)
			print(n, n - 1)
		elif det1 == '001':
			print(2)
			print(n, n - 2)
			print(n - 1, n - 1)
		elif det1 == '010':
			print(2)
			print(n, n - 2)
			print(n - 2, n)
		elif det1 == '011':
			print(1)
			print(n, n - 2)
		elif det1 == '100':
			print(2)
			print(n - 1, n - 1)
			print(n - 2, n)
		elif det1 == '101':
			print(1)
			print(n - 1, n - 1)
		elif det1 == '110':
			print(1)
			print(n - 2, n)
		elif det1 == '111':
			print(0)
	elif det2 == '10':
		if det1 == '111':
			print(1)
			print(n, n - 1)
		elif det1 == '110':
			print(2)
			print(n, n - 1)
			print(n - 2, n)
		elif det1 == '101':
			print(2)
			print(n - 1, n - 1)
			print(n, n - 1)
		elif det1 == '100':
			print(2)
			print(n, n - 2)
			print(n - 1, n)
		elif det1 == '011':
			print(2)
			print(n, n - 2)
			print(n, n - 1)
		elif det1 == '010':
			print(2)
			print(n - 1, n - 1)
			print(n - 1, n)
		elif det1 == '001':
			print(2)
			print(n - 2, n)
			print(n - 1, n)
		elif det1 == '000':
			print(1)
			print(n - 1, n)
	elif det2 == '01':
		if det1 == '000':
			print(1)
			print(n, n - 1)
		elif det1 == '001':
			print(2)
			print(n, n - 1)
			print(n - 2, n)
		elif det1 == '010':
			print(2)
			print(n - 1, n - 1)
			print(n, n - 1)
		elif det1 == '011':
			print(2)
			print(n, n - 2)
			print(n - 1, n)
		elif det1 == '100':
			print(2)
			print(n, n - 2)
			print(n, n - 1)
		elif det1 == '101':
			print(2)
			print(n - 1, n - 1)
			print(n - 1, n)
		elif det1 == '110':
			print(2)
			print(n - 2, n)
			print(n - 1, n)
		elif det1 == '111':
			print(1)
			print(n - 1, n)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	s = []
	for i in range(n):
		a = input()
		s.append(list(a))
	if s[0][1] == s[1][0]:
		if s[-1][-2] == s[-2][-1]:
			if s[-1][-2] == s[0][1]:
				print(2)
				print(n - 1, n)
				print(n, n - 1)
			else:
				print(0)
		elif s[-1][-2] == s[0][1]:
			print(1)
			print(n, n - 1)
		else:
			print(1)
			print(n - 1, n)
	elif s[-1][-2] == s[-2][-1]:
		if s[-1][-2] == s[0][1]:
			print(1)
			print(1, 2)
		else:
			print(1)
			print(2, 1)
	elif s[-1][-2] == s[0][1]:
		print(2)
		print(1, 2)
		print(n - 1, n)
	else:
		print(2)
		print(n, n - 1)
		print(1, 2)


from collections import Counter
from collections import OrderedDict
from collections import defaultdict

def freq_count(mylist):
	return Counter(mylist)
t = int(input())
for _ in range(t):
	n = int(input())
	grid = [list(input()) for x in range(n)]
	li = []
	c1 = 0
	if grid[1][0] == '1':
		li.append([2, 1])
		c1 += 1
	if grid[0][1] == '1':
		li.append([1, 2])
		c1 += 1
	if grid[n - 1][n - 2] == '0':
		li.append([n, n - 1])
		c1 += 1
	if grid[n - 2][n - 1] == '0':
		li.append([n - 1, n])
		c1 += 1
	if c1 > 3:
		print(0)
		continue
	if c1 == 3:
		print(1)
		if grid[1][0] == grid[0][1]:
			if grid[n - 1][n - 2] == '1':
				print(n, n - 1)
			if grid[n - 2][n - 1] == '1':
				print(n - 1, n)
			continue
		if grid[n - 1][n - 2] == grid[n - 2][n - 1]:
			if grid[1][0] == '0':
				print(2, 1)
			if grid[0][1] == '0':
				print(1, 2)
			continue
	print(c1)
	for i in range(c1):
		print(li[i][0], li[i][1])


import sys
from math import ceil, factorial, gcd
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify
MOD = 10 ** 9 + 7
INF = float('inf')
rl = lambda : list(map(int, sys.stdin.readline().split()))
for _ in range(int(input())):
	n = int(input())
	g = [sys.stdin.readline() for _ in range(n)]
	ans = []
	num = 0
	l = [g[0][1], g[1][0], g[n - 2][n - 1], g[n - 1][n - 2]]
	if len(set(l)) == 1:
		num += 2
		ans.append([1, 2])
		ans.append([2, 1])
	elif l[0] == l[1]:
		if l[1] == l[2]:
			num += 1
			ans.append([n - 1, n])
		if l[1] == l[3]:
			num += 1
			ans.append([n, n - 1])
	elif l[0] != l[1] and l[1] == l[2] == l[3]:
		num += 1
		ans.append([2, 1])
	elif l[0] != l[1] and l[0] == l[2] == l[3]:
		num += 1
		ans.append([1, 2])
	elif l[0] != l[1] and l[0] == l[2]:
		num += 2
		ans.append([1, 2])
		ans.append([n, n - 1])
	elif l[0] != l[1] and l[0] == l[3]:
		num += 2
		ans.append([1, 2])
		ans.append([n - 1, n])
	print(num)
	if num:
		for a in ans:
			print(*a)


for _ in range(int(input())):
	n = int(input())
	ans = []
	mat = [input() for k in range(n)]
	if mat[0][1] == '0' and mat[1][0] == '0':
		if mat[-1][-2] == '0':
			ans.append([n, n - 1])
		if mat[-2][-1] == '0':
			ans.append([n - 1, n])
	elif mat[0][1] == '1' and mat[1][0] == '1':
		if mat[-1][-2] == '1':
			ans.append([n, n - 1])
		if mat[-2][-1] == '1':
			ans.append([n - 1, n])
	elif mat[-1][-2] == '1' and mat[-2][-1] == '1':
		if mat[0][1] == '1':
			ans.append([1, 2])
		if mat[1][0] == '1':
			ans.append([2, 1])
	elif mat[-1][-2] == '0' and mat[-2][-1] == '0':
		if mat[0][1] == '0':
			ans.append([1, 2])
		if mat[1][0] == '0':
			ans.append([2, 1])
	else:
		if mat[-1][-2] == '0':
			ans.append([n, n - 1])
		if mat[-2][-1] == '0':
			ans.append([n - 1, n])
		if mat[0][1] == '1':
			ans.append([1, 2])
		if mat[1][0] == '1':
			ans.append([2, 1])
	print(len(ans))
	for e in ans:
		print(e[0], e[1])


t = int(input())
for _ in range(t):
	n = int(input())
	mat = [input() for _ in range(n)]
	ans = []
	if mat[0][1] == mat[1][0]:
		if mat[n - 2][n - 1] == mat[0][1]:
			ans.append([n - 2 + 1, n - 1 + 1])
		if mat[n - 1][n - 2] == mat[0][1]:
			ans.append([n - 1 + 1, n - 2 + 1])
	elif mat[n - 2][n - 1] == mat[n - 1][n - 2]:
		if mat[n - 2][n - 1] == mat[0][1]:
			ans.append([1, 2])
		else:
			ans.append([2, 1])
	elif mat[n - 2][n - 1] == mat[0][1]:
		ans.append([1, 2])
		ans.append([n - 1 + 1, n - 2 + 1])
	elif mat[n - 1][n - 2] == mat[0][1]:
		ans.append([1, 2])
		ans.append([n - 2 + 1, n - 1 + 1])
	elif mat[n - 2][n - 1] == mat[1][0]:
		ans.append([2, 1])
		ans.append([n - 1 + 1, n - 2 + 1])
	elif mat[n - 1][n - 2] == mat[1][0]:
		ans.append([2, 1])
		ans.append([n - 2 + 1, n - 1 + 1])
	print(len(ans))
	for i in ans:
		print(i[0], i[1])


import itertools
import math
import sys
from collections import defaultdict

def is_debug():
	return '--debug' in sys.argv

def stdin_wrapper():
	data = '3\n4\nS010\n0001\n1000\n111F\n3\nS10\n101\n01F\n5\nS0101\n00000\n01111\n11111\n0001F\n\n'
	for line in data.split('\n'):
		yield line
if not is_debug():

	def stdin_wrapper():
		while True:
			yield sys.stdin.readline()
inputs = stdin_wrapper()

def input_wrapper():
	return next(inputs)

def get_str():
	if is_debug():
		return input_wrapper()
	return input()

def get(_type):
	if _type == str:
		return get_str()
	return _type(input_wrapper())

def get_arr(_type):
	return [_type(x) for x in input_wrapper().split()]

def tuplerize(method):

	def wrap(*args, **kwargs):
		res = method(*args, **kwargs)
		if not isinstance(res, (tuple, list)):
			res = (res,)
		return res
	return wrap

@tuplerize
def solve(data):
	c = [int(data[0][1]), int(data[1][0]), int(data[-2][-1]), int(data[-1][-2])]
	coords = [(1, 2), (2, 1), (len(data) - 1, len(data)), (len(data), len(data) - 1)]
	if c[0] == c[1] and c[2] == c[3] and (c[0] != c[2]):
		return 0
	res = []
	if c[0] == c[1]:
		target = 1 - c[0]
		if c[2] != target:
			res.append(coords[2])
		if c[3] != target:
			res.append(coords[3])
	elif c[2] == c[3]:
		target = 1 - c[2]
		if c[0] != target:
			res.append(coords[0])
		if c[1] != target:
			res.append(coords[1])
	else:
		target = 0
		if c[0] != target:
			res.append(coords[0])
		if c[1] != target:
			res.append(coords[1])
		target = 1 - target
		if c[2] != target:
			res.append(coords[2])
		if c[3] != target:
			res.append(coords[3])
	return '{}\n{}'.format(len(res), '\n'.join([' '.join(list(map(str, c))) for c in res]))
t = get(int)
for _ in range(t):
	rows = get(int)
	data = []
	for _ in range(rows):
		data.append(get_str())
	print(*solve(data))


def read_int():
	return int(input())

def read_ints():
	return map(int, input().split(' '))
t = read_int()
for case_num in range(t):
	n = read_int()
	a = []
	for i in range(n):
		a.append(input())
	ans = []
	pos = [(0, 1), (1, 0), (n - 1, n - 2), (n - 2, n - 1)]
	target = '0011'
	for (i, p) in enumerate(pos):
		if a[p[0]][p[1]] != target[i]:
			ans.append((p[0] + 1, p[1] + 1))
	if len(ans) <= 2:
		print(len(ans))
		for (r, c) in ans:
			print(r, c)
	else:
		target = '1100'
		ans = []
		for (i, p) in enumerate(pos):
			if a[p[0]][p[1]] != target[i]:
				ans.append((p[0] + 1, p[1] + 1))
		print(len(ans))
		for (r, c) in ans:
			print(r, c)


t = int(input())
for i in range(t):
	n = int(input())
	grid = []
	for j in range(n):
		grid.append(input())
	s1 = grid[0][1]
	s2 = grid[1][0]
	s3 = grid[-2][-1]
	s4 = grid[-1][-2]
	if s1 == s2 == s3 == s4:
		print(2)
		print(1, 2)
		print(2, 1)
	elif s1 == s2 == s3:
		print(1)
		print(n - 1, n)
	elif s1 == s2 == s4:
		print(1)
		print(n, n - 1)
	elif s1 == s4 == s3:
		print(1)
		print(1, 2)
	elif s4 == s2 == s3:
		print(1)
		print(2, 1)
	elif s1 == s3:
		print(2)
		print(1, 2)
		print(n, n - 1)
	elif s1 == s4:
		print(2)
		print(1, 2)
		print(n - 1, n)
	else:
		print(0)


t = int(input())
for i in range(t):
	l = []
	n = int(input())
	for i in range(n):
		z = [i for i in input().split()]
		l.append(z)
	a = int(l[0][0][1])
	b = int(l[1][0][0])
	c = int(l[n - 2][0][n - 1])
	d = int(l[n - 1][0][n - 2])
	if a == b == c == d:
		print(2)
		print(1, 2)
		print(2, 1)
	if a == 1 and b == 0 and (c == 0) and (d == 0):
		print(1)
		print(2, 1)
	if a == 0 and b == 1 and (c == 0) and (d == 0):
		print(1)
		print(1, 2)
	if a == 1 and b == 1 and (c == 0) and (d == 0):
		print(0)
	if a == 0 and b == 0 and (c == 1) and (d == 1):
		print(0)
	if a == 0 and b == 0 and (c == 1) and (d == 0):
		print(1)
		print(n, n - 1)
	if a == 0 and b == 0 and (c == 0) and (d == 1):
		print(1)
		print(n - 1, n)
	if a == 0 and b == 1 and (c == 0) and (d == 1):
		print(2)
		print(2, 1)
		print(n - 1, n)
	if a == 0 and b == 1 and (c == 1) and (d == 1):
		print(1)
		print(2, 1)
	if a == 0 and b == 1 and (c == 1) and (d == 0):
		print(2)
		print(2, 1)
		print(n, n - 1)
	if a == 1 and b == 0 and (c == 0) and (d == 1):
		print(2)
		print(2, 1)
		print(n, n - 1)
	if a == 1 and b == 0 and (c == 1) and (d == 1):
		print(1)
		print(1, 2)
	if a == 1 and b == 0 and (c == 1) and (d == 0):
		print(2)
		print(1, 2)
		print(n, n - 1)
	if a == 1 and b == 1 and (c == 0) and (d == 1):
		print(1)
		print(n, n - 1)
	if a == 1 and b == 1 and (c == 1) and (d == 0):
		print(1)
		print(n - 1, n)


t = int(input())
for i in range(t):
	n = int(input())
	l = []
	for i in range(n):
		l.append(list(input()))
	if l[0][1] == '0' and l[1][0] == '0':
		if l[n - 2][n - 1] == '0' and l[n - 1][n - 2] == '0':
			print(2)
			print(n - 1, n)
			print(n, n - 1)
		elif l[n - 2][n - 1] == '0' and l[n - 1][n - 2] == '1':
			print(1)
			print(n - 1, n)
		elif l[n - 2][n - 1] == '1' and l[n - 1][n - 2] == '0':
			print(1)
			print(n, n - 1)
		elif l[n - 2][n - 1] == '1' and l[n - 1][n - 2] == '1':
			print(0)
	elif l[0][1] == '0' and l[1][0] == '1':
		if l[n - 2][n - 1] == '0' and l[n - 1][n - 2] == '0':
			print(1)
			print(1, 2)
		elif l[n - 2][n - 1] == '0' and l[n - 1][n - 2] == '1':
			print(2)
			print(1, 2)
			print(n, n - 1)
		elif l[n - 2][n - 1] == '1' and l[n - 1][n - 2] == '0':
			print(2)
			print(1, 2)
			print(n - 1, n)
		elif l[n - 2][n - 1] == '1' and l[n - 1][n - 2] == '1':
			print(1)
			print(2, 1)
	elif l[0][1] == '1' and l[1][0] == '0':
		if l[n - 2][n - 1] == '0' and l[n - 1][n - 2] == '0':
			print(1)
			print(2, 1)
		elif l[n - 2][n - 1] == '0' and l[n - 1][n - 2] == '1':
			print(2)
			print(2, 1)
			print(n, n - 1)
		elif l[n - 2][n - 1] == '1' and l[n - 1][n - 2] == '0':
			print(2)
			print(2, 1)
			print(n - 1, n)
		elif l[n - 2][n - 1] == '1' and l[n - 1][n - 2] == '1':
			print(1)
			print(1, 2)
	elif l[0][1] == '1' and l[1][0] == '1':
		if l[n - 2][n - 1] == '0' and l[n - 1][n - 2] == '0':
			print(0)
		elif l[n - 2][n - 1] == '0' and l[n - 1][n - 2] == '1':
			print(1)
			print(n, n - 1)
		elif l[n - 2][n - 1] == '1' and l[n - 1][n - 2] == '0':
			print(1)
			print(n - 1, n)
		elif l[n - 2][n - 1] == '1' and l[n - 1][n - 2] == '1':
			print(2)
			print(n - 1, n)
			print(n, n - 1)


a = int(input())
for i in range(0, a):
	b = int(input())
	arr = []
	for i in range(0, b):
		arr.append(input())
	n = b - 1
	if arr[0][1] == arr[1][0]:
		count = 0
		if arr[n - 1][n] == arr[0][1]:
			count = count + 1
		if arr[n][n - 1] == arr[0][1]:
			count = count + 1
		print(count)
		if arr[n - 1][n] == arr[0][1]:
			print(n, n + 1)
		if arr[n][n - 1] == arr[0][1]:
			print(n + 1, n)
	elif arr[n][n - 1] == arr[n - 1][n]:
		count = 0
		if arr[n - 1][n] == arr[0][1]:
			count = count + 1
		if arr[n][n - 1] == arr[1][0]:
			count = count + 1
		print(count)
		if arr[n - 1][n] == arr[0][1]:
			print(1, 2)
		if arr[n][n - 1] == arr[1][0]:
			print(2, 1)
	elif arr[1][1] == '0':
		count = 0
		if arr[1][0] == '1':
			if arr[2][0] == '1':
				count = count + 1
		elif arr[0][1] == '1':
			if arr[0][2] == '1':
				count = count + 1
		if arr[n - 1][n] == '0':
			count = count + 1
		else:
			count = count + 1
		print(count)
		if arr[1][0] == '1':
			if arr[2][0] == '1':
				print(3, 1)
		elif arr[0][1] == '1':
			if arr[0][2] == '1':
				print(1, 3)
		if arr[n - 1][n] == '0':
			print(n, n + 1)
		else:
			print(n + 1, n)
	elif arr[1][1] == '1':
		count = 0
		if arr[1][0] == '0':
			if arr[2][0] == '0':
				count = count + 1
		elif arr[0][1] == '0':
			if arr[0][2] == '0':
				count = count + 1
		if arr[n - 1][n] == '1':
			count = count + 1
		else:
			count = count + 1
		print(count)
		if arr[1][0] == '0':
			if arr[2][0] == '0':
				print(3, 1)
		elif arr[0][1] == '0':
			if arr[0][2] == '0':
				print(1, 3)
		if arr[n - 1][n] == '1':
			print(n, n + 1)
		else:
			print(n + 1, n)


for _ in range(int(input())):
	n = int(input())
	S = []
	for i in range(n):
		s = input()
		S.append(s)
	a = S[0][1]
	b = S[1][0]
	c = S[n - 1][n - 2]
	d = S[n - 2][n - 1]
	ans = []
	if a == b:
		if c == a:
			ans.append([n, n - 1])
		if d == a:
			ans.append([n - 1, n])
	elif c == d:
		if a == c:
			ans.append([1, 2])
		if b == c:
			ans.append([2, 1])
	else:
		if a == c:
			ans.append([1, 2])
			ans.append([n - 1, n])
		if a == d:
			ans.append([1, 2])
			ans.append([n, n - 1])
	print(len(ans))
	for i in ans:
		print(*i)


for _ in ' ' * int(input()):
	n = int(input())
	lst = []
	for i in range(n):
		s = list(input())
		lst.append(s)
	if lst[1][0] == '0' and lst[0][1] == '1' and (lst[n - 2][n - 1] == '0') and (lst[n - 1][n - 2] == '1'):
		print(2)
		print(2, 1)
		print(n, n - 1)
	elif lst[1][0] == '1' and lst[0][1] == '0' and (lst[n - 2][n - 1] == '1') and (lst[n - 1][n - 2] == '1'):
		print(1)
		print(2, 1)
	elif lst[1][0] == '1' and lst[0][1] == '0' and (lst[n - 2][n - 1] == '0') and (lst[n - 1][n - 2] == '1'):
		print(2)
		print(2, 1)
		print(n - 1, n)
	elif lst[1][0] == '0' and lst[0][1] == '1' and (lst[n - 2][n - 1] == '1') and (lst[n - 1][n - 2] == '0'):
		print(2)
		print(2, 1)
		print(n - 1, n)
	elif lst[1][0] == '1' and lst[0][1] == '0' and (lst[n - 2][n - 1] == '0') and (lst[n - 1][n - 2] == '0'):
		print(1)
		print(1, 2)
	elif lst[1][0] == '1' and lst[0][1] == '0' and (lst[n - 2][n - 1] == '1') and (lst[n - 1][n - 2] == '0'):
		print(2)
		print(2, 1)
		print(n, n - 1)
	elif lst[1][0] == '1' and lst[0][1] == '1' and (lst[n - 2][n - 1] == '0') and (lst[n - 1][n - 2] == '0'):
		print(0)
	elif lst[1][0] == '1' and lst[0][1] == '1' and (lst[n - 2][n - 1] == '0') and (lst[n - 1][n - 2] == '1'):
		print(1)
		print(n, n - 1)
	elif lst[1][0] == '1' and lst[0][1] == '1' and (lst[n - 2][n - 1] == '1') and (lst[n - 1][n - 2] == '0'):
		print(1)
		print(n - 1, n)
	elif lst[1][0] == '1' and lst[0][1] == '1' and (lst[n - 2][n - 1] == '1') and (lst[n - 1][n - 2] == '1'):
		print(2)
		print(2, 1)
		print(1, 2)
	elif lst[1][0] == '0' and lst[0][1] == '0' and (lst[n - 2][n - 1] == '0') and (lst[n - 1][n - 2] == '0'):
		print(2)
		print(2, 1)
		print(1, 2)
	elif lst[1][0] == '0' and lst[0][1] == '0' and (lst[n - 2][n - 1] == '0') and (lst[n - 1][n - 2] == '1'):
		print(1)
		print(n - 1, n)
	elif lst[1][0] == '0' and lst[0][1] == '1' and (lst[n - 2][n - 1] == '1') and (lst[n - 1][n - 2] == '1'):
		print(1)
		print(1, 2)
	elif lst[1][0] == '0' and lst[0][1] == '0' and (lst[n - 2][n - 1] == '1') and (lst[n - 1][n - 2] == '0'):
		print(1)
		print(n, n - 1)
	elif lst[1][0] == '0' and lst[0][1] == '0' and (lst[n - 2][n - 1] == '1') and (lst[n - 1][n - 2] == '1'):
		print(0)
	elif lst[1][0] == '0' and lst[0][1] == '1' and (lst[n - 2][n - 1] == '0') and (lst[n - 1][n - 2] == '0'):
		print(1)
		print(2, 1)


t = int(input())
for _ in range(t):
	n = int(input())
	l = []
	kl = []
	for i in range(n):
		l.append(input())
	kl.append(l[0][1])
	kl.append(l[1][0])
	kl.append(l[n - 2][n - 1])
	kl.append(l[n - 1][n - 2])
	i = 0
	for op in kl:
		if op == '0':
			i += 1
	if i == 4:
		print(2)
		print('1 2')
		print('2 1')
	elif i == 3:
		print(1)
		if kl[0] == '1':
			print('2 1')
		elif kl[1] == '1':
			print('1 2')
		elif kl[2] == '1':
			print(n, end=' ')
			print(n - 1)
		elif kl[3] == '1':
			print(n - 1, end=' ')
			print(n)
	elif i == 2:
		if not kl[0] == kl[1]:
			print(2)
			print('1 2')
			if kl[0] == kl[2]:
				print(n, end=' ')
				print(n - 1)
			else:
				print(n - 1, end=' ')
				print(n)
		else:
			print(0)
	elif i == 1:
		print(1)
		if kl[0] == '0':
			print('2 1')
		elif kl[1] == '0':
			print('1 2')
		elif kl[2] == '0':
			print(n, end=' ')
			print(n - 1)
		elif kl[3] == '0':
			print(n - 1, end=' ')
			print(n)
	elif i == 0:
		print(2)
		print('1 2')
		print('2 1')


for i in range(int(input())):
	l = [list(input()) for j in range(int(input()))]
	n = len(l)
	if l[0][1] == '0' and l[1][0] == '0':
		if l[n - 2][n - 1] == '0' and l[n - 1][n - 2] == '0':
			print(2)
			print(n, n - 1)
			print(n - 1, n)
		elif l[n - 2][n - 1] == '0':
			print(1)
			print(n - 1, n)
		elif l[n - 1][n - 2] == '0':
			print(1)
			print(n, n - 1)
		else:
			print(0)
	elif l[0][1] == '1' and l[1][0] == '1':
		if l[n - 2][n - 1] == '1' and l[n - 1][n - 2] == '1':
			print(2)
			print(n, n - 1)
			print(n - 1, n)
		elif l[n - 2][n - 1] == '1':
			print(1)
			print(n - 1, n)
		elif l[n - 1][n - 2] == '1':
			print(1)
			print(n, n - 1)
		else:
			print(0)
	elif l[n - 2][n - 1] == '0' and l[n - 1][n - 2] == '0':
		if l[0][1] == '0':
			print(1)
			print(1, 2)
		else:
			print(1)
			print(2, 1)
	elif l[n - 2][n - 1] == '1' and l[n - 1][n - 2] == '1':
		if l[0][1] == '1':
			print(1)
			print(1, 2)
		else:
			print(1)
			print(2, 1)
	elif l[0][1] == '1':
		if l[n - 2][n - 1] == '0':
			print(2)
			print(1, 2)
			print(n - 1, n)
		else:
			print(2)
			print(1, 2)
			print(n, n - 1)
	elif l[n - 2][n - 1] == '1':
		print(2)
		print(1, 2)
		print(n - 1, n)
	else:
		print(2)
		print(1, 2)
		print(n, n - 1)


t = int(input())
for you in range(t):
	n = int(input())
	l = []
	for i in range(n):
		s = input()
		l.append(s)
	if l[0][1] == l[1][0]:
		z = l[0][1]
		lo = []
		if l[-1][-2] == z:
			lo.append((n, n - 1))
		if l[-2][-1] == z:
			lo.append((n - 1, n))
		print(len(lo))
		for i in lo:
			print(i[0], i[1])
		continue
	if l[-1][-2] == l[-2][-1]:
		z = l[-1][-2]
		lo = []
		if l[0][1] == z:
			lo.append((1, 2))
		if l[1][0] == z:
			lo.append((2, 1))
		print(len(lo))
		for i in lo:
			print(i[0], i[1])
		continue
	lo = []
	if l[0][1] == '0':
		lo.append((1, 2))
	if l[1][0] == '0':
		lo.append((2, 1))
	if l[-2][-1] == '1':
		lo.append((n - 1, n))
	if l[-1][-2] == '1':
		lo.append((n, n - 1))
	print(len(lo))
	for i in lo:
		print(i[0], i[1])


import sys
INP = lambda : sys.stdin.readline().strip()
INT = lambda : int(INP())
MAP = lambda : map(int, INP().split())
ARR = lambda : [ord(i) - 48 for i in list(INP())]

def JOIN(arr, x=' '):
	return x.join([str(i) for i in arr])

def EXIT(x='NO'):
	print(x)
	exit()
for _ in range(INT()):
	n = INT()
	arr = [INP() for _ in range(n)]
	(a12, a21) = (int(arr[0][1]), int(arr[1][0]))
	(anm, amn) = (int(arr[-1][-2]), int(arr[-2][-1]))
	del arr
	if a12 == a21:
		if anm == amn:
			if a12 == anm:
				print(2)
				print(1, 2)
				print(2, 1)
			else:
				print(0)
		elif a12 == anm:
			print(1)
			print(n, n - 1)
		else:
			print(1)
			print(n - 1, n)
	elif anm == amn:
		if a12 == anm:
			print(1)
			print(1, 2)
		else:
			print(1)
			print(2, 1)
	elif a12 == anm:
		print(2)
		print(2, 1)
		print(n, n - 1)
	else:
		print(2)
		print(1, 2)
		print(n, n - 1)


for _ in range(int(input())):
	n = int(input())
	grid = [input() for i in range(n)]
	p = []
	count = 0
	if grid[0][1] == '0' and grid[1][0] == '0' and (grid[n - 1][n - 2] == '1') and (grid[n - 2][n - 1] == '1'):
		print(0)
		continue
	elif grid[0][1] == '1' and grid[1][0] == '1' and (grid[n - 1][n - 2] == '0') and (grid[n - 2][n - 1] == '0'):
		print(0)
		continue
	elif grid[0][1] == '0' and grid[1][0] == '0':
		if grid[n - 1][n - 2] != '1':
			count += 1
			p.append((n - 1, n - 2))
		if grid[n - 2][n - 1] != '1':
			count += 1
			p.append((n - 2, n - 1))
	elif grid[0][1] == '1' and grid[1][0] == '1':
		if grid[n - 1][n - 2] != '0':
			count += 1
			p.append((n - 1, n - 2))
		if grid[n - 2][n - 1] != '0':
			count += 1
			p.append((n - 2, n - 1))
	elif grid[n - 1][n - 2] == '0' and grid[n - 2][n - 1] == '0':
		if grid[0][1] != '1':
			count += 1
			p.append((0, 1))
		if grid[1][0] != '1':
			count += 1
			p.append((1, 0))
	elif grid[n - 1][n - 2] == '1' and grid[n - 2][n - 1] == '1':
		if grid[0][1] != '0':
			count += 1
			p.append((0, 1))
		if grid[1][0] != '0':
			count += 1
			p.append((1, 0))
	elif grid[0][1] == '0' and grid[1][0] == '1':
		if grid[n - 1][n - 2] == '1' and grid[n - 2][n - 1] == '1':
			p.append((1, 0))
			count += 1
		elif grid[n - 1][n - 2] == '0' and grid[n - 2][n - 1] == '0':
			p.append((0, 1))
			count += 1
		elif grid[n - 1][n - 2] == '1' and grid[n - 2][n - 1] == '0':
			p.append((n - 1, n - 2))
			p.append((0, 1))
			count += 2
		elif grid[n - 1][n - 2] == '0' and grid[n - 2][n - 1] == '1':
			p.append((1, 0))
			p.append((n - 1, n - 2))
			count += 2
	elif grid[0][1] == '1' and grid[1][0] == '0':
		if grid[n - 1][n - 2] == '1' and grid[n - 2][n - 1] == '1':
			p.append((0, 1))
			count += 1
		elif grid[n - 1][n - 2] == '0' and grid[n - 2][n - 1] == '0':
			p.append((1, 0))
			count += 1
		elif grid[n - 1][n - 2] == '1' and grid[n - 2][n - 1] == '0':
			p.append((n - 1, n - 2))
			p.append((1, 0))
			count += 2
		elif grid[n - 1][n - 2] == '0' and grid[n - 2][n - 1] == '1':
			p.append((1, 0))
			p.append((n - 2, n - 1))
			count += 2
	elif grid[n - 1][n - 2] == '0' and grid[n - 2][n - 1] == '1':
		if grid[0][1] == '1' and grid[1][0] == '1':
			p.append((n - 1, n - 2))
			count += 1
		elif grid[0][1] == '0' and grid[1][0] == '0':
			p.append((n - 1, n - 2))
			count += 1
		elif grid[0][1] == '1' and grid[1][0] == '0':
			p.append((1, 0))
			p.append((n - 2, n - 1))
			count += 2
		else:
			p.append((0, 1))
			p.append((n - 1, n - 2))
			count += 1
	print(count)
	for i in p:
		print(i[0] + 1, i[1] + 1)


def solution():
	n = int(input())
	l = []
	for i in range(n):
		a = list(input())
		l.append(a)
	ans = []
	if l[1][0] == l[0][1]:
		if l[n - 2][n - 1] == l[1][0]:
			ans.append([n - 1, n])
		if l[n - 1][n - 2] == l[1][0]:
			ans.append([n, n - 1])
	elif l[n - 1][n - 2] == l[n - 2][n - 1]:
		if l[1][0] == l[n - 2][n - 1]:
			ans.append([2, 1])
		if l[0][1] == l[n - 1][n - 2]:
			ans.append([1, 2])
	else:
		if l[1][0] == l[n - 1][n - 2]:
			ans.append([n, n - 1])
		if l[1][0] == l[n - 2][n - 1]:
			ans.append([n - 1, n])
		ans.append([1, 2])
	print(len(ans))
	for i in range(len(ans)):
		print(ans[i][0], ans[i][1])
t = int(input())
for _ in range(t):
	solution()


from collections import deque, defaultdict
for _ in range(int(input())):
	n = int(input())
	mat = [[]]
	for i in range(n):
		a = [0] + list(input().strip())
		mat.append(a)
	one = [mat[1][2], mat[2][1]]
	two = [mat[n][n - 1], mat[n - 1][n]]
	if len(set(one + two)) == 1:
		print(2)
		print(n, n - 1)
		print(n - 1, n)
	elif len(set(one)) == 1 and len(set(two)) == 1 and (set(one) != set(two)):
		print(0)
	elif one[0] == one[1]:
		if one[0] == two[0]:
			print(1)
			print(n, n - 1)
		else:
			print(1)
			print(n - 1, n)
	elif two[0] == two[1]:
		if two[0] == one[0]:
			print(1)
			print(1, 2)
		else:
			print(1)
			print(2, 1)
	else:
		print(2)
		if one[0] == '1':
			print(2, 1)
		else:
			print(1, 2)
		if two[0] == '0':
			print(n - 1, n)
		else:
			print(n, n - 1)


import sys
import itertools
import math
input = sys.stdin.readline
I = lambda : list(map(str, input().split()))
(n,) = I()
n = int(n)
while n:
	n -= 1
	(k,) = I()
	k = int(k)
	arr = []
	for i in range(k):
		(g,) = I()
		arr.append(g)
	(a, b, x, y) = (int(arr[0][1]), int(arr[1][0]), int(arr[k - 1][k - 2]), int(arr[k - 2][k - 1]))
	if a == b and x == y and (a == x):
		print(2)
		print(1, 2)
		print(2, 1)
	elif a == b and x == y and (a != x):
		print(0)
	elif a == b:
		if x == a:
			print(1)
			print(k, k - 1)
		elif y == a:
			print(1)
			print(k - 1, k)
	elif x == y:
		if a == x:
			print(1)
			print(1, 2)
		else:
			print(1)
			print(2, 1)
	else:
		print(2)
		if a == 1:
			print(1, 2)
		elif b == 1:
			print(2, 1)
		if x == 0:
			print(k, k - 1)
		elif y == 0:
			print(k - 1, k)


def solv():
	x = int(input())
	s = [list(input()) for n in range(x)]
	ct = 0
	v = []
	if s[0][1] != '0':
		ct += 1
		v.append([1, 2])
	if s[1][0] != '0':
		ct += 1
		v.append([2, 1])
	if s[x - 1][x - 2] != '1':
		ct += 1
		v.append([x, x - 1])
	if s[x - 2][x - 1] != '1':
		ct += 1
		v.append([x - 1, x])
	if ct <= 2:
		print(ct)
		for n in v:
			print(*n)
		return
	ct = 0
	v = []
	if s[0][1] != '1':
		ct += 1
		v.append([1, 2])
	if s[1][0] != '1':
		ct += 1
		v.append([2, 1])
	if s[x - 1][x - 2] != '0':
		ct += 1
		v.append([x, x - 1])
	if s[x - 2][x - 1] != '0':
		ct += 1
		v.append([x - 1, x])
	if ct <= 2:
		print(ct)
		for n in v:
			print(*n)
		return
for _ in range(int(input())):
	solv()


for _ in range(int(input())):
	n = int(input())
	arr = [list(input()) for _ in range(n)]
	res = []
	if arr[n - 2][n - 1] == arr[n - 1][n - 2]:
		if arr[0][1] == arr[n - 2][n - 1]:
			res.append((1, 2))
		if arr[1][0] == arr[n - 2][n - 1]:
			res.append((2, 1))
	elif arr[0][1] == arr[1][0]:
		if arr[n - 2][n - 1] == arr[0][1]:
			res.append((n - 1, n))
		if arr[n - 1][n - 2] == arr[0][1]:
			res.append((n, n - 1))
	else:
		if arr[0][1] == '1':
			res.append((1, 2))
		if arr[1][0] == '1':
			res.append((2, 1))
		if arr[n - 2][n - 1] == '0':
			res.append((n - 1, n))
		if arr[n - 1][n - 2] == '0':
			res.append((n, n - 1))
	print(len(res))
	for e in res:
		print(*e)


import os
import sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		n = int(input())
		a = [list(input()) for x in range(n)]
		tl = int(a[1][0])
		td = int(a[0][1])
		ru = int(a[n - 2][n - 1])
		rr = int(a[n - 1][n - 2])
		ans = []
		if tl != td and ru != rr:
			if tl == ru:
				print(2)
				print(2, 1)
				print(n, n - 1)
			elif tl == rr:
				print(2)
				print(1, 2)
				print(n, n - 1)
		elif tl == td == ru == rr:
			print(2)
			print(2, 1)
			print(1, 2)
		elif tl == td == 0 and ru == rr == 1 or (tl == td == 1 and ru == rr == 0):
			print(0)
		elif tl == td or ru == rr:
			print(1)
			if tl == td:
				if tl == rr:
					print(n, n - 1)
				else:
					print(n - 1, n)
			elif ru == rr:
				if rr == tl:
					print(2, 1)
				else:
					print(1, 2)
		else:
			print(2)
			print(2, 1)
			print(1, 2)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
for j in range(int(input())):
	(n, list1) = (int(input()), [])
	for i in range(n):
		z = [str(i) for i in sys.stdin.readline().strip()]
		list1.append(z)
	(a1, a2, b1, b2) = (list1[0][1], list1[1][0], list1[-1][-2], list1[-2][-1])
	if a2 == a1 and b2 == b1 and (a2 != b2):
		print(0)
	elif a2 == a1 == b2 == b1:
		print(2)
		print(1, 2)
		print(2, 1)
	elif a2 != a1 and b1 == b2:
		print(1)
		if a1 != b1:
			print(2, 1)
		else:
			print(1, 2)
	elif a2 == a1 and b2 != b1:
		print(1)
		if a1 != b1:
			print(n - 1, n)
		else:
			print(n, n - 1)
	elif a2 != a1 and b1 != b2:
		print(2)
		if a1 != b1:
			print(1, 2)
			print(n, n - 1)
		else:
			print(1, 2)
			print(n - 1, n)


l = []
for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		a.append(list(input()))
	if a[0][1] == a[1][0]:
		if a[n - 1][n - 2] == a[n - 2][n - 1]:
			if a[n - 1][n - 2] == a[0][1]:
				l.append('2')
				l.append('1 2')
				l.append('2 1')
			else:
				l.append('0')
		elif a[n - 1][n - 2] != a[0][1]:
			l.append('1')
			l.append(str(n - 1) + ' ' + str(n))
		else:
			l.append('1')
			l.append(str(n) + ' ' + str(n - 1))
	elif a[n - 1][n - 2] == a[n - 2][n - 1]:
		if a[n - 1][n - 2] != a[0][1]:
			l.append('1')
			l.append('2 1')
		else:
			l.append('1')
			l.append('1 2')
	elif a[0][1] != a[n - 2][n - 1]:
		l.append('2')
		l.append('1 2')
		l.append(str(n - 1) + ' ' + str(n))
	else:
		l.append('2')
		l.append('2 1')
		l.append(str(n - 1) + ' ' + str(n))
for i in l:
	print(i)


import sys
from array import array
import typing as Tp

def input():
	return sys.stdin.buffer.readline().decode('utf-8')

def output(*args):
	sys.stdout.buffer.write(('\n'.join(map(str, args)) + '\n').encode('utf-8'))

def main():
	t = int(input())
	ans_a = [''] * t
	for ti in range(t):
		n = int(input())
		mat = [input().rstrip() for _ in range(n)]
		cells = [mat[0][1], mat[1][0], mat[-1][-2], mat[-2][-1]]
		ans = []
		if len(set(cells)) == 1:
			ans.extend(['1 2', '2 1'])
		elif cells[0] == cells[1] and cells[2] == cells[3]:
			pass
		elif cells[0] == cells[1]:
			if cells[0] == cells[2]:
				ans.append(f'{n} {n - 1}')
			if cells[0] == cells[3]:
				ans.append(f'{n - 1} {n}')
		elif cells[2] == cells[3]:
			if cells[0] == cells[3]:
				ans.append('1 2')
			if cells[1] == cells[3]:
				ans.append('2 1')
		else:
			if cells[0] == '1':
				ans.append('1 2')
			if cells[1] == '1':
				ans.append('2 1')
			if cells[2] == '0':
				ans.append(f'{n} {n - 1}')
			if cells[3] == '0':
				ans.append(f'{n - 1} {n}')
		ans_a[ti] = f'{len(ans)}\n' + '\n'.join(ans)
	output(*ans_a)
main()


def solve(n, grid):
	l = [(1, 0), (0, 1), (-1, -2), (-2, -1)]
	cnt = 0
	for (x, y) in l:
		if (grid[x][y] == '1') ^ (x >= 0):
			cnt += 1
	ret = ''
	if cnt >= 2:
		ret += str(4 - cnt) + '\n'
		for (x, y) in l:
			if (grid[x][y] == '1') ^ (x < 0):
				ret += str(x % n + 1) + ' ' + str(y % n + 1) + '\n'
	else:
		ret += str(cnt) + '\n'
		for (x, y) in l:
			if (grid[x][y] == '1') ^ (x >= 0):
				ret += str(x % n + 1) + ' ' + str(y % n + 1) + '\n'
	return ret
for _ in range(int(input())):
	n = int(input())
	grid = [input() for _ in range(n)]
	print(solve(n, grid), end='')


import bisect

def solve(grid):
	oneone = grid[0][1]
	twoone = grid[1][0]
	lastleft = grid[-1][-2]
	lastup = grid[-2][-1]
	ans = []
	n = len(grid)
	if oneone == twoone:
		if lastleft == oneone:
			ans.append([n, n - 1])
			pass
		if lastup == oneone:
			ans.append([n - 1, n])
			pass
	elif lastleft == lastup:
		if lastleft == oneone:
			ans.append([1, 2])
			pass
		if lastleft == twoone:
			ans.append([2, 1])
			pass
	else:
		oneone = twoone
		ans.append([1, 2])
		if lastleft == oneone:
			ans.append([n, n - 1])
			pass
		if lastup == oneone:
			ans.append([n - 1, n])
			pass
	return ans
	pass
t = int(input())
ans = []
for i in range(t):
	n = int(input())
	grid = []
	for j in range(n):
		grid.append(list(input()))
	ans.append(solve(grid))
for test in ans:
	print(len(test))
	for ans in test:
		for ele in ans:
			print(ele, end=' ')
		print()


tc = int(input())

def solve(grid):
	n = len(grid)
	ans = [(1, 2), (2, 1), (n, n - 1), (n - 1, n)]
	(a, b) = (int(grid[0][1]), int(grid[1][0]))
	(c, d) = (int(grid[-1][-2]), int(grid[-2][-1]))
	cur = [a, b, c, d]
	ans1 = [1, 1, 0, 0]
	ans2 = [0, 0, 1, 1]
	diff1 = []
	for (a, b) in zip(cur, ans1):
		diff1.append(abs(a - b))
	diff2 = []
	for (a, b) in zip(cur, ans2):
		diff2.append(abs(a - b))
	ret = []
	if sum(diff1) <= sum(diff2):
		for i in range(len(diff1)):
			if diff1[i] == 1:
				ret.append(ans[i])
	else:
		for i in range(len(diff2)):
			if diff2[i] == 1:
				ret.append(ans[i])
	return (len(ret), ret)
for _ in range(tc):
	n = int(input())
	grid = []
	for _ in range(n):
		line = str(input())
		grid.append(line)
	(l, lst) = solve(grid)
	print(l)
	for (a, b) in lst:
		print(a, b)


t = int(input())
for i in range(t):
	n = int(input())
	l = []
	for j in range(n):
		s = input()
		l.append(s)
	a = l[0][1]
	b = l[1][0]
	c = l[n - 2][n - 1]
	d = l[n - 1][n - 2]
	if a == b:
		if c == a and d == a:
			print('2')
			print(n, n - 1)
			print(n - 1, n)
		elif c == a:
			print('1')
			print(n - 1, n)
		elif d == a:
			print('1')
			print(n, n - 1)
		else:
			print('0')
	elif c == d:
		if c == a and c == b:
			print('2')
			print('1 2')
			print('2 1')
		elif c == a:
			print('1')
			print('1 2')
		elif c == b:
			print('1')
			print('2 1')
		else:
			print('0')
	else:
		print('2')
		print('1 2')
		if a == c:
			print(n, n - 1)
		else:
			print(n - 1, n)


t = int(input())
for _ in range(t):
	n = int(input())
	field = [list(input()) for _ in range(n)]
	s = (int(field[0][1]), int(field[1][0]))
	f = (int(field[n - 1][-2]), int(field[n - 2][-1]))
	ans = 0
	coords = []
	if len(set(s)) == 1:
		if s[0] == f[0]:
			ans += 1
			coords.append((n, n - 1))
		if s[0] == f[1]:
			ans += 1
			coords.append((n - 1, n))
	elif len(set(f)) == 1:
		if f[0] == s[0]:
			ans += 1
			coords.append((1, 2))
		if f[0] == s[1]:
			ans += 1
			coords.append((2, 1))
	else:
		ans = 2
		if s[0] == 0:
			coords.append((2, 1))
		elif s[0] == 1:
			coords.append((1, 2))
		if f[0] == 1:
			coords.append((n - 1, n))
		elif f[0] == 0:
			coords.append((n, n - 1))
	print(ans)
	for coord in coords:
		print(*coord)


from sys import stdin
for _ in range(int(stdin.readline())):
	side = int(stdin.readline())
	board = []
	for i in range(side):
		board.append(stdin.readline().strip())
	a = board[0][1]
	b = board[1][0]
	c = board[side - 2][side - 1]
	d = board[side - 1][side - 2]
	if a == b:
		if a == '1':
			if c == d:
				if c == '1':
					print(2)
					print(2, 1)
					print(1, 2)
				else:
					print(0)
			elif c == '1':
				print(1)
				print(side - 1, side)
			else:
				print(1)
				print(side, side - 1)
		elif c == d:
			if c == '1':
				print(0)
			else:
				print(2)
				print(2, 1)
				print(1, 2)
		elif c == '1':
			print(1)
			print(side, side - 1)
		else:
			print(1)
			print(side - 1, side)
	elif a == '1':
		if d == c:
			if d == '1':
				print(1)
				print(1, 2)
			else:
				print(1)
				print(2, 1)
		elif d == '1':
			print(2)
			print(1, 2)
			print(side - 1, side)
		else:
			print(2)
			print(1, 2)
			print(side, side - 1)
	elif d == c:
		if d == '1':
			print(1)
			print(2, 1)
		else:
			print(1)
			print(1, 2)
	elif d == '1':
		print(2)
		print(2, 1)
		print(side - 1, side)
	else:
		print(2)
		print(2, 1)
		print(side, side - 1)


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = []
	for i in range(n):
		a.append(input())
	ans = []
	if a[0][1] == '0' and a[1][0] == '0':
		if a[n - 1][n - 2] == '1' and a[n - 2][n - 1] == '1':
			pass
		elif a[n - 1][n - 2] == '0' and a[n - 2][n - 1] == '0':
			ans.append([0, 1])
			ans.append([1, 0])
		elif a[n - 1][n - 2] == '0' and a[n - 2][n - 1] == '1':
			ans.append([n - 1, n - 2])
		else:
			ans.append([n - 2, n - 1])
	elif a[0][1] == '1' and a[1][0] == '1':
		if a[n - 1][n - 2] == '1' and a[n - 2][n - 1] == '1':
			ans.append([0, 1])
			ans.append([1, 0])
		elif a[n - 1][n - 2] == '0' and a[n - 2][n - 1] == '0':
			pass
		elif a[n - 1][n - 2] == '0' and a[n - 2][n - 1] == '1':
			ans.append([n - 2, n - 1])
		else:
			ans.append([n - 1, n - 2])
	elif a[0][1] == '1' and a[1][0] == '0':
		if a[n - 1][n - 2] == '1' and a[n - 2][n - 1] == '1':
			ans.append([0, 1])
		elif a[n - 1][n - 2] == '0' and a[n - 2][n - 1] == '0':
			ans.append([1, 0])
		elif a[n - 1][n - 2] == '0' and a[n - 2][n - 1] == '1':
			ans.append([n - 2, n - 1])
			ans.append([1, 0])
		else:
			ans.append([n - 1, n - 2])
			ans.append([1, 0])
	elif a[n - 1][n - 2] == '1' and a[n - 2][n - 1] == '1':
		ans.append([1, 0])
	elif a[n - 1][n - 2] == '0' and a[n - 2][n - 1] == '0':
		ans.append([0, 1])
	elif a[n - 1][n - 2] == '0' and a[n - 2][n - 1] == '1':
		ans.append([n - 1, n - 2])
		ans.append([1, 0])
	else:
		ans.append([n - 2, n - 1])
		ans.append([1, 0])
	print(len(ans))
	for i in ans:
		print(i[0] + 1, i[1] + 1)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	li = []
	for i in range(n):
		ali = input()
		ali = list(ali)
		li.append(ali)
	q = int(li[0][1])
	w = int(li[1][0])
	e = int(li[n - 2][n - 1])
	r = int(li[n - 1][n - 2])
	cnt = 0
	ans = []
	if q == 0 and w == 0:
		if e != 1:
			cnt += 1
			ans.append((n - 1, n))
		if r != 1:
			cnt += 1
			ans.append((n, n - 1))
	elif q == 1 and w == 1:
		if e != 0:
			cnt += 1
			ans.append((n - 1, n))
		if r != 0:
			cnt += 1
			ans.append((n, n - 1))
	elif e == r:
		if q == r:
			cnt += 1
			ans.append((1, 2))
		if w == r:
			cnt += 1
			ans.append((2, 1))
	else:
		if q != 0:
			cnt += 1
			ans.append((1, 2))
		else:
			cnt += 1
			ans.append((2, 1))
		if e != 1:
			cnt += 1
			ans.append((n - 1, n))
		else:
			cnt += 1
			ans.append((n, n - 1))
	print(cnt)
	for i in range(len(ans)):
		print(*ans[i])


from collections import deque
from collections import OrderedDict
from queue import PriorityQueue
import math
import sys
import os
import threading
import bisect
import operator
import queue
import heapq
from atexit import register
from io import BytesIO
import io
from sys import stdin, stdout
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	n = int(input())
	arD = [''] * n
	for i in range(n):
		arD[i] = input()
	st1 = arD[1][0] + arD[0][1] + arD[n - 1][n - 2] + arD[n - 2][n - 1]
	if st1.count('1') == 4 or st1.count('0') == 4:
		print(2)
		print(1, 2)
		print(2, 1)
	elif st1[0] == st1[1]:
		if st1[2] == st1[3]:
			print(0)
		else:
			print(1)
			if st1[2] == st1[0]:
				print(n, n - 1)
			else:
				print(n - 1, n)
	elif st1[2] == st1[3]:
		print(1)
		if st1[2] == st1[0]:
			print(2, 1)
		else:
			print(1, 2)
	else:
		print(2)
		if st1[0] == '1':
			print(2, 1)
		if st1[1] == '1':
			print(1, 2)
		if st1[2] == '0':
			print(n, n - 1)
		if st1[3] == '0':
			print(n - 1, n)


k = int(input())
for i in range(k):
	ans = []
	n = int(input())
	for i in range(n):
		ans.append(input())
	(a, b) = (ans[0][1], ans[1][0])
	(c, d) = (ans[-1][-2], ans[-2][-1])
	flag = 0
	for q in range(0, 2):
		if flag == 1:
			break
		for w in range(0, 2):
			if flag == 1:
				break
			for e in range(0, 2):
				if flag == 1:
					break
				for r in range(0, 2):
					if flag:
						break
					ans = 0
					if r != int(d):
						ans += 1
					if e != int(c):
						ans += 1
					if w != int(b):
						ans += 1
					if int(a) != q:
						ans += 1
					if (q == w and e == r and (q != e)) and ans <= 2:
						print(ans)
						if r != int(d):
							print(n - 1, n)
						if e != int(c):
							print(n, n - 1)
						if w != int(b):
							print(2, 1)
						if q != int(a):
							print(1, 2)
						flag = 1
						break


def ans(a, n):
	s1 = a[0][1]
	s2 = a[1][0]
	f2 = a[n - 1][n - 2]
	f1 = a[n - 2][n - 1]
	if f1 == f2 and s1 == s2 and (f1 != s1):
		print(0)
	elif f1 == f2 and f1 == s1 and (s1 == s2):
		print(2)
		print('1 2')
		print('2 1')
	elif f1 == f2:
		print(1)
		if s1 == f1:
			print('1 2')
		else:
			print('2 1')
	elif s1 == s2:
		print(1)
		if f2 == s1:
			print(str(n) + ' ' + str(n - 1))
		else:
			print(str(n - 1) + ' ' + str(n))
	else:
		print(2)
		if f1 == s1:
			print('1 2')
			print(str(n) + ' ' + str(n - 1))
		else:
			print('1 2')
			print(str(n - 1) + ' ' + str(n))
	return
m = int(input())
for j in range(m):
	n = int(input())
	a = []
	for i in range(n):
		b = input()
		a.append(b)
	ans(a, n)


for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		a.append(input())
	l = []
	if a[0][1] == a[1][0]:
		if a[-2][-1] == a[0][1]:
			l.append([n - 1, n])
		if a[-1][-2] == a[0][1]:
			l.append([n, n - 1])
	elif a[-1][-2] == a[-2][-1]:
		if a[0][1] == a[-1][-2]:
			l.append([1, 2])
		else:
			l.append([2, 1])
	else:
		l.append([1, 2])
		if a[0][1] == a[-1][-2]:
			l.append([n - 1, n])
		else:
			l.append([n, n - 1])
	print(len(l))
	for x in l:
		print(*x)


from collections import Counter, deque
GRID = []
SMALL_DIAGONAL = [(0, 1), (1, 0)]
BIG_DIAGONAL = [(0, 2), (1, 1), (2, 0)]

def get_input():
	return input().split()

def get_int_input():
	return map(int, get_input())

def _is_valid_cell(cell, n):
	if cell[0] >= n or cell[1] >= n:
		return False
	return True

def is_there_a_path(n):
	queue = deque([((0, 0), '0'), ((0, 0), '1')])
	FINAL_CELLS = [(n - 1, n - 2), (n - 2, n - 1)]
	while queue:
		(cell, digit) = queue.popleft()
		if cell in FINAL_CELLS:
			return True
		new_cell = (cell[0] + 1, cell[1])
		if _is_valid_cell(new_cell, n):
			if GRID[new_cell[0]][new_cell[1]] == digit:
				queue.append((new_cell, digit))
		new_cell = (cell[0], cell[1] + 1)
		if _is_valid_cell(new_cell, n):
			if GRID[new_cell[0]][new_cell[1]] == digit:
				queue.append((new_cell, digit))
	return False

def C1421B(n):
	ans_count = 0
	ans_cells = []
	if len(Counter([GRID[cell[0]][cell[1]] for cell in BIG_DIAGONAL])) == 1 and len(Counter([GRID[cell[0]][cell[1]] for cell in SMALL_DIAGONAL])) == 1 and (GRID[BIG_DIAGONAL[0][0]][BIG_DIAGONAL[0][1]] != GRID[SMALL_DIAGONAL[0][0]][SMALL_DIAGONAL[0][1]]):
		return 0
	elif len(Counter([GRID[cell[0]][cell[1]] for cell in BIG_DIAGONAL])) == 1:
		big_diagonal_value = GRID[BIG_DIAGONAL[0][0]][BIG_DIAGONAL[0][1]]
		for cell in SMALL_DIAGONAL:
			if GRID[cell[0]][cell[1]] == big_diagonal_value:
				ans_count += 1
				ans_cells.append(' '.join(map(str, [val + 1 for val in cell])))
	elif GRID[0][1] == GRID[1][0]:
		small_diagonal_value = GRID[SMALL_DIAGONAL[0][0]][SMALL_DIAGONAL[0][1]]
		for cell in BIG_DIAGONAL:
			if GRID[cell[0]][cell[1]] == small_diagonal_value:
				ans_count += 1
				ans_cells.append(' '.join(map(str, [val + 1 for val in cell])))
	else:
		counter = Counter([GRID[cell[0]][cell[1]] for cell in BIG_DIAGONAL])
		inv_counter = {counter[c]: c for c in counter}
		more_occurring_value = inv_counter.get(3, '') or inv_counter.get(2, '')
		for cell in SMALL_DIAGONAL:
			if GRID[cell[0]][cell[1]] == more_occurring_value:
				ans_count += 1
				ans_cells.append(' '.join(map(str, [val + 1 for val in cell])))
		for cell in BIG_DIAGONAL:
			if GRID[cell[0]][cell[1]] != more_occurring_value:
				ans_count += 1
				ans_cells.append(' '.join(map(str, [val + 1 for val in cell])))
	return str(ans_count) + '\n' + '\n'.join(ans_cells)

def main():
	(t,) = get_int_input()
	for _ in range(t):
		globals()['GRID'] = []
		(n,) = get_int_input()
		for _ in range(n):
			GRID.append(list(input()))
		print(C1421B(n))
main()


t = int(input())
for _ in range(t):
	n = int(input())
	up = [-1, -1]
	down = [-1, -1]
	for i in range(n):
		s = input()
		if i == 0:
			up[0] = s[1]
		elif i == 1:
			up[1] = s[0]
		if i == n - 2:
			down[0] = s[-1]
		elif i == n - 1:
			down[1] = s[-2]
	if up[0] == up[1] and down[0] == down[1]:
		if up[0] == down[0]:
			print(2)
			print(1, 2)
			print(2, 1)
		else:
			print(0)
	elif up[0] == up[1]:
		if down[0] == up[0]:
			print(1)
			print(n - 1, n)
		else:
			print(1)
			print(n, n - 1)
	elif down[0] == down[1]:
		if down[0] == up[0]:
			print(1)
			print(1, 2)
		else:
			print(1)
			print(2, 1)
	else:
		print(2)
		print(1, 2)
		if up[0] != down[0]:
			print(n - 1, n)
		else:
			print(n, n - 1)


t = int(input())
for q in range(t):
	a = int(input())
	arr = []
	for w in range(a):
		arr.append(list(input()))
	x1 = int(arr[0][1])
	x2 = int(arr[1][0])
	x3 = int(arr[a - 2][a - 1])
	x4 = int(arr[a - 1][a - 2])
	if x1 == x2:
		if x3 == x4:
			if x1 == x3:
				print(2)
				print(1, 2)
				print(2, 1)
			else:
				print(0)
		elif x3 == x1:
			print(1)
			print(a - 1, a)
		else:
			print(1)
			print(a, a - 1)
	elif x1 == x3:
		if x3 == x4:
			print(1)
			print(1, 2)
		else:
			print(2)
			print(2, 1)
			print(a - 1, a)
	elif x3 == x4:
		print(1)
		print(2, 1)
	else:
		print(2)
		print(2, 1)
		print(a, a - 1)


n = int(input())
for j in range(n):
	n = int(input())
	f = []
	for j in range(n):
		l = input()
		if n == 3:
			if j == 0:
				f.append(int(l[1]))
			if j == 1:
				f.append(int(l[0]))
				f.append(int(l[n - 1]))
			if j == n - 1:
				f.append(int(l[n - 2]))
		else:
			if j == 0:
				f.append(int(l[1]))
			if j == 1:
				f.append(int(l[0]))
			if j == n - 1:
				f.append(int(l[n - 2]))
			if j == n - 2:
				f.append(int(l[n - 1]))
	cnt = 0
	cnt1 = 0
	if f[0] == 0:
		cnt += 1
	else:
		cnt1 += 1
	if f[1] == 0:
		cnt += 1
	else:
		cnt1 += 1
	if f[2] == 1:
		cnt += 1
	else:
		cnt1 += 1
	if f[3] == 1:
		cnt += 1
	else:
		cnt1 += 1
	if cnt >= cnt1:
		print(cnt1)
		if f[0] == 1:
			print(1, 2)
		if f[1] == 1:
			print(2, 1)
		if f[2] == 0:
			print(n - 1, n)
		if f[3] == 0:
			print(n, n - 1)
	else:
		print(cnt)
		if f[0] == 0:
			print(1, 2)
		if f[1] == 0:
			print(2, 1)
		if f[2] == 1:
			print(n - 1, n)
		if f[3] == 1:
			print(n, n - 1)


def solve():
	n = int(input())
	mat = []
	for _ in range(n):
		mat.append(input())
	if mat[0][1] != mat[1][0] and mat[n - 2][n - 1] != mat[n - 1][n - 2]:
		print(2)
		if mat[0][1] == '0':
			print(1, 2)
		else:
			print(2, 1)
		if mat[n - 2][n - 1] == '1':
			print(n - 1, n)
		else:
			print(n, n - 1)
	elif mat[0][1] == mat[1][0] and mat[n - 2][n - 1] != mat[n - 1][n - 2]:
		print(1)
		if mat[0][1] == mat[n - 2][n - 1]:
			print(n - 1, n)
		else:
			print(n, n - 1)
	elif mat[n - 2][n - 1] == mat[n - 1][n - 2] and mat[0][1] != mat[1][0]:
		print(1)
		if mat[n - 2][n - 1] == mat[0][1]:
			print(1, 2)
		else:
			print(2, 1)
	elif mat[n - 2][n - 1] == mat[n - 1][n - 2] and mat[0][1] == mat[1][0] and (mat[n - 2][n - 1] == mat[0][1]):
		print(2)
		print(1, 2)
		print(2, 1)
	elif mat[n - 2][n - 1] == mat[n - 1][n - 2] and mat[0][1] == mat[1][0] and (mat[n - 2][n - 1] != mat[0][1]):
		print(0)
	else:
		raise Exception
t = int(input())
for _ in range(t):
	solve()


for x in range(int(input())):
	n = int(input())
	l = []
	for i in range(n):
		s = input()
		l.append(s)
	if l[n - 1][n - 2] != l[n - 2][n - 1]:
		if l[1][0] == l[0][1]:
			print(1)
			if l[n - 1][n - 2] == l[1][0]:
				print(n, n - 1)
			else:
				print(n - 1, n)
		else:
			print(2)
			if l[n - 1][n - 2] != l[1][0]:
				print(n, n - 1)
				print(2, 1)
			else:
				print(n, n - 1)
				print(1, 2)
	elif l[1][0] == l[0][1]:
		if l[n - 1][n - 2] != l[1][0]:
			print(0)
		else:
			print(2)
			print(2, 1)
			print(1, 2)
	elif l[n - 1][n - 2] != l[1][0]:
		print(1)
		print(1, 2)
	else:
		print(1)
		print(2, 1)


import io
import os
import sys
import math
import heapq
input = sys.stdin.readline
mod = 10 ** 9 + 7
t = int(input())
for _ in range(t):
	n = int(input())
	G = []
	for _ in range(n):
		x = input().rstrip()
		x = list(x)
		G.append(x)
	(s1, s2) = (int(G[0][1]), int(G[1][0]))
	(f1, f2) = (int(G[n - 2][n - 1]), int(G[n - 1][n - 2]))
	if s1 + s2 == 2:
		s = f1 + f2
		print(s)
		if f1 == 1:
			print(n - 1, n)
		if f2 == 1:
			print(n, n - 1)
	elif s1 + s2 == 0:
		s = 2 - (f1 + f2)
		print(s)
		if f1 == 0:
			print(n - 1, n)
		if f2 == 0:
			print(n, n - 1)
	elif f1 + f2 > 0:
		s = 2 - (f1 + f2) + 1
		print(s)
		if f1 == 0:
			print(n - 1, n)
		if f2 == 0:
			print(n, n - 1)
		if s1 == 1:
			print(1, 2)
		if s2 == 1:
			print(2, 1)
	else:
		s = 2 - (s1 + s2)
		print(s)
		if s1 == 0:
			print(1, 2)
		if s2 == 0:
			print(2, 1)


import os, sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		n = int(input())
		arr = [list(input().strip()) for _ in range(n)]
		(a, b, c, d) = (int(arr[0][1]), int(arr[1][0]), int(arr[n - 1][n - 2]), int(arr[n - 2][n - 1]))
		ch = int((a != 0) + (b != 0) + (c != 1) + (d != 1))
		ch1 = int((a != 1) + (b != 1) + (c != 0) + (d != 0))
		if ch <= 2:
			print(ch)
			if a:
				print(1, 2)
			if b:
				print(2, 1)
			if not c:
				print(n, n - 1)
			if not d:
				print(n - 1, n)
		else:
			print(ch1)
			if not a:
				print(1, 2)
			if not b:
				print(2, 1)
			if c:
				print(n, n - 1)
			if d:
				print(n - 1, n)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for i in range(t):
	n = int(input())
	a = []
	an = []
	for j in range(n):
		a.append(input().strip())
	(p, q) = (int(a[0][1]), int(a[1][0]))
	(r, s) = (int(a[-1][-2]), int(a[-2][-1]))
	if r == s:
		pt = r ^ 1
		if p != pt:
			an.append((1, 2))
		if q != pt:
			an.append((2, 1))
	elif p == q:
		pt = p ^ 1
		if r != pt:
			an.append((n, n - 1))
		else:
			an.append((n - 1, n))
	else:
		an.append((2, 1))
		pt = p ^ 1
		if r != pt:
			an.append((n, n - 1))
		else:
			an.append((n - 1, n))
	print(len(an))
	for (u, v) in an:
		print(u, v)


from collections import deque as dq
import sys
input = sys.stdin.readline
t = int(input())
while t:
	n = int(input())
	ll = []
	for i in range(n):
		s = input().split()[0]
		ll.append(s)
	a = ll[0][1]
	b = ll[1][0]
	c = ll[n - 1][n - 2]
	d = ll[n - 2][n - 1]
	ans = []
	if a == b and c == d:
		if a == c:
			ans.append((1, 2))
			ans.append((2, 1))
		else:
			lol = 1
	elif a == b and c != d:
		if a == c:
			ans.append((n, n - 1))
		else:
			ans.append((n - 1, n))
	elif a != b and c == d:
		if a == c:
			ans.append((1, 2))
		else:
			ans.append((2, 1))
	else:
		if a == '1':
			ans.append((1, 2))
		else:
			ans.append((2, 1))
		if c == '0':
			ans.append((n, n - 1))
		else:
			ans.append((n - 1, n))
	print(len(ans))
	for i in ans:
		print(*i)
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	l = []
	for i in range(n):
		l.append(input())
	a = int(l[0][1])
	b = int(l[1][0])
	c = int(l[-1][-2])
	d = int(l[-2][-1])
	s1 = a + b
	s2 = c + d
	if {s1, s2} == {0, 2}:
		print(0)
	elif {s1, s2} == {1}:
		print(2)
		print('1 2')
		if a != c:
			print(str(n) + ' ' + str(n - 1))
		else:
			print(str(n - 1) + ' ' + str(n))
	elif {s1, s2} == {2} or {s1, s2} == {0}:
		print(2)
		print(str(n) + ' ' + str(n - 1))
		print(str(n - 1) + ' ' + str(n))
	else:
		print(1)
		if s1 == 1 and s2 == 2:
			if a == 0:
				print('2 1')
			else:
				print('1 2')
		elif s1 == 2 and s2 == 1:
			if c == 0:
				print(str(n - 1) + ' ' + str(n))
			else:
				print(str(n) + ' ' + str(n - 1))
		elif s1 == 0 and s2 == 1:
			if c == 0:
				print(str(n) + ' ' + str(n - 1))
			else:
				print(str(n - 1) + ' ' + str(n))
		elif a == 0:
			print('1 2')
		else:
			print('2 1')


def flip(n):
	if n == '0':
		return '1'
	else:
		return '0'

def hi(a):
	n = len(a)
	c = 0
	f = []
	if a[0][1] == a[1][0] and a[n - 1][n - 2] == a[n - 2][n - 1] and (a[0][1] != a[n - 1][n - 2]):
		return (c, [])
	if a[0][1] == a[1][0]:
		p = a[0][1]
		if a[n - 1][n - 2] == p:
			a[n - 1][n - 2] = flip(p)
			c += 1
			f.append([str(n), str(n - 1)])
		if a[n - 2][n - 1] == p:
			a[n - 2][n - 1] = flip(p)
			c += 1
			f.append([str(n - 1), str(n)])
		return (c, f)
	elif a[n - 1][n - 2] == a[n - 2][n - 1]:
		p = a[n - 1][n - 2]
		if a[0][1] == p:
			a[0][1] = flip(p)
			c += 1
			f.append(['1', '2'])
		else:
			a[1][0] = flip(p)
			c += 1
			f.append(['2', '1'])
		return (c, f)
	else:
		p = a[n - 1][n - 2]
		a[n - 2][n - 1] = p
		c += 1
		f.append([str(n - 1), str(n)])
		if a[0][1] == p:
			c += 1
			a[0][1] = flip(p)
			f.append(['1', '2'])
		else:
			c += 1
			a[1][0] = flip(p)
			f.append(['2', '1'])
		return (c, f)
t = int(input())
b = [[] for i in range(2 * t)]
for i in range(t):
	p = int(input())
	a = []
	for j in range(p):
		a.append(list(input()))
	(b[2 * i], b[2 * i + 1]) = hi(a)
for i in range(len(b)):
	if i % 2 == 0:
		print(b[i])
	elif len(b) == 0:
		pass
	else:
		for j in range(len(b[i])):
			p = ' '.join(b[i][j])
			print(p)


t = int(input())
i = 1
while i <= t:
	n = int(input())
	mat = []
	for j in range(n):
		mat.append(list(input()))
	x1 = int(mat[0][1])
	x2 = int(mat[1][0])
	x3 = int(mat[n - 1][n - 2])
	x4 = int(mat[n - 2][n - 1])
	s1 = x1 + x2
	s2 = x3 + x4
	if s1 == 0 and s2 == 1:
		print(1)
		if x3 == 0:
			print(n, n - 1)
		if x4 == 0:
			print(n - 1, n)
	elif s1 == 1 and s2 == 1:
		print(2)
		if x1 == 1:
			print(1, 2)
		if x2 == 1:
			print(2, 1)
		if x3 == 0:
			print(n, n - 1)
		if x4 == 0:
			print(n - 1, n)
	elif s1 == 2 and s2 == 1:
		print(1)
		if x3 == 1:
			print(n, n - 1)
		if x4 == 1:
			print(n - 1, n)
	elif s1 == 1 and s2 == 0:
		print(1)
		if x1 == 0:
			print(1, 2)
		if x2 == 0:
			print(2, 1)
	elif s1 == 0 and s2 == 0:
		print(2)
		print(1, 2)
		print(2, 1)
	elif s1 == 2 and s2 == 2:
		print(2)
		print(1, 2)
		print(2, 1)
	elif s1 == 1 and s2 == 2:
		print(1)
		if x1 == 1:
			print(1, 2)
		if x2 == 1:
			print(2, 1)
	else:
		print(0)
	i += 1


import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
from bisect import *
from math import sqrt, pi, ceil
import math
from itertools import permutations
from copy import deepcopy
for t in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		a.append(list(input().rstrip()))
	f = [a[n - 1][-2], a[n - 2][-1]]
	s = [a[0][1], a[1][0]]
	if f[0] == '0' and f[1] == '0':
		if s[0] == '1' and s[1] == '1':
			print(0)
		elif s[0] == '1' and s[1] == '0':
			print(1)
			print(2, 1)
		elif s[0] == '0' and s[1] == '0':
			print(2)
			print(1, 2)
			print(2, 1)
		else:
			print(1)
			print(1, 2)
	elif f[0] == '1' and f[1] == '1':
		if s[0] == '1' and s[1] == '1':
			print(2)
			print(1, 2)
			print(2, 1)
		elif s[0] == '1' and s[1] == '0':
			print(1)
			print(1, 2)
		elif s[0] == '0' and s[1] == '1':
			print(1)
			print(2, 1)
		else:
			print(0)
	elif f[0] == '1' and f[1] == '0':
		if s[0] == '1' and s[1] == '1':
			print(1)
			print(n, n - 1)
		elif s[0] == '1' and s[1] == '0':
			print(2)
			print(2, 1)
			print(n, n - 1)
		elif s[0] == '0' and s[1] == '1':
			print(2)
			print(2, 1)
			print(n - 1, n)
		else:
			print(1)
			print(n - 1, n)
	elif s[0] == '1' and s[1] == '1':
		print(1)
		print(n - 1, n)
	elif s[0] == '1' and s[1] == '0':
		print(2)
		print(2, 1)
		print(n - 1, n)
	elif s[0] == '0' and s[1] == '1':
		print(2)
		print(2, 1)
		print(n, n - 1)
	else:
		print(1)
		print(n, n - 1)


for _ in range(int(input())):
	n = int(input())
	l = []
	for i in range(n):
		s = input()
		k = list(s)
		l.append(k)
	c = 0
	v1 = l[0][1]
	v2 = l[1][0]
	v3 = l[n - 1][n - 2]
	v4 = l[n - 2][n - 1]
	ans = []
	if v1 == v2:
		if v1 == '1':
			if v3 == '1':
				c += 1
				ans.append(n - 1)
				ans.append(n - 2)
			if v4 == '1':
				c += 1
				ans.append(n - 2)
				ans.append(n - 1)
		else:
			if v3 == '0':
				c += 1
				ans.append(n - 1)
				ans.append(n - 2)
			if v4 == '0':
				c += 1
				ans.append(n - 2)
				ans.append(n - 1)
	elif v3 == v4:
		if v3 == '1':
			if v1 == '1':
				c += 1
				ans.append(0)
				ans.append(1)
			if v2 == '1':
				c += 1
				ans.append(1)
				ans.append(0)
		else:
			if v1 == '0':
				c += 1
				ans.append(0)
				ans.append(1)
			if v2 == '0':
				c += 1
				ans.append(1)
				ans.append(0)
	else:
		if v1 == '0':
			c += 1
			ans.append(0)
			ans.append(1)
		elif v2 == '0':
			c += 1
			ans.append(1)
			ans.append(0)
		if v3 == '1':
			c += 1
			ans.append(n - 1)
			ans.append(n - 2)
		elif v4 == '1':
			c += 1
			ans.append(n - 2)
			ans.append(n - 1)
	print(c)
	if c > 0:
		print(ans[0] + 1, ans[1] + 1)
	if c > 1:
		print(ans[2] + 1, ans[3] + 1)


def f(c, ans):
	if c != 0:
		print(c)
		for i in range(c):
			print(ans[i][0], ans[i][1])
	else:
		print(c)

def main():
	t = int(input())
	for i in range(t):
		x = int(input())
		a = [input() for i in range(x)]
		a1 = a[0][1]
		a2 = a[1][0]
		a3 = a[x - 2][x - 1]
		a4 = a[x - 1][x - 2]
		c = 0
		ans = []
		if a1 == a2:
			v = str(a1)
			if a3 == v:
				c += 1
				ans.append((x - 1, x))
			if a4 == v:
				c += 1
				ans.append((x, x - 1))
			f(c, ans)
		elif a3 == a4:
			v = str(a3)
			if a1 == v:
				c += 1
				ans.append((1, 2))
			if a2 == v:
				c += 1
				ans.append((2, 1))
			f(c, ans)
		else:
			if a1 != '0':
				c += 1
				ans.append((1, 2))
			if a2 != '0':
				c += 1
				ans.append((2, 1))
			if a3 != '1':
				c += 1
				ans.append((x - 1, x))
			if a4 != '1':
				c += 1
				ans.append((x, x - 1))
			f(c, ans)
main()


import sys
import collections
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		N = int(input())
		S = [input() for _ in range(N)]
		if S[0][1] == '0' and S[1][0] == '0' and (S[N - 1][N - 2] == '0') and (S[N - 2][N - 1] == '0'):
			print(2)
			print(1, 2)
			print(2, 1)
		if S[0][1] == '0' and S[1][0] == '0' and (S[N - 1][N - 2] == '0') and (S[N - 2][N - 1] == '1'):
			print(1)
			print(N, N - 1)
		if S[0][1] == '0' and S[1][0] == '0' and (S[N - 1][N - 2] == '1') and (S[N - 2][N - 1] == '0'):
			print(1)
			print(N - 1, N)
		if S[0][1] == '0' and S[1][0] == '0' and (S[N - 1][N - 2] == '1') and (S[N - 2][N - 1] == '1'):
			print(0)
		if S[0][1] == '0' and S[1][0] == '1' and (S[N - 1][N - 2] == '0') and (S[N - 2][N - 1] == '0'):
			print(1)
			print(1, 2)
		if S[0][1] == '0' and S[1][0] == '1' and (S[N - 1][N - 2] == '0') and (S[N - 2][N - 1] == '1'):
			print(2)
			print(1, 2)
			print(N - 1, N)
		if S[0][1] == '0' and S[1][0] == '1' and (S[N - 1][N - 2] == '1') and (S[N - 2][N - 1] == '0'):
			print(2)
			print(1, 2)
			print(N, N - 1)
		if S[0][1] == '0' and S[1][0] == '1' and (S[N - 1][N - 2] == '1') and (S[N - 2][N - 1] == '1'):
			print(1)
			print(2, 1)
		if S[0][1] == '1' and S[1][0] == '0' and (S[N - 1][N - 2] == '0') and (S[N - 2][N - 1] == '0'):
			print(1)
			print(2, 1)
		if S[0][1] == '1' and S[1][0] == '0' and (S[N - 1][N - 2] == '0') and (S[N - 2][N - 1] == '1'):
			print(2)
			print(2, 1)
			print(N - 1, N)
		if S[0][1] == '1' and S[1][0] == '0' and (S[N - 1][N - 2] == '1') and (S[N - 2][N - 1] == '0'):
			print(2)
			print(2, 1)
			print(N, N - 1)
		if S[0][1] == '1' and S[1][0] == '0' and (S[N - 1][N - 2] == '1') and (S[N - 2][N - 1] == '1'):
			print(1)
			print(1, 2)
		if S[0][1] == '1' and S[1][0] == '1' and (S[N - 1][N - 2] == '0') and (S[N - 2][N - 1] == '0'):
			print(0)
		if S[0][1] == '1' and S[1][0] == '1' and (S[N - 1][N - 2] == '0') and (S[N - 2][N - 1] == '1'):
			print(1)
			print(N - 1, N)
		if S[0][1] == '1' and S[1][0] == '1' and (S[N - 1][N - 2] == '1') and (S[N - 2][N - 1] == '0'):
			print(1)
			print(N, N - 1)
		if S[0][1] == '1' and S[1][0] == '1' and (S[N - 1][N - 2] == '1') and (S[N - 2][N - 1] == '1'):
			print(2)
			print(1, 2)
			print(2, 1)
main()


import sys
import math
from collections import defaultdict, Counter
input = sys.stdin.readline
t = int(input())
for i in range(t):
	n = int(input())
	for j in range(n):
		s = input().strip()
		if j == 0:
			flag = int(s[1])
		elif j == n - 1:
			flag3 = int(s[-2])
		else:
			if j == 1:
				flag1 = int(s[0])
			if j == n - 2:
				flag2 = int(s[-1])
	l = []
	if flag == flag1:
		if flag == 0:
			if flag2 == 0:
				l.append([n - 1, n])
			if flag3 == 0:
				l.append([n, n - 1])
		else:
			if flag2 == 1:
				l.append([n - 1, n])
			if flag3 == 1:
				l.append([n, n - 1])
	elif flag2 == flag3:
		if flag2 == 0:
			if flag == 0:
				l.append([1, 2])
			if flag1 == 0:
				l.append([2, 1])
		else:
			if flag == 1:
				l.append([1, 2])
			if flag1 == 1:
				l.append([2, 1])
	else:
		if flag == 0:
			l.append([2, 1])
		else:
			l.append([1, 2])
		if flag2 == 0:
			l.append([n - 1, n])
		else:
			l.append([n, n - 1])
	print(len(l))
	for j in l:
		print(*j)


from sys import stdin
input = stdin.readline
q = int(input())
for _ in range(q):
	n = int(input())
	mat = [list(input()) for i in range(n)]
	for i in range(n):
		mat[i] = mat[i][:n]
	l = [mat[0][1], mat[1][0]]
	r = [mat[-1][-2], mat[-2][-1]]
	if l[0] == l[1] and l[0] == '0':
		r[0] = '1'
		r[1] = '1'
	elif l[0] == l[1] and l[0] == '1':
		r[0] = '0'
		r[1] = '0'
	elif r[0] == r[1] and r[0] == '1':
		l[0] = '0'
		l[1] = '0'
	elif r[0] == r[1] and r[0] == '0':
		l[0] = '1'
		l[1] = '1'
	else:
		r[0] = '1'
		r[1] = '1'
		l[0] = '0'
		l[1] = '0'
	cnt = 0
	zj = mat[0][1]
	jz = mat[1][0]
	bw = mat[-1][-2]
	wb = mat[-2][-1]
	zmien = []
	if zj != l[0]:
		cnt += 1
		zmien.append([1, 2])
	if jz != l[1]:
		cnt += 1
		zmien.append([2, 1])
	if bw != r[0]:
		cnt += 1
		zmien.append([n, n - 1])
	if wb != r[1]:
		cnt += 1
		zmien.append([n - 1, n])
	print(cnt)
	for i in zmien:
		print(*i)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	grid = []
	for i in range(n):
		grid.append(list(input())[:-1])
	cnt = 0
	ans = []
	if grid[0][1] == grid[1][0] == '0':
		if grid[n - 2][n - 1] == '0':
			ans.append((n - 1, n))
			cnt += 1
		if grid[n - 1][n - 2] == '0':
			ans.append((n, n - 1))
			cnt += 1
	elif grid[0][1] == grid[1][0] == '1':
		if grid[n - 2][n - 1] == '1':
			ans.append((n - 1, n))
			cnt += 1
		if grid[n - 1][n - 2] == '1':
			ans.append((n, n - 1))
			cnt += 1
	elif grid[n - 2][n - 1] == grid[n - 1][n - 2] == '0':
		if grid[0][1] == '0':
			ans.append((1, 2))
			cnt += 1
		if grid[1][0] == '0':
			ans.append((2, 1))
			cnt += 1
	elif grid[n - 2][n - 1] == grid[n - 1][n - 2] == '1':
		if grid[0][1] == '1':
			ans.append((1, 2))
			cnt += 1
		if grid[1][0] == '1':
			ans.append((2, 1))
			cnt += 1
	else:
		if grid[0][1] == '1':
			ans.append((1, 2))
			cnt += 1
		if grid[1][0] == '1':
			ans.append((2, 1))
			cnt += 1
		if grid[n - 2][n - 1] == '0':
			ans.append((n - 1, n))
			cnt += 1
		if grid[n - 1][n - 2] == '0':
			ans.append((n, n - 1))
			cnt += 1
	print(cnt)
	for i in range(cnt):
		print(ans[i][0], ans[i][1])


for _ in ' ' * int(input()):
	a = int(input())
	z = [[0] * (a + 1)]
	for i in range(a):
		f = [0] + list(map(str, input().replace('', ' ').split()))
		z.append(f)
	k = z[1][2]
	k1 = z[2][1]
	k2 = z[a - 1][a]
	k3 = z[a][a - 1]
	o = [k, k1, k2, k3]
	(z, z1) = (0, 0)
	for i in o:
		if i == '0':
			z += 1
		else:
			z1 += 1
	if z == z1:
		if k == k1:
			print(0)
		else:
			print(2)
			if k == '0':
				print(1, 2)
			else:
				print(2, 1)
			if k2 == '1':
				print(a - 1, a)
			else:
				print(a, a - 1)
	elif z == 3 or z1 == 3:
		print(1)
		if k == k1:
			if k2 == k:
				print(a - 1, a)
			else:
				print(a, a - 1)
		elif k2 == k:
			print(1, 2)
		else:
			print(2, 1)
	else:
		print(2)
		print(1, 2)
		print(2, 1)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return list(map(int, input().split()))

def main():
	t = inp()
	for _ in range(0, t):
		line = inp()
		matrix = []
		for _ in range(0, line):
			matrix.append(insr())
		a = helper(matrix, '1', '0')
		if a == None:
			a = helper(matrix, '0', '1')
		if a != None:
			print(len(a))
			for c in a:
				print('{} {}'.format(c[0], c[1]))

def helper(matrix, top, bottom):
	ans = []
	if matrix[0][1] != top:
		ans.append((1, 2))
	if matrix[1][0] != top:
		ans.append((2, 1))
	if matrix[len(matrix) - 1][len(matrix[0]) - 2] != bottom:
		ans.append((len(matrix), len(matrix[0]) - 1))
	if matrix[len(matrix) - 2][len(matrix[0]) - 1] != bottom:
		ans.append((len(matrix) - 1, len(matrix[0])))
	if len(ans) <= 2:
		return ans
	return None
main()


def st(a, b):
	return str(a + 1) + ' ' + str(b + 1)
ans = []
for _ in range(int(input())):
	n = int(input())
	u = []
	for i in range(n):
		u.append(list(input()))
	a = [u[0][1], u[1][0], u[n - 1][n - 2], u[n - 2][n - 1]]
	if a[0] == a[1] and a[2] == a[3]:
		if a[1] != a[2]:
			ans.append(0)
		else:
			ans.append(2)
			ans.append(st(0, 1))
			ans.append(st(1, 0))
	elif a[0] == a[1]:
		ans.append(1)
		if a[2] == a[1]:
			ans.append(st(n - 1, n - 2))
		else:
			ans.append(st(n - 2, n - 1))
	elif a[2] == a[3]:
		ans.append(1)
		if a[0] == a[2]:
			ans.append(st(0, 1))
		else:
			ans.append(st(1, 0))
	else:
		ans.append(2)
		if a[0] == a[2]:
			ans.append(st(0, 1))
			ans.append(st(n - 2, n - 1))
		else:
			ans.append(st(0, 1))
			ans.append(st(n - 1, n - 2))
print('\n'.join(map(str, ans)))


for j in range(int(input())):
	n = int(input())
	a = [list(input()) for i in range(n)]
	t = a[0][1]
	r = a[1][0]
	w = a[-1][-2]
	y = a[-2][-1]
	d = []
	if t == r == '1':
		if w == '1':
			d.append([n, n - 1])
		if y == '1':
			d.append([n - 1, n])
	elif t == r == '0':
		if w == '0':
			d.append([n, n - 1])
		if y == '0':
			d.append([n - 1, n])
	elif w == y == '1':
		if t == '1':
			d.append([1, 2])
		if r == '1':
			d.append([2, 1])
	elif w == y == '0':
		if t == '0':
			d.append([1, 2])
		if r == '0':
			d.append([2, 1])
	else:
		if w == '1':
			d.append([n, n - 1])
		if y == '1':
			d.append([n - 1, n])
		if r == '0':
			d.append([2, 1])
		if t == '0':
			d.append([1, 2])
	print(len(d))
	for x in d:
		print(*x)


t = int(input())
for i in range(t):
	grid = []
	n = int(input())
	for j in range(n):
		grid.append(input())
	a = grid[0][1]
	b = grid[1][0]
	c = grid[n - 2][n - 1]
	d = grid[n - 1][n - 2]
	if a == b and c == d and (b == c):
		print(2)
		print('1 2')
		print('2 1')
	elif a == b and c == d:
		print(0)
	elif a == b and c != d:
		print(1)
		if a == c:
			print(str(n - 1) + ' ' + str(n))
		else:
			print(str(n) + ' ' + str(n - 1))
	elif c == d:
		print(1)
		if a == c:
			print('1 2')
		else:
			print('2 1')
	else:
		print(2)
		if a == '0':
			print('2 1')
		else:
			print('1 2')
		if c == '0':
			print(str(n - 1) + ' ' + str(n))
		else:
			print(str(n) + ' ' + str(n - 1))


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import time
start_time = time.time()
import collections as col
import math, string
from functools import reduce

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7

def solve():
	N = getInt()
	S = []
	for n in range(N):
		S.append(getStr())
	ans = 0
	inv = []
	(S1, S2) = (int(S[0][1]), int(S[1][0]))
	(E1, E2) = (int(S[N - 1][N - 2]), int(S[N - 2][N - 1]))
	if S1 == S2:
		targ = 1 - S1
		if E1 != targ:
			ans += 1
			inv.append((N, N - 1))
		if E2 != targ:
			ans += 1
			inv.append((N - 1, N))
	elif E1 == E2:
		targ = 1 - E1
		if S1 != targ:
			ans += 1
			inv.append((1, 2))
		if S2 != targ:
			ans += 1
			inv.append((2, 1))
	else:
		ans = 2
		targ = 1 - S1
		inv.append((2, 1))
		if E1 != targ:
			inv.append((N, N - 1))
		else:
			inv.append((N - 1, N))
	print(ans)
	for op in inv:
		print(*op)
	return
for _ in range(getInt()):
	solve()


import math
for _ in range(int(input())):
	n = int(input())
	s = []
	for i in range(n):
		l = input()
		s.append(l)
	if s[0][1] == '1' and s[1][0] == '1' and (s[n - 1][n - 2] == '0') and (s[n - 2][n - 1] == '0') or (s[0][1] == '0' and s[1][0] == '0' and (s[n - 1][n - 2] == '1') and (s[n - 2][n - 1] == '1')):
		print(0)
	elif s[0][1] == '1' and s[1][0] == '1':
		if s[n - 1][n - 2] == '1' and s[n - 2][n - 1] == '1':
			print(2)
			print(n, n - 1)
			print(n - 1, n)
		elif s[n - 1][n - 2] == '1' and s[n - 2][n - 1] == '0':
			print(1)
			print(n, n - 1)
		elif s[n - 1][n - 2] == '0' and s[n - 2][n - 1] == '1':
			print(1)
			print(n - 1, n)
		else:
			print(0)
	elif s[0][1] == '0' and s[1][0] == '0':
		if s[n - 1][n - 2] == '0' and s[n - 2][n - 1] == '0':
			print(2)
			print(n, n - 1)
			print(n - 1, n)
		elif s[n - 1][n - 2] == '0' and s[n - 2][n - 1] == '1':
			print(1)
			print(n, n - 1)
		elif s[n - 1][n - 2] == '1' and s[n - 2][n - 1] == '0':
			print(1)
			print(n - 1, n)
		else:
			print(0)
	elif s[0][1] == '1' and s[1][0] == '0' and (s[n - 1][n - 2] == '1') and (s[n - 2][n - 1] == '0') or (s[0][1] == '0' and s[1][0] == '1' and (s[n - 1][n - 2] == '0') and (s[n - 2][n - 1] == '1')):
		print(2)
		print(2, 1)
		print(n, n - 1)
	elif s[0][1] == '1' and s[1][0] == '0' and (s[n - 1][n - 2] == '0') and (s[n - 2][n - 1] == '1') or (s[0][1] == '0' and s[1][0] == '1' and (s[n - 1][n - 2] == '1') and (s[n - 2][n - 1] == '0')):
		print(2)
		print(1, 2)
		print(n, n - 1)
	elif s[0][1] == '1' and s[1][0] == '0' and (s[n - 1][n - 2] == '0') and (s[n - 2][n - 1] == '0') or (s[0][1] == '0' and s[1][0] == '1' and (s[n - 1][n - 2] == '1') and (s[n - 2][n - 1] == '1')):
		print(1)
		print(2, 1)
	elif s[0][1] == '1' and s[1][0] == '0' and (s[n - 1][n - 2] == '1') and (s[n - 2][n - 1] == '1') or (s[0][1] == '0' and s[1][0] == '1' and (s[n - 1][n - 2] == '0') and (s[n - 2][n - 1] == '0')):
		print(1)
		print(1, 2)


import os
import sys
from io import BytesIO, IOBase
_str = str
BUFSIZE = 8192

def str(x=b''):
	return x if type(x) is bytes else _str(x).encode()

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def inp():
	return sys.stdin.readline().rstrip()

def mpint():
	return map(int, inp().split(' '))

def itg():
	return int(inp())

def to_list(binary_num, size=None):
	if size is None:
		size = binary_num.bit_length()
	result = [0] * size
	index = size - 1
	while binary_num:
		if binary_num & 1:
			result[index] = 1
		index -= 1
		binary_num >>= 1
	return result

def invert(x):
	return '0' if x == '1' else '1'

def solve():
	n = itg()
	g = [inp() for _ in range(n)]
	arr = (g[0][1], g[1][0], g[n - 2][-1], g[-1][n - 2])
	pos = [(1, 2), (2, 1), (n - 1, n), (n, n - 1)]
	for bit in range(2 ** 4):
		bit = to_list(bit, 4)
		if sum(bit) > 2:
			continue
		tmp = list(arr)
		for (i, b) in enumerate(bit):
			if b:
				tmp[i] = invert(tmp[i])
		(a, b, c, d) = tmp
		if a == b and c == d and (a != c):
			print(sum(bit))
			for (i, b) in enumerate(bit):
				if b:
					print(*pos[i])
			return
	while True:
		pass

def main():
	for _ in range(itg()):
		solve()
DEBUG = 0
URL = 'https://codeforces.com/contest/1421/problem/0'
if DEBUG == 1:
	import requests
	from ACgenerator.Y_Test_Case_Runner import TestCaseRunner
	runner = TestCaseRunner(main, URL)
	inp = runner.input_stream
	print = runner.output_stream
	runner.checking()
elif DEBUG == 2:
	main()
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	main()


t = int(input())
for _ in range(t):
	n = int(input())
	B = [input() for _ in range(n)]
	(a, b) = map(int, (B[0][1], B[1][0]))
	(c, d) = map(int, (B[-1][-2], B[-2][-1]))
	ans = []
	if abs(a - 1) + abs(b - 1) + abs(c - 0) + abs(d - 0) <= 2:
		if a == 0:
			ans.append((1, 2))
		if b == 0:
			ans.append((2, 1))
		if c == 1:
			ans.append((n, n - 1))
		if d == 1:
			ans.append((n - 1, n))
	else:
		if a == 1:
			ans.append((1, 2))
		if b == 1:
			ans.append((2, 1))
		if c == 0:
			ans.append((n, n - 1))
		if d == 0:
			ans.append((n - 1, n))
	print(len(ans))
	for p in ans:
		print(*p)


for nt in range(int(input())):
	n = int(input())
	grid = []
	for i in range(n):
		grid.append(list(input()))
	if grid[n - 1][n - 2] == grid[n - 2][n - 1]:
		(count, ans) = (0, [])
		if grid[n - 1][n - 2] == '1':
			if grid[0][1] == '1':
				count += 1
				ans.append([1, 2])
			if grid[1][0] == '1':
				count += 1
				ans.append([2, 1])
		else:
			if grid[0][1] == '0':
				count += 1
				ans.append([1, 2])
			if grid[1][0] == '0':
				count += 1
				ans.append([2, 1])
		print(count)
		for i in ans:
			print(*i)
	elif grid[n - 1][n - 2] == '1':
		if grid[0][1] == grid[1][0]:
			if grid[0][1] == '1':
				print(1)
				print(n, n - 1)
			else:
				print(1)
				print(n - 1, n)
		elif grid[0][1] == '1':
			print(2)
			print(1, 2)
			print(n - 1, n)
		else:
			print(2)
			print(1, 2)
			print(n, n - 1)
	elif grid[0][1] == grid[1][0]:
		if grid[0][1] == '1':
			print(1)
			print(n - 1, n)
		else:
			print(1)
			print(n, n - 1)
	elif grid[0][1] == '1':
		print(2)
		print(1, 2)
		print(n, n - 1)
	else:
		print(2)
		print(1, 2)
		print(n - 1, n)


t = int(input())
for i in range(0, t):
	m = int(input())
	l = []
	for j in range(0, m):
		str1 = input()
		x = len(str1)
		l.append(str1)
	a = l[0][1]
	b = l[1][0]
	c = l[-2][-1]
	d = l[-1][-2]
	a = int(a)
	b = int(b)
	c = int(c)
	d = int(d)
	if a == 0 and b == 0 and (c == 0) and (d == 0):
		print(2)
		print(1, 2)
		print(2, 1)
	elif a == 0 and b == 0 and (c == 0) and (d == 1):
		print(1)
		print(m - 1, x)
	elif a == 0 and b == 0 and (c == 1) and (d == 0):
		print(1)
		print(m, x - 1)
	elif a == 0 and b == 0 and (c == 1) and (d == 1):
		print(0)
	elif a == 0 and b == 1 and (c == 0) and (d == 0):
		print(1)
		print(1, 2)
	elif a == 0 and b == 1 and (c == 0) and (d == 1):
		print(2)
		print(1, 2)
		print(m, x - 1)
	elif a == 0 and b == 1 and (c == 1) and (d == 0):
		print(2)
		print(2, 1)
		print(m, x - 1)
	elif a == 0 and b == 1 and (c == 1) and (d == 1):
		print(1)
		print(2, 1)
	elif a == 1 and b == 0 and (c == 0) and (d == 0):
		print(1)
		print(2, 1)
	elif a == 1 and b == 0 and (c == 0) and (d == 1):
		print(2)
		print(1, 2)
		print(m - 1, x)
	elif a == 1 and b == 0 and (c == 1) and (d == 0):
		print(2)
		print(2, 1)
		print(m - 1, x)
	elif a == 1 and b == 0 and (c == 1) and (d == 1):
		print(1)
		print(1, 2)
	elif a == 1 and b == 1 and (c == 0) and (d == 0):
		print(0)
	elif a == 1 and b == 1 and (c == 0) and (d == 1):
		print(1)
		print(m, x - 1)
	elif a == 1 and b == 1 and (c == 1) and (d == 0):
		print(1)
		print(m - 1, x)
	elif a == 1 and b == 1 and (c == 1) and (d == 1):
		print(2)
		print(1, 2)
		print(2, 1)


t = int(input())
for _ in range(t):
	n = int(input())
	s = list()
	for _ in range(n):
		a = input()
		s.append(a)
	u = int(s[n - 2][n - 1])
	d = int(s[1][0])
	l = int(s[n - 1][n - 2])
	r = int(s[0][1])
	c = 0
	k = list()
	if r + d == 0:
		if u == 0:
			c += 1
			k.append(n - 1)
			k.append(n)
		if l == 0:
			c += 1
			k.append(n)
			k.append(n - 1)
	elif r + d == 2:
		if u == 1:
			c += 1
			k.append(n - 1)
			k.append(n)
		if l == 1:
			c += 1
			k.append(n)
			k.append(n - 1)
	elif l + u == 2:
		if r == 1:
			c += 1
			k.append(1)
			k.append(2)
		if d == 1:
			c += 1
			k.append(2)
			k.append(1)
	elif l + u == 0:
		if r == 0:
			c += 1
			k.append(1)
			k.append(2)
		if d == 0:
			c += 1
			k.append(2)
			k.append(1)
	else:
		if r == 0:
			c += 1
			k.append(1)
			k.append(2)
		if d == 0:
			c += 1
			k.append(2)
			k.append(1)
		if u == 1:
			c += 1
			k.append(n - 1)
			k.append(n)
		if l == 1:
			c += 1
			k.append(n)
			k.append(n - 1)
	print(c)
	if len(k) != 0:
		for i in range(0, len(k), 2):
			print(k[i], k[i + 1])


for tt in range(int(input())):
	n = int(input())
	mat = []
	for i in range(n):
		mat.append(list(input()))
	c = 0
	ans = []
	if mat[0][1] == '1' and mat[1][0] == '1':
		if mat[n - 2][n - 1] == '1':
			c += 1
			ans.append((n - 1, n))
		if mat[n - 1][n - 2] == '1':
			c += 1
			ans.append((n, n - 1))
	elif mat[0][1] == '0' and mat[1][0] == '0':
		if mat[n - 2][n - 1] == '0':
			c += 1
			ans.append((n - 1, n))
		if mat[n - 1][n - 2] == '0':
			c += 1
			ans.append((n, n - 1))
	elif mat[0][1] == '0' and mat[1][0] == '1':
		if mat[n - 2][n - 1] == '0' and mat[n - 1][n - 2] == '1':
			c = 2
			ans.append((1, 2))
			ans.append((n, n - 1))
		elif mat[n - 2][n - 1] == '1' and mat[n - 1][n - 2] == '0':
			c = 2
			ans.append((2, 1))
			ans.append((n, n - 1))
		elif mat[n - 2][n - 1] == '1' and mat[n - 1][n - 2] == '1':
			c = 1
			ans.append((2, 1))
		elif mat[n - 2][n - 1] == '0' and mat[n - 1][n - 2] == '0':
			c = 1
			ans.append((1, 2))
	elif mat[0][1] == '1' and mat[1][0] == '0':
		if mat[n - 2][n - 1] == '0' and mat[n - 1][n - 2] == '1':
			c = 2
			ans.append((2, 1))
			ans.append((n, n - 1))
		elif mat[n - 2][n - 1] == '1' and mat[n - 1][n - 2] == '0':
			c = 2
			ans.append((1, 2))
			ans.append((n, n - 1))
		elif mat[n - 2][n - 1] == '1' and mat[n - 1][n - 2] == '1':
			c = 1
			ans.append((1, 2))
		elif mat[n - 2][n - 1] == '0' and mat[n - 1][n - 2] == '0':
			c = 1
			ans.append((2, 1))
	print(c)
	for i in ans:
		print(*i)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = []
	for i in range(n):
		b = input()
		a.append(b)
	c = int(a[0][1])
	d = int(a[1][0])
	e = int(a[-1][-2])
	f = int(a[-2][-1])
	if c == d and e == f and (c != e):
		print(0)
	elif c == d and e == f and (c == e):
		print(2)
		print(1, 2)
		print(2, 1)
	elif c != d and e != f:
		print(2)
		if c == 0:
			print(1, 2)
		if d == 0:
			print(2, 1)
		if e == 1:
			print(n, n - 1)
		if f == 1:
			print(n - 1, n)
	elif c == d:
		print(1)
		if c == e:
			print(n, n - 1)
		else:
			print(n - 1, n)
	elif e == f:
		print(1)
		if c == e:
			print(1, 2)
		else:
			print(2, 1)


t = int(input())
while t > 0:
	n = int(input())
	l = [[] for x in range(n)]
	for x in range(0, n):
		a = list(input())
		l[x].extend(a)
	l1 = list(l)
	v1 = l[0][1]
	v2 = l[1][0]
	w1 = l[n - 1][n - 2]
	w2 = l[n - 2][n - 1]
	ans = 0
	a = []
	if (v1 == '0' and v2 == '0') and (w1 == '1' and w2 == '1'):
		ans = 0
	elif (v1 == '1' and v2 == '1') and (w1 == '0' and w2 == '0'):
		ans = 0
	elif v1 == '1' and v2 == '1':
		if w1 != '0':
			ans += 1
			a.append((n, n - 1))
		if w2 != '0':
			ans += 1
			a.append((n - 1, n))
	elif v1 == '0' and v2 == '0':
		if w1 != '1':
			ans += 1
			a.append((n, n - 1))
		if w2 != '1':
			ans += 1
			a.append((n - 1, n))
	elif w1 == '1' and w2 == '1':
		if v1 != '0':
			ans += 1
			a.append((1, 2))
		if v2 != '0':
			ans += 1
			a.append((2, 1))
	elif w1 == '0' and w2 == '0':
		if v1 != '1':
			ans += 1
			a.append((1, 2))
		if v2 != '1':
			ans += 1
			a.append((2, 1))
	else:
		if v1 == '1':
			ans += 1
			a.append((1, 2))
		else:
			ans += 1
			a.append((2, 1))
		if w1 == '0':
			ans += 1
			a.append((n, n - 1))
		else:
			ans += 1
			a.append((n - 1, n))
	print(ans)
	for x in a:
		print(x[0], x[1])
	t -= 1


t = int(input())
for i in range(t):
	size = int(input())
	lines = []
	for j in range(size):
		lines.append(input())
	(d0, d1, f0, f1) = (0, 0, 0, 0)
	if lines[0][1] == '1':
		d1 += 1
	if lines[1][0] == '1':
		d1 += 1
	if lines[-1][-2] == '1':
		f1 += 1
	if lines[-2][-1] == '1':
		f1 += 1
	rep = []
	if d1 in [0, 2] and f1 in [0, 2]:
		if d1 != f1:
			print(0)
		else:
			print(2)
	elif d1 == 1 and f1 == 1:
		print(2)
	else:
		print(1)
	if d1 == 0:
		if lines[-1][-2] == '0':
			print(size, size - 1)
		if lines[-2][-1] == '0':
			print(size - 1, size)
	elif d1 == 1:
		if f1 == 0:
			if lines[0][1] == '0':
				print(1, 2)
			if lines[1][0] == '0':
				print(2, 1)
		if f1 == 1:
			if lines[0][1] == '0':
				print(1, 2)
			if lines[1][0] == '0':
				print(2, 1)
			if lines[-1][-2] == '1':
				print(size, size - 1)
			if lines[-2][-1] == '1':
				print(size - 1, size)
		if f1 == 2:
			if lines[0][1] == '1':
				print(1, 2)
			if lines[1][0] == '1':
				print(2, 1)
	else:
		if lines[-1][-2] == '1':
			print(size, size - 1)
		if lines[-2][-1] == '1':
			print(size - 1, size)


import math
from decimal import *
import random
for _ in range(int(input())):
	n = int(input())
	grid = []
	for i in range(n):
		grid.append(list(input()))
	if grid[0][1] == '0' and grid[1][0] == '0':
		no = 0
		ans = []
		if grid[n - 1][n - 2] == '0':
			no += 1
			ans.append([str(n), str(n - 1)])
		if grid[n - 2][n - 1] == '0':
			no += 1
			ans.append([str(n - 1), str(n)])
		print(no)
		for i in range(no):
			print(' '.join(ans[i]))
	elif grid[0][1] == '1' and grid[1][0] == '1':
		no = 0
		ans = []
		if grid[n - 1][n - 2] == '1':
			no += 1
			ans.append([str(n), str(n - 1)])
		if grid[n - 2][n - 1] == '1':
			no += 1
			ans.append([str(n - 1), str(n)])
		print(no)
		for i in range(no):
			print(' '.join(ans[i]))
	elif grid[n - 2][n - 1] == '0' and grid[n - 1][n - 2] == '0':
		no = 0
		ans = []
		if grid[0][1] == '0':
			no += 1
			ans.append([str(1), str(2)])
		if grid[1][0] == '0':
			no += 1
			ans.append([str(2), str(1)])
		print(no)
		for i in range(no):
			print(' '.join(ans[i]))
	elif grid[n - 2][n - 1] == '1' and grid[n - 1][n - 2] == '1':
		no = 0
		ans = []
		if grid[0][1] == '1':
			no += 1
			ans.append([str(1), str(2)])
		if grid[1][0] == '1':
			no += 1
			ans.append([str(2), str(1)])
		print(no)
		for i in range(no):
			print(' '.join(ans[i]))
	else:
		ans = []
		if grid[1][0] != grid[0][1]:
			if grid[n - 1][n - 2] != grid[n - 2][n - 1]:
				if grid[n - 2][n - 1] == grid[0][1]:
					ans.append(['1', '2'])
					ans.append([str(n), str(n - 1)])
				if grid[n - 2][n - 1] == grid[1][0]:
					ans.append(['1', '2'])
					ans.append([str(n - 1), str(n)])
		print(len(ans))
		for x in ans:
			print(' '.join(x))


from sys import stdin
input = stdin.readline

def A():
	t = int(input())
	for _ in range(t):
		(a, b) = map(int, input().split())
		print(a ^ b)

def B():
	from collections import deque
	t = int(input())
	for _ in range(t):
		n = int(input())
		square = [0 for i in range(n)]
		for i in range(n):
			square[i] = list(input().rstrip())
		(a, b, c, d) = (square[0][1], square[1][0], square[n - 2][n - 1], square[n - 1][n - 2])
		ans = []
		if a == '0' and b == '0':
			if c == '0':
				ans.append([n - 2, n - 1])
			if d == '0':
				ans.append([n - 1, n - 2])
		elif a == '1' and b == '1':
			if c == '1':
				ans.append([n - 2, n - 1])
			if d == '1':
				ans.append([n - 1, n - 2])
		elif a == '1' and b == '0':
			if c == '1' and d == '1':
				ans.append([0, 1])
			elif c == '1' and d == '0':
				ans = [[0, 1], [n - 1, n - 2]]
			elif c == '0' and d == '1':
				ans = [[0, 1], [n - 2, n - 1]]
			elif c == '0' and d == '0':
				ans.append([1, 0])
		elif a == '0' and b == '1':
			if c == '1' and d == '1':
				ans.append([1, 0])
			elif c == '1' and d == '0':
				ans = [[0, 1], [n - 2, n - 1]]
			elif c == '0' and d == '1':
				ans = [[0, 1], [n - 1, n - 2]]
			elif c == '0' and d == '0':
				ans.append([0, 1])
		print(len(ans))
		for i in ans:
			print(i[0] + 1, i[1] + 1)

def C():
	t = int(input())
	for _ in range(t):
		print(_)

def D():
	t = int(input())
	for _ in range(t):
		print(_)
B()


from os import path
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input().rstrip()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 998244353
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')

def ceil1(a, b):
	return (a + b - 1) // b

def solve():
	for _ in range(ii()):
		n = ii()
		a = []
		for i in range(n):
			a.append(list(si()))
		x = [[0, 1], [1, 0], [n - 2, n - 1], [n - 1, n - 2]]
		for i in range(16):
			ok = True
			for j in range(4):
				if i & 1 << j:
					p = x[j]
					x1 = a[p[0]][p[1]]
					x1 = int(x1) ^ 1
					a[p[0]][p[1]] = str(x1)
			q = deque([[0, 0]])
			vis = [[0] * n for i in range(n)]
			vis[0][0] = 1
			while len(q) > 0:
				u = q[0][0]
				v = q[0][1]
				if ok == False:
					break
				q.popleft()
				for k in [[0, 1], [1, 0]]:
					x1 = u + k[0]
					x2 = v + k[1]
					if x1 >= n or x2 >= n or vis[x1][x2]:
						continue
					if a[x1][x2] == 'F':
						ok = False
						break
					if a[x1][x2] == '0':
						continue
					vis[x1][x2] = 1
					q.append([x1, x2])
			q = deque([[0, 0]])
			vis = [[0] * n for i in range(n)]
			vis[0][0] = 1
			while len(q) > 0:
				u = q[0][0]
				v = q[0][1]
				if ok == False:
					break
				q.popleft()
				for k in [[0, 1], [1, 0]]:
					x1 = u + k[0]
					x2 = v + k[1]
					if x1 >= n or x2 >= n or vis[x1][x2]:
						continue
					if a[x1][x2] == 'F':
						ok = False
						break
					if a[x1][x2] == '1':
						continue
					vis[x1][x2] = 1
					q.append([x1, x2])
			ans = []
			for j in range(4):
				if i & 1 << j:
					ans.append(x[j])
					p = x[j]
					x1 = a[p[0]][p[1]]
					x1 = int(x1) ^ 1
					a[p[0]][p[1]] = str(x1)
			if ok:
				print(len(ans))
				for i in ans:
					print(i[0] + 1, i[1] + 1)
				break
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = sys.stdin.readline
solve()


i = int(input())
for _ in range(i):
	ii = int(input())
	lz = []
	for _ in range(ii):
		lz.append(list(input()))
	scor = [lz[0][1], lz[1][0]]
	lcor = [lz[-2][-1], lz[-1][-2]]
	zer = scor.count('0')
	zer += lcor.count('0')
	if zer == 1:
		print(1)
		if scor[0] == '0':
			print('2 1')
		elif scor[1] == '0':
			print('1 2')
		elif lcor[0] == '0':
			print(str(ii) + ' ' + str(ii - 1))
		elif lcor[1] == '0':
			print(str(ii - 1) + ' ' + str(ii))
	elif zer == 3:
		print(1)
		if scor[0] == '1':
			print('2 1')
		elif scor[1] == '1':
			print('1 2')
		elif lcor[0] == '1':
			print(str(ii) + ' ' + str(ii - 1))
		elif lcor[1] == '1':
			print(str(ii - 1) + ' ' + str(ii))
	elif zer == 2:
		if scor.count('0') == 2 or scor.count('1') == 2:
			print(0)
		else:
			print(2)
			print('1 2')
			if scor[0] == '1':
				if lcor[0] == '1':
					print(str(ii) + ' ' + str(ii - 1))
				elif lcor[1] == '1':
					print(str(ii - 1) + ' ' + str(ii))
			elif lcor[0] == '0':
				print(str(ii) + ' ' + str(ii - 1))
			elif lcor[1] == '0':
				print(str(ii - 1) + ' ' + str(ii))
	else:
		print(2)
		print('1 2')
		print('2 1')


t = int(input())
for i in range(t):
	n = list(map(int, input().split()))[0]
	l = [2, 2, 2, 2]
	cords = [(1, 2), (2, 1), (n - 1, n), (n, n - 1)]
	for j in range(n):
		s = input()
		if j == 0:
			l[0] = int(s[1])
		if j == 1:
			l[1] = int(s[0])
		if j == n - 2:
			l[2] = int(s[n - 1])
		if j == n - 1:
			l[3] = int(s[n - 2])
	sum1 = l[0] + l[1]
	sum2 = l[2] + l[3]
	if sum1 == 0:
		if sum2 == 2:
			print(0)
		elif sum2 == 1:
			if l[2] == 0:
				print('1\n{} {}'.format(*cords[2]))
			else:
				print('1\n{} {}'.format(*cords[3]))
		else:
			print('2\n{} {}\n{} {}'.format(*cords[2], *cords[3]))
	elif sum1 == 2:
		if sum2 == 0:
			print(0)
		elif sum2 == 1:
			if l[2] == 0:
				print('1\n{} {}'.format(*cords[3]))
			else:
				print('1\n{} {}'.format(*cords[2]))
		else:
			print('2\n{} {}\n{} {}'.format(*cords[2], *cords[3]))
	elif sum2 == 1:
		if l[0] == l[2]:
			print('2\n{} {}\n{} {}'.format(*cords[0], *cords[3]))
		else:
			print('2\n{} {}\n{} {}'.format(*cords[0], *cords[2]))
	elif sum2 == 0:
		if l[0] == 0:
			print('1\n{} {}'.format(*cords[0]))
		else:
			print('1\n{} {}'.format(*cords[1]))
	elif l[0] == 1:
		print('1\n{} {}'.format(*cords[0]))
	else:
		print('1\n{} {}'.format(*cords[1]))


from collections import Counter
import math
import sys
from bisect import bisect, bisect_left, bisect_right
from itertools import permutations

def input():
	return sys.stdin.readline().strip()

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def mod():
	return 10 ** 9 + 7
for i in range(INT()):
	n = INT()
	arr = []
	xx = 0
	yy = 0
	xx = xx + yy
	for i in range(n):
		s = input()
		a = [str(i) for i in s]
		arr.append(a)
	x = arr[0][1]
	x1 = arr[1][0]
	y = arr[-1][-2]
	y1 = arr[-2][-1]
	if x1 == x and y1 == y and (x1 != y1):
		print(0)
	elif x1 == x == y1 == y:
		print(2)
		print(2, 1)
		print(1, 2)
	elif x1 == x and y1 != y:
		print(1)
		if x != y:
			print(n - 1, n)
		else:
			print(n, n - 1)
	elif x1 != x and y == y1:
		print(1)
		if x != y:
			print(2, 1)
		else:
			print(1, 2)
	elif x1 != x and y != y1:
		print(2)
		if x != y:
			print(1, 2)
			print(n, n - 1)
		else:
			print(1, 2)
			print(n - 1, n)


import math
test = int(input())
for t in range(test):
	n = int(input())
	S = []
	for i in range(n):
		s = input()
		S.append(s)
	a = S[0][1]
	b = S[1][0]
	c = S[n - 1][n - 2]
	d = S[n - 2][n - 1]
	ans = []
	if a == b:
		if c == a:
			ans.append([n, n - 1])
		if d == a:
			ans.append([n - 1, n])
	elif c == d:
		if a == c:
			ans.append([1, 2])
		if b == c:
			ans.append([2, 1])
	else:
		if a == c:
			ans.append([1, 2])
			ans.append([n - 1, n])
		if a == d:
			ans.append([1, 2])
			ans.append([n, n - 1])
	print(len(ans))
	for i in ans:
		print(*i)


def solve(n, m):
	a = m[0][1]
	b = m[1][0]
	c = m[n - 1][n - 2]
	d = m[n - 2][n - 1]
	res = []
	if a == b:
		if a == c:
			res.append([n, n - 1])
		if a == d:
			res.append([n - 1, n])
	elif c == d:
		if c == a:
			res.append([1, 2])
		if b == c:
			res.append([2, 1])
	else:
		res.append([2, 1])
		if a == c:
			res.append([n, n - 1])
		if a == d:
			res.append([n - 1, n])
	print(len(res))
	return res
t = int(input())
for _ in range(t):
	n = int(input())
	r = []
	c = n
	while n:
		x = list(input())
		r.append(x)
		n -= 1
	k = solve(c, r)
	for x in k:
		print(*x)


def main():
	n = int(input())
	(s1, s2, e1, e2) = (0, 0, 0, 0)
	for i in range(n):
		row = input()
		if i == 0:
			s1 = row[1]
		elif i == 1:
			s2 = row[0]
		if i + 2 == n:
			e1 = row[n - 1]
		elif i + 1 == n:
			e2 = row[n - 2]
	if s1 == s2:
		if e1 == e2:
			if e1 == s1:
				print(2)
				print('{} {}'.format(1, 2))
				print('{} {}'.format(2, 1))
			else:
				print(0)
		elif e1 == s1:
			print(1)
			print('{} {}'.format(n - 1, n))
		else:
			print(1)
			print('{} {}'.format(n, n - 1))
	elif e1 == e2:
		if s1 == e1:
			print(1)
			print('{} {}'.format(1, 2))
		else:
			print(1)
			print('{} {}'.format(2, 1))
	elif s1 == e1:
		print(2)
		print('{} {}'.format(1, 2))
		print('{} {}'.format(n, n - 1))
	elif s1 == e2:
		print(2)
		print('{} {}'.format(1, 2))
		print('{} {}'.format(n - 1, n))
for _ in range(int(input())):
	main()


def solve():
	n = int(input())
	start_numbers = set()
	finish_numbers = set()
	matrix = list()
	inversion = list()
	for _ in range(n):
		inp = list(input())
		matrix.append(inp)
	start_numbers.add(matrix[0][1])
	start_numbers.add(matrix[1][0])
	finish_numbers.add(matrix[-1][-2])
	finish_numbers.add(matrix[-2][-1])
	if len(start_numbers) > 1:
		if len(finish_numbers) > 1:
			inversion_number = matrix[1][0]
			inversion.append((1, 2))
			if matrix[-1][-2] == inversion_number:
				inversion.append((n, n - 1))
			else:
				inversion.append((n - 1, n))
		elif matrix[0][1] == matrix[-1][-2]:
			inversion.append((1, 2))
		else:
			inversion.append((2, 1))
	else:
		inversion_number = matrix[0][1]
		if matrix[-1][-2] == inversion_number:
			inversion.append((n, n - 1))
		if matrix[-2][-1] == inversion_number:
			inversion.append((n - 1, n))
	print(len(inversion))
	for coords in inversion:
		print(*coords)

def main():
	for _ in range(int(input())):
		solve()
main()


t = int(input())
for _ in range(t):
	n = int(input())
	mat = [[0 for y in range(n)] for x in range(n)]
	for i in range(n):
		s = input()
		for j in range(n):
			mat[i][j] = s[j]
	if mat[0][1] == mat[1][0] == '0':
		if mat[n - 2][n - 1] == mat[n - 1][n - 2] == '1':
			print(0)
			continue
		elif mat[n - 2][n - 1] == mat[n - 1][n - 2] == '0':
			print(2)
			print(n - 1, n)
			print(n, n - 1)
			continue
		elif mat[n - 2][n - 1] == '1' and mat[n - 1][n - 2] == '0':
			print(1)
			print(n, n - 1)
			continue
		elif mat[n - 2][n - 1] == '0' and mat[n - 1][n - 2] == '1':
			print(1)
			print(n - 1, n)
			continue
	if mat[0][1] == mat[1][0] == '1':
		if mat[n - 2][n - 1] == mat[n - 1][n - 2] == '0':
			print(0)
			continue
		elif mat[n - 2][n - 1] == mat[n - 1][n - 2] == '1':
			print(2)
			print(n - 1, n)
			print(n, n - 1)
			continue
		elif mat[n - 2][n - 1] == '0' and mat[n - 1][n - 2] == '1':
			print(1)
			print(n, n - 1)
			continue
		elif mat[n - 2][n - 1] == '1' and mat[n - 1][n - 2] == '0':
			print(1)
			print(n - 1, n)
			continue
	if mat[0][1] == '1' and mat[1][0] == '0':
		if mat[n - 2][n - 1] == mat[n - 1][n - 2] == '1':
			print(1)
			print(1, 2)
			continue
		elif mat[n - 2][n - 1] == mat[n - 1][n - 2] == '0':
			print(1)
			print(2, 1)
			continue
		elif mat[n - 2][n - 1] == '1' and mat[n - 1][n - 2] == '0':
			print(2)
			print(1, 2)
			print(n, n - 1)
			continue
		elif mat[n - 2][n - 1] == '0' and mat[n - 1][n - 2] == '1':
			print(2)
			print(2, 1)
			print(n, n - 1)
			continue
	if mat[0][1] == '0' and mat[1][0] == '1':
		if mat[n - 2][n - 1] == mat[n - 1][n - 2] == '1':
			print(1)
			print(2, 1)
			continue
		elif mat[n - 2][n - 1] == mat[n - 1][n - 2] == '0':
			print(1)
			print(1, 2)
			continue
		elif mat[n - 2][n - 1] == '1' and mat[n - 1][n - 2] == '0':
			print(2)
			print(1, 2)
			print(n - 1, n)
			continue
		elif mat[n - 2][n - 1] == '0' and mat[n - 1][n - 2] == '1':
			print(2)
			print(1, 2)
			print(n, n - 1)
			continue


for _ in range(int(input())):
	n = int(input())
	d = {}
	for i in range(n):
		o = input()
		for j in range(n):
			x = o[j]
			d[i + 1, j + 1] = x
	if d[1, 2] == d[2, 1] == d[n, n - 1] == d[n - 1, n]:
		print(2)
		print(1, 2)
		print(2, 1)
		continue
	if d[1, 2] == d[2, 1] and d[n, n - 1] == d[n - 1, n]:
		print(0)
		continue
	if d[1, 2] == d[2, 1] == '0':
		print(1)
		if d[n, n - 1] == '0':
			print(n, n - 1)
		else:
			print(n - 1, n)
		continue
	if d[n, n - 1] == d[n - 1, n] == '0':
		print(1)
		if d[1, 2] == '0':
			print(1, 2)
		else:
			print(2, 1)
		continue
	if d[1, 2] == d[2, 1] == '1':
		print(1)
		if d[n, n - 1] == '1':
			print(n, n - 1)
		else:
			print(n - 1, n)
		continue
	if d[n, n - 1] == d[n - 1, n] == '1':
		print(1)
		if d[1, 2] == '1':
			print(1, 2)
		else:
			print(2, 1)
		continue
	if d[1, 2] == '1':
		print(2)
		print(2, 1)
		if d[n, n - 1] == '1':
			print(n, n - 1)
		else:
			print(n - 1, n)
		continue
	else:
		print(2)
		print(1, 2)
		if d[n, n - 1] == '1':
			print(n, n - 1)
		else:
			print(n - 1, n)
		continue


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 998244353

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
	n = val()
	l = []
	for i in range(n):
		l.append(list(st()))
	ans = []
	if l[0][1] == l[1][0]:
		if l[-1][-2] == l[0][1]:
			ans.append([n - 1, n - 2])
		if l[-2][-1] == l[0][1]:
			ans.append([n - 2, n - 1])
	elif l[-1][-2] == l[-2][-1]:
		if l[-1][-2] == l[0][1]:
			ans.append([0, 1])
		else:
			ans.append([1, 0])
	elif l[-1][-2] == l[0][1]:
		ans.append([0, 1])
		ans.append([n - 2, n - 1])
	else:
		ans.append([1, 0])
		ans.append([n - 2, n - 1])
	print(len(ans))
	for i in ans:
		print(i[0] + 1, i[1] + 1)


import sys
from sys import stdin
tt = int(stdin.readline())
for loop in range(tt):
	n = int(stdin.readline())
	s = [stdin.readline()[:-1] for i in range(n)]
	ans = []
	for i in range(2 ** 4):
		(a, b) = (int(s[0][1]), int(s[1][0]))
		(c, d) = (int(s[n - 2][n - 1]), int(s[n - 1][n - 2]))
		now = []
		if i & 1 > 0:
			a ^= 1
			now.append((1, 2))
		if i & 2 > 0:
			b ^= 1
			now.append((2, 1))
		if i & 4 > 0:
			c ^= 1
			now.append((n - 1, n))
		if i & 8 > 0:
			d ^= 1
			now.append((n, n - 1))
		if len(now) <= 2 and (a + b == 0 and c + d == 2 or (a + b == 2 and c + d == 0)):
			ans = now
			break
	print(len(ans))
	for i in ans:
		print(*i)


t = int(input())
while t:
	n = int(input())
	maze = [[0] * n] * n
	for i in range(n):
		s = input()
		row = [i for i in s]
		maze[i] = row
	s_right = maze[0][1]
	s_down = maze[1][0]
	f_up = maze[n - 2][n - 1]
	f_left = maze[n - 1][n - 2]
	f = [f_up, f_left]
	if s_right not in f and s_down not in f:
		print(0)
		t -= 1
		continue
	if s_right != s_down and f_left != f_up:
		if s_right == f_up and s_down == f_left:
			print(2)
			print(1, 2)
			print(n, n - 1)
			t -= 1
			continue
		else:
			print(2)
			print(1, 2)
			print(n - 1, n)
			t -= 1
			continue
	if f_up == f_left:
		num = f_up
		if s_right != s_down:
			if s_right == num:
				print(1)
				print(1, 2)
				t -= 1
				continue
			if s_down == num:
				print(1)
				print(2, 1)
				t -= 1
				continue
	if s_right == s_down:
		num1 = s_right
		if f_up != f_left:
			if f_up == num1:
				print(1)
				print(n - 1, n)
				t -= 1
				continue
			if f_left == num1:
				print(1)
				print(n, n - 1)
				t -= 1
				continue
	if num == num1:
		print(2)
		print(1, 2)
		print(2, 1)
		t -= 1
		continue
	t -= 1


for test_var in range(int(input())):
	n = int(input())
	s = [''] * n
	for i in range(n):
		s[i] = input().strip()
	(a, b, c, d) = (s[0][1], s[1][0], s[n - 1][n - 2], s[n - 2][n - 1])
	if a == b == c == d:
		print('2\n1 2\n2 1')
	elif a != b and c == d:
		if a == c:
			print('1\n1 2')
		else:
			print('1\n2 1')
	elif a == b and c != d:
		if a == c:
			print(f'1\n{n} {n - 1}')
		else:
			print(f'1\n{n - 1} {n}')
	elif a != b and c != d:
		if a == c:
			print(f'2\n1 2\n{n - 1} {n}')
		else:
			print(f'2\n2 1\n{n - 1} {n}')
	else:
		print(0)


from sys import stdout, stdin
from collections import defaultdict, deque
import math
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	l = []
	for i in range(n):
		l.append(list(input()))
	if l[0][1] == '0' and l[1][0] == '0':
		if l[n - 1][n - 2] == '1' and l[n - 2][n - 1] == '1':
			print(0)
		elif l[n - 1][n - 2] == '1' and l[n - 2][n - 1] == '0':
			print(1)
			print(n - 1, n)
		elif l[n - 1][n - 2] == '0' and l[n - 2][n - 1] == '1':
			print(1)
			print(n, n - 1)
		else:
			print(2)
			print(n, n - 1)
			print(n - 1, n)
	elif l[0][1] == '1' and l[1][0] == '1':
		if l[n - 1][n - 2] == '0' and l[n - 2][n - 1] == '0':
			print(0)
		elif l[n - 1][n - 2] == '0' and l[n - 2][n - 1] == '1':
			print(1)
			print(n - 1, n)
		elif l[n - 1][n - 2] == '1' and l[n - 2][n - 1] == '0':
			print(1)
			print(n, n - 1)
		else:
			print(2)
			print(n, n - 1)
			print(n - 1, n)
	elif l[0][1] == '1' and l[1][0] == '0':
		if l[n - 1][n - 2] == '0' and l[n - 2][n - 1] == '0':
			print(1)
			print(2, 1)
		elif l[n - 1][n - 2] == '0' and l[n - 2][n - 1] == '1':
			print(2)
			print(2, 1)
			print(n - 1, n)
		elif l[n - 1][n - 2] == '1' and l[n - 2][n - 1] == '0':
			print(2)
			print(2, 1)
			print(n, n - 1)
		else:
			print(1)
			print(1, 2)
	elif l[0][1] == '0' and l[1][0] == '1':
		if l[n - 1][n - 2] == '0' and l[n - 2][n - 1] == '0':
			print(1)
			print(1, 2)
		elif l[n - 1][n - 2] == '0' and l[n - 2][n - 1] == '1':
			print(2)
			print(1, 2)
			print(n - 1, n)
		elif l[n - 1][n - 2] == '1' and l[n - 2][n - 1] == '0':
			print(2)
			print(2, 1)
			print(n - 1, n)
		else:
			print(1)
			print(2, 1)


for _ in range(int(input())):
	n = int(input())
	siatka = [[] for _ in range(n)]
	for x in range(n):
		siatka[x] = input()
	wynik = []
	if siatka[0][1] == siatka[1][0]:
		if siatka[-1][-2] == siatka[0][1]:
			wynik += [(n, n - 1)]
		if siatka[-2][-1] == siatka[0][1]:
			wynik += [(n - 1, n)]
	elif siatka[-1][-2] == siatka[-2][-1]:
		if siatka[-1][-2] == siatka[0][1]:
			wynik += [(1, 2)]
		if siatka[-2][-1] == siatka[1][0]:
			wynik += [(2, 1)]
	else:
		wynik += [(1, 2)]
		if siatka[-1][-2] == siatka[1][0]:
			wynik += [(n, n - 1)]
		else:
			wynik += [(n - 1, n)]
	print(len(wynik))
	for x in wynik:
		print(x[0], x[1])


import sys, bisect, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
rep = range
R = range

def Golf():
	(n, *t) = map(int, open(0).read().split())

def I():
	return int(input())

def S_():
	return input()

def IS():
	return input().split()

def LS():
	return [i for i in input().split()]

def MI():
	return map(int, input().split())

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def NLI(n):
	return [[int(i) for i in input().split()] for i in range(n)]

def NLI_(n):
	return [[int(i) - 1 for i in input().split()] for i in range(n)]

def StoLI():
	return [ord(i) - 97 for i in input()]

def ItoS(n):
	return chr(n + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def RA():
	return map(int, open(0).read().split())

def RLI(n=8, a=1, b=10):
	return [random.randint(a, b) for i in range(n)]

def RI(a=1, b=10):
	return random.randint(a, b)

def INP():
	N = 10
	A = 10
	n = random.randint(1, N)
	a = [random.randint(1, A) for i in range(n)]
	return (n, a)

def Rtest(T):
	(case, err) = (0, 0)
	for i in range(T):
		inp = INP()
		a1 = naive(*inp)
		a2 = solve(*inp)
		if a1 != a2:
			print((a1, a2), inp)
			err += 1
		case += 1
	print('Tested', case, 'case with', err, 'errors')

def GI(V, E, ls=None, Directed=False, index=1):
	org_inp = []
	g = [[] for i in range(V)]
	FromStdin = True if ls == None else False
	for i in range(E):
		if FromStdin:
			inp = LI()
			org_inp.append(inp)
		else:
			inp = ls[i]
		if len(inp) == 2:
			(a, b) = inp
			c = 1
		else:
			(a, b, c) = inp
		if index == 1:
			a -= 1
			b -= 1
		aa = (a, c)
		bb = (b, c)
		g[a].append(bb)
		if not Directed:
			g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}, boundary=1):
	mp = [boundary] * (w + 2)
	found = {}
	for i in R(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [boundary] + [mp_def[j] for j in s] + [boundary]
	mp += [boundary] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def accum(ls):
	rt = [0]
	for i in ls:
		rt += [rt[-1] + i]
	return rt

def bit_combination(n, base=2):
	rt = []
	for tb in R(base ** n):
		s = [tb // base ** bt % base for bt in R(n)]
		rt += [s]
	return rt

def gcd(x, y):
	if y == 0:
		return x
	if x % y == 0:
		return y
	while x % y != 0:
		(x, y) = (y, x % y)
	return y

def YN(x):
	print(['NO', 'YES'][x])

def Yn(x):
	print(['No', 'Yes'][x])

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
mo = 10 ** 9 + 7
inf = float('inf')
FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)]
EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip('WENS', FourNb))
cursol = dict(zip('LRUD', FourNb))
l_alp = string.ascii_lowercase
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = lambda : sys.stdin.readline().rstrip()
show_flg = False
ans = 0
for _ in range(I()):
	ans = 0
	h = w = I()
	m = []
	for i in range(h):
		m += (input(),)
	(a, b, c, d) = (m[0][1], m[1][0], m[h - 1][w - 2], m[h - 2][w - 1])
	l = [a, b, c, d]
	(a, b, c, d) = map(int, l)
	l = [a, b, c, d]
	if a == 1:
		(a, b, c, d) = map(lambda x: 1 - x, l)
	ans = []
	y = [(1, 2), (2, 1), (h, w - 1), (h - 1, w)]
	for i in range(1 << 4):
		cnt = sum((i >> j & 1 for j in range(4)))
		if cnt > 2:
			continue
		x = l[:]
		for j in range(4):
			if i >> j & 1:
				x[j] = 1 - x[j]
		if x[0] == x[1] and x[2] == x[3] and (x[0] != x[2]):
			for j in range(4):
				if i >> j & 1:
					ans += (y[j],)
			break
	print(cnt)
	for i in ans:
		print(*i)


for _ in range(int(input())):
	n = int(input())
	s = []
	for i in range(n):
		temp = input()
		s.append([i for i in temp])
	cnt1 = 0
	ans1 = []
	cnt2 = 0
	ans2 = []
	if s[0][1] == '0':
		pass
	else:
		cnt1 += 1
		ans1.append([1, 2])
	if s[1][0] == '0':
		pass
	else:
		cnt1 += 1
		ans1.append([2, 1])
	if s[-1][-2] == '1':
		pass
	else:
		cnt1 += 1
		ans1.append([n, n - 1])
	if s[-2][-1] == '1':
		pass
	else:
		cnt1 += 1
		ans1.append([n - 1, n])
	if s[0][1] == '1':
		pass
	else:
		cnt2 += 1
		ans2.append([1, 2])
	if s[1][0] == '1':
		pass
	else:
		cnt2 += 1
		ans2.append([2, 1])
	if s[-1][-2] == '0':
		pass
	else:
		cnt2 += 1
		ans2.append([n, n - 1])
	if s[-2][-1] == '0':
		pass
	else:
		cnt2 += 1
		ans2.append([n - 1, n])
	if cnt1 <= 2:
		print(cnt1)
		for i in ans1:
			print(*i)
	else:
		print(cnt2)
		for i in ans2:
			print(*i)


for _ in range(int(input())):
	n = int(input())
	g = [input() for _ in range(n)]
	x1 = g[0][1] + g[1][0]
	x2 = g[-1][-2] + g[-2][-1]
	if x1[0] == x1[1] == x2[0] == x2[1]:
		print(2)
		print(1, 2)
		print(2, 1)
		continue
	if (x1[0] != x2[0]) == (x1[1] != x2[1]):
		if x1[0] == x1[1] and x2[0] == x2[1]:
			print(0)
			continue
		if x1[0] == x2[1] and x2[0] == x1[1]:
			print(2)
			print(1, 2)
			print(n, n - 1)
			continue
		if x1[0] == x2[0] and x1[1] == x2[1]:
			print(2)
			print(1, 2)
			print(n - 1, n)
			continue
	if x1[0] == x1[1] == x2[0]:
		print(1)
		print(n, n - 1)
		continue
	if x1[0] == x1[1] == x2[1]:
		print(1)
		print(n - 1, n)
		continue
	if x2[0] == x2[1] == x1[0]:
		print(1)
		print(1, 2)
		continue
	if x2[0] == x2[1] == x1[1]:
		print(1)
		print(2, 1)
		continue


t = int(input())
for _ in range(t):
	n = int(input())
	brick = [[0 for _ in range(n)] for _ in range(n)]
	brick[0][0] = 'S'
	brick[n - 1][n - 1] = 'F'
	for i in range(n):
		string = input()
		for j in range(len(string)):
			if string[j] != 'F' and string[j] != 'S':
				brick[i][j] = int(string[j])
			else:
				brick[i][j] = string[j]
	if brick[0][1] == 1 and brick[1][0] == 1 and (brick[n - 2][n - 1] == 0) and (brick[n - 1][n - 2] == 0):
		print(0)
	if brick[0][1] == 0 and brick[1][0] == 0 and (brick[n - 2][n - 1] == 1) and (brick[n - 1][n - 2] == 1):
		print(0)
	if brick[0][1] == 1 and brick[1][0] == 1 and (brick[n - 2][n - 1] == 0) and (brick[n - 1][n - 2] == 1):
		print(1)
		print(n, n - 1)
	if brick[0][1] == 1 and brick[1][0] == 1 and (brick[n - 2][n - 1] == 1) and (brick[n - 1][n - 2] == 0):
		print(1)
		print(n - 1, n)
	if brick[0][1] == 0 and brick[1][0] == 1 and (brick[n - 2][n - 1] == 1) and (brick[n - 1][n - 2] == 1):
		print(1)
		print(2, 1)
	if brick[0][1] == 1 and brick[1][0] == 0 and (brick[n - 2][n - 1] == 1) and (brick[n - 1][n - 2] == 1):
		print(1)
		print(1, 2)
	if brick[0][1] == 0 and brick[1][0] == 0 and (brick[n - 2][n - 1] == 0) and (brick[n - 1][n - 2] == 1):
		print(1)
		print(n - 1, n)
	if brick[0][1] == 0 and brick[1][0] == 0 and (brick[n - 2][n - 1] == 1) and (brick[n - 1][n - 2] == 0):
		print(1)
		print(n, n - 1)
	if brick[0][1] == 1 and brick[1][0] == 0 and (brick[n - 2][n - 1] == 0) and (brick[n - 1][n - 2] == 0):
		print(1)
		print(2, 1)
	if brick[0][1] == 0 and brick[1][0] == 1 and (brick[n - 2][n - 1] == 0) and (brick[n - 1][n - 2] == 0):
		print(1)
		print(1, 2)
	if brick[0][1] == 1 and brick[1][0] == 1 and (brick[n - 2][n - 1] == 1) and (brick[n - 1][n - 2] == 1):
		print(2)
		print(n - 1, n)
		print(n, n - 1)
	if brick[0][1] == 0 and brick[1][0] == 0 and (brick[n - 2][n - 1] == 0) and (brick[n - 1][n - 2] == 0):
		print(2)
		print(n - 1, n)
		print(n, n - 1)
	if brick[0][1] == 1 and brick[1][0] == 0 and (brick[n - 2][n - 1] == 0) and (brick[n - 1][n - 2] == 1):
		print(2)
		print(1, 2)
		print(n - 1, n)
	if brick[0][1] == 1 and brick[1][0] == 0 and (brick[n - 2][n - 1] == 1) and (brick[n - 1][n - 2] == 0):
		print(2)
		print(1, 2)
		print(n, n - 1)
	if brick[0][1] == 0 and brick[1][0] == 1 and (brick[n - 2][n - 1] == 0) and (brick[n - 1][n - 2] == 1):
		print(2)
		print(1, 2)
		print(n, n - 1)
	if brick[0][1] == 0 and brick[1][0] == 1 and (brick[n - 2][n - 1] == 1) and (brick[n - 1][n - 2] == 0):
		print(2)
		print(1, 2)
		print(n - 1, n)


from collections import Counter as ctr
inp = lambda : int(input())
strl = lambda : list(input().strip())
seq = lambda : list(map(int, input().strip().split()))

def results(arr, n):
	(a, b, c, d) = (arr[0][1], arr[1][0], arr[n - 1][-2], arr[n - 2][-1])
	cd = ctr([a, b, c, d])
	if len(cd) == 1:
		return [2, [[1, 2], [2, 1]]]
	else:
		if cd['1'] == cd['0']:
			if a == b:
				return [0]
			elif a == c:
				return [2, [[1, 2], [n - 1, n]]]
			else:
				return [2, [[1, 2], [n, n - 1]]]
		if cd['0'] > cd['1']:
			if a != '0':
				return [1, [[2, 1]]]
			elif b != '0':
				return [1, [[1, 2]]]
			elif c != '0':
				return [1, [[n - 1, n]]]
			else:
				return [1, [[n, n - 1]]]
		else:
			if a != '1':
				return [1, [[2, 1]]]
			if b != '1':
				return [1, [[1, 2]]]
			if c != '1':
				return [1, [[n - 1, n]]]
			else:
				return [1, [[n, n - 1]]]

def main():
	t = inp()
	for _ in range(t):
		n = inp()
		a = []
		for _ in range(n):
			a.append(strl())
		result = results(a, n)
		if len(result) == 1:
			print(result[0])
		else:
			print(result[0])
			for i in range(len(result[1])):
				print(*result[1][i])
main()


import sys
import math

def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
t = II()
for q in range(t):
	n = II()
	l = []
	for i in range(n):
		l.append(list(SI()))
	(a, b) = (l[0][1], l[1][0])
	(c, d) = (l[n - 1][n - 2], l[n - 2][n - 1])
	ans = []
	if a == b and c == d:
		if a == b == c == d:
			ans.append([1, 2])
			ans.append([2, 1])
	elif a == b:
		if c == a:
			ans.append([n, n - 1])
		else:
			ans.append([n - 1, n])
	elif c == d:
		if c == a:
			ans.append([1, 2])
		else:
			ans.append([2, 1])
	elif a == c:
		ans.append([1, 2])
		ans.append([n - 1, n])
	else:
		ans.append([1, 2])
		ans.append([n, n - 1])
	print(len(ans))
	for i in ans:
		print(*i)


for tt in range(int(input())):
	n = int(input())
	g = [input() for i in range(n)]
	for i in range(2):
		m = []
		if g[0][1] != str(i):
			m.append((0, 1))
		if g[1][0] != str(i):
			m.append((1, 0))
		if g[n - 1][-2] != str(i ^ 1):
			m.append((n - 1, n - 2))
		if g[-2][n - 1] != str(i ^ 1):
			m.append((n - 2, n - 1))
		if len(m) <= 2:
			print(len(m))
			for j in m:
				print(j[0] + 1, j[1] + 1)
			break


for t__ in range(int(input())):
	n = int(input())
	if n != 3:
		s1 = input()
		s2 = input()
		for i in range(n - 4):
			s__ = input()
		s3 = input()
		s4 = input()
		s1 = int(s1[1])
		s2 = int(s2[0])
		s3 = int(s3[-1])
		s4 = int(s4[-2])
	else:
		s1 = input()
		s2 = input()
		s3 = input()
		s1 = int(s1[1])
		s2_ = int(s2[0])
		s3_ = int(s2[-1])
		s4 = int(s3[-2])
		s2 = s2_
		s3 = s3_
	if s1 == s2 == s3 == s4:
		print(2)
		print(1, 2)
		print(2, 1)
	elif s1 == s2 and s3 == s4:
		print(0)
	elif s1 == s2 and s3 != s4:
		print(1)
		if s3 == s1:
			print(n - 1, n)
		else:
			print(n, n - 1)
	elif s3 == s4 and s1 != s2:
		print(1)
		if s1 == s3:
			print(1, 2)
		else:
			print(2, 1)
	elif s1 == s3 and s2 == s4:
		print(2)
		print(2, 1)
		print(n - 1, n)
	else:
		print(2)
		print(2, 1)
		print(n, n - 1)


for i in range(int(input())):
	n = int(input())
	l = list()
	for i in range(n):
		x = input()
		lst = list()
		for i in x:
			lst.append(i)
		l.append(lst)
	l1 = l[n - 2][n - 1]
	l2 = l[n - 1][n - 2]
	f1 = l[0][1]
	f2 = l[1][0]
	if int(f1) == 0 and int(f2) == 0:
		if int(l1) == 0 and int(l2) == 0:
			print(2)
			print(n - 2 + 1, n - 1 + 1)
			print(n - 1 + 1, n - 2 + 1)
		elif int(l1) == 1 and int(l2) == 0:
			print(1)
			print(n - 1 + 1, n - 2 + 1)
		elif int(l1) == 0 and int(l2) == 1:
			print(1)
			print(n - 2 + 1, n - 1 + 1)
		else:
			print(0)
	elif int(f1) == 1 and int(f2) == 1:
		if int(l1) == 1 and int(l2) == 1:
			print(2)
			print(n - 2 + 1, n - 1 + 1)
			print(n - 1 + 1, n - 2 + 1)
		elif int(l1) == 0 and int(l2) == 1:
			print(1)
			print(n - 1 + 1, n - 2 + 1)
		elif int(l1) == 1 and int(l2) == 0:
			print(1)
			print(n - 2 + 1, n - 1 + 1)
		else:
			print(0)
	elif int(f1) == 0 and int(f2) == 1:
		if int(l1) == 0 and int(l2) == 0:
			print(1)
			print(1, 2)
		elif int(l1) == 1 and int(l2) == 0:
			print(2)
			print(2, 1)
			print(n - 1 + 1, n - 2 + 1)
		elif int(l1) == 0 and int(l2) == 1:
			print(2)
			print(2, 1)
			print(n - 2 + 1, n - 1 + 1)
		else:
			print(1)
			print(2, 1)
	elif int(f1) == 1 and int(f2) == 0:
		if int(l1) == 0 and int(l2) == 0:
			print(1)
			print(2, 1)
		elif int(l1) == 1 and int(l2) == 0:
			print(2)
			print(1, 2)
			print(n - 1 + 1, n - 2 + 1)
		elif int(l1) == 0 and int(l2) == 1:
			print(2)
			print(1, 2)
			print(n - 2 + 1, n - 1 + 1)
		else:
			print(1)
			print(1, 2)


for _ in range(int(input())):
	n = int(input())
	a = [input() for j in range(n)]
	if a[0][1] == a[1][0] == '1' and a[n - 2][n - 1] == a[n - 1][n - 2] == '0' or (a[0][1] == a[1][0] == '0' and a[n - 2][n - 1] == a[n - 1][n - 2] == '1'):
		print(0)
	else:
		(n1, n2, n3, n4) = (int(a[0][1]), int(a[1][0]), int(a[n - 1][n - 2]), int(a[n - 2][n - 1]))
		if n1 + n2 == n3 + n4 == 0 or n1 + n2 == n3 + n4 == 2:
			print(2)
			print(1, 2)
			print(2, 1)
		elif n1 + n2 == 1 and n3 + n4 == 1:
			print(2)
			print(1, 2)
			if n1 == 1:
				if n3 == 0:
					print(n, n - 1)
				else:
					print(n - 1, n)
			elif n3 == 1:
				print(n, n - 1)
			else:
				print(n - 1, n)
		elif n1 + n2 == 0 and n3 + n4 == 1:
			print(1)
			if n3 == 0:
				print(n, n - 1)
			else:
				print(n - 1, n)
		elif n1 + n2 == 1 and n3 + n4 == 0:
			print(1)
			if n1 == 0:
				print(1, 2)
			else:
				print(2, 1)
		elif n1 + n2 == 1 and n3 + n4 == 2:
			print(1)
			if n1 == 1:
				print(1, 2)
			else:
				print(2, 1)
		else:
			print(1)
			if n3 == 1:
				print(n, n - 1)
			else:
				print(n - 1, n)


from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	grid = []
	for i in range(n):
		grid.append([i for i in input()])
	if grid[0][1] == grid[1][0]:
		ans = []
		if grid[0][1] == '0':
			if grid[n - 1][n - 2] == '0':
				ans.append([n, n - 1])
			if grid[n - 2][n - 1] == '0':
				ans.append([n - 1, n])
		if grid[0][1] == '1':
			if grid[n - 1][n - 2] == '1':
				ans.append([n, n - 1])
			if grid[n - 2][n - 1] == '1':
				ans.append([n - 1, n])
	else:
		ans = []
		if grid[n - 1][n - 2] == grid[n - 2][n - 1]:
			x = grid[n - 1][n - 2]
			if grid[0][1] == x:
				ans.append([1, 2])
			if grid[1][0] == x:
				ans.append([2, 1])
		else:
			if grid[0][1] == '1':
				ans.append([1, 2])
			if grid[1][0] == '1':
				ans.append([2, 1])
			if grid[n - 1][n - 2] == '0':
				ans.append([n, n - 1])
			if grid[n - 2][n - 1] == '0':
				ans.append([n - 1, n])
	print(len(ans))
	for i in ans:
		print(*i)


t = int(input())
for i in range(t):
	n = int(input())
	l = []
	for j in range(n):
		l.append(list(input()))
	(a, b, c, d) = (l[0][1], l[1][0], l[n - 2][n - 1], l[n - 1][n - 2])
	if a == '1':
		if b == '1':
			if c == '1':
				if d == '1':
					print(2)
					print('1 2')
					print('2 1')
				else:
					print('1')
					print(str(n - 1) + ' ' + str(n))
			elif d == '1':
				print('1')
				print(str(n) + ' ' + str(n - 1))
			else:
				print(0)
		elif c == '1':
			if d == '1':
				print('1')
				print('1 2')
			else:
				print(2)
				print(str(n - 1) + ' ' + str(n))
				print('2 1')
		elif d == '1':
			print('2')
			print(str(n - 1) + ' ' + str(n))
			print('1 2')
		else:
			print('1')
			print('2 1')
	elif b == '1':
		if c == '1':
			if d == '1':
				print('1')
				print('2 1')
			else:
				print('2')
				print(str(n - 1) + ' ' + str(n))
				print('1 2')
		elif d == '1':
			print(2)
			print(str(n) + ' ' + str(n - 1))
			print('1 2')
		else:
			print('1')
			print('1 2')
	elif c == '1':
		if d == '1':
			print(0)
		else:
			print('1')
			print(str(n) + ' ' + str(n - 1))
	elif d == '1':
		print('1')
		print(str(n - 1) + ' ' + str(n))
	else:
		print('2')
		print(str(n - 1) + ' ' + str(n))
		print(str(n) + ' ' + str(n - 1))


for _ in range(int(input())):
	n = int(input())
	mat = []
	c = 0
	for i in range(n):
		mat.append(list(input()))
	out = []
	if mat[1][0] == mat[0][1]:
		par = int(mat[1][0]) ^ 1
		if mat[-1][-2] != str(par):
			c += 1
			out.append((n, n - 1))
		if mat[-2][-1] != str(par):
			c += 1
			out.append((n - 1, n))
	elif mat[-1][-2] == mat[-2][-1]:
		par = int(mat[-1][-2]) ^ 1
		if mat[1][0] != str(par):
			out.append((2, 1))
			c += 1
		if mat[0][1] != str(par):
			out.append((1, 2))
			c += 1
	else:
		par = 0
		if mat[1][0] != str(par):
			out.append((2, 1))
			c += 1
		else:
			out.append((1, 2))
			c += 1
		par = 1
		if mat[-1][-2] != str(par):
			c += 1
			out.append((n, n - 1))
		if mat[-2][-1] != str(par):
			c += 1
			out.append((n - 1, n))
	print(c)
	for i in out:
		print(*i)


import sys
input = sys.stdin.readline
from collections import defaultdict as dc
from bisect import bisect_right
import math
for _ in range(int(input())):
	n = int(input())
	l = []
	for i in range(n):
		l.append(list(input()))
	(a, b, x, y) = (l[0][1], l[1][0], l[n - 1][n - 2], l[n - 2][n - 1])
	if a == '1' and b == '1':
		if x == '0' and y == '0':
			print(0)
		else:
			p = []
			c = 0
			if x == '1':
				c += 1
				p.append([n, n - 1])
			if y == '1':
				c += 1
				p.append([n - 1, n])
			print(c)
			for t in p:
				print(*t)
	elif a == '0' and b == '0':
		if x == '1' and y == '1':
			print(0)
		else:
			p = []
			c = 0
			if x == '0':
				c += 1
				p.append([n, n - 1])
			if y == '0':
				c += 1
				p.append([n - 1, n])
			print(c)
			for t in p:
				print(*t)
	elif x == y:
		p = []
		if a == x:
			p = [1, 2]
		else:
			p = [2, 1]
		print(1)
		print(*p)
	else:
		print(2)
		if a == '1':
			print(1, 2)
		elif b == '1':
			print(2, 1)
		if x == '0':
			print(n, n - 1)
		elif y == '0':
			print(n - 1, n)


import sys

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def solve():
	n = mint()
	a = [None] * n
	for i in range(n):
		a[i] = minp()
	c = [None, None, None, None]
	pos = [(0, 1, 0), (1, 0, 1), (2, n - 1, n - 2), (3, n - 2, n - 1)]
	for (i, x, y) in pos:
		c[i] = a[x][y]
	for v in ((0, 0, 1, 1), (1, 1, 0, 0)):
		cnt = sum([int(c[i]) ^ v[i] for i in range(4)])
		if cnt <= 2:
			print(cnt)
			for (i, x, y) in pos:
				if int(c[i]) != v[i]:
					print(x + 1, y + 1)
			return
for i in range(mint()):
	solve()


for _ in range(int(input())):
	n = int(input())
	grid = [[None] * n] * n
	c = 0
	changed = []
	for i in range(n):
		grid[i] = list(input())
	if grid[0][1] == grid[1][0]:
		a = grid[0][1]
		if grid[n - 1][n - 2] == a:
			c += 1
			changed.append([n, n - 1])
		if grid[n - 2][n - 1] == a:
			c += 1
			changed.append([n - 1, n])
	elif grid[n - 2][n - 1] == grid[n - 1][n - 2]:
		a = grid[n - 2][n - 1]
		if grid[1][0] == a:
			c += 1
			changed.append([2, 1])
		if grid[0][1] == a:
			c += 1
			changed.append([1, 2])
	else:
		c = 2
		changed.append([1, 2])
		if grid[n - 2][n - 1] == grid[0][1]:
			changed.append([n, n - 1])
		else:
			changed.append([n - 1, n])
	print(c)
	for i in changed:
		print(*i)


for _ in range(int(input())):
	n = int(input())
	ar = []
	for i in range(n):
		ar.append(list(input()))
	st = [int(ar[0][1]), int(ar[1][0])]
	fi = [int(ar[n - 1][n - 2]), int(ar[n - 2][n - 1])]
	ans = []
	if st[0] != st[1] and fi[0] != fi[1]:
		if st[0] != 0:
			ans.append([1, 2])
		if st[1] != 0:
			ans.append([2, 1])
		if fi[0] != 1:
			ans.append([n, n - 1])
		if fi[1] != 1:
			ans.append([n - 1, n])
	elif st[0] == st[1]:
		ty = abs(st[0] - 1)
		if fi[0] != ty:
			ans.append([n, n - 1])
		if fi[1] != ty:
			ans.append([n - 1, n])
	elif fi[0] == fi[1]:
		ty = abs(fi[0] - 1)
		if st[0] != ty:
			ans.append([1, 2])
		if st[1] != ty:
			ans.append([2, 1])
	print(len(ans))
	for i in ans:
		print(*i)


import sys
import math
from math import *
from collections import Counter, defaultdict, deque
from bisect import bisect_left
import random
lip = lambda : list(map(int, input().split()))
ip = lambda : int(input())
sip = lambda : input().split()
mod = 10 ** 9 + 7

def main():
	n = ip()
	mat = []
	for i in range(n):
		mat.append(input())
	ctr = 0
	if mat[0][1] == '1':
		ctr += 1
	if mat[1][0] == '1':
		ctr += 1
	c = 0
	if mat[-1][-2] == '1':
		c += 1
	if mat[-2][-1] == '1':
		c += 1
	if ctr == 0:
		if c == 2:
			print(0)
		elif c == 0:
			print(2)
			print(n, n - 1)
			print(n - 1, n)
		else:
			print(1)
			if mat[-2][-1] == '1':
				print(n, n - 1)
			else:
				print(n - 1, n)
	elif ctr == 2:
		if c == 0:
			print(0)
		elif c == 2:
			print(2)
			print(n, n - 1)
			print(n - 1, n)
		else:
			print(1)
			if mat[-2][-1] == '0':
				print(n, n - 1)
			else:
				print(n - 1, n)
	elif c == 2:
		print(1)
		if mat[0][1] == '1':
			print(1, 2)
		else:
			print(2, 1)
	elif c == 0:
		print(1)
		if mat[0][1] == '0':
			print(1, 2)
		else:
			print(2, 1)
	else:
		print(2)
		if mat[0][1] == '0':
			print(1, 2)
		if mat[1][0] == '0':
			print(2, 1)
		if mat[-1][-2] == '1':
			print(n, n - 1)
		if mat[-2][-1] == '1':
			print(n - 1, n)
for i in range(ip()):
	main()


t = int(input())
while t:
	t -= 1
	n = int(input())
	for i in range(n):
		s = input().strip()
		if i == 0:
			a = int(s[1])
		if i == 1:
			b = int(s[0])
		if i == n - 2:
			c = int(s[-1])
		if i == n - 1:
			d = int(s[-2])
		else:
			continue
	count = 0
	if a == b:
		if c == a:
			count += 1
		if d == a:
			count += 1
		print(count)
		if c == a:
			print('%d %d' % (n - 1, n))
		if d == a:
			print('%d %d' % (n, n - 1))
	elif c == d:
		if c == a:
			count += 1
		if c == b:
			count += 1
		print(count)
		if c == a:
			print('%d %d' % (1, 2))
		if c == b:
			print('%d %d' % (2, 1))
	else:
		if a != 0:
			count += 1
		if b != 0:
			count += 1
		if c != 1:
			count += 1
		if d != 1:
			count += 1
		print(count)
		if a != 0:
			print('%d %d' % (1, 2))
		if b != 0:
			print('%d %d' % (2, 1))
		if c != 1:
			print('%d %d' % (n - 1, n))
		if d != 1:
			print('%d %d' % (n, n - 1))


t = int(input())
for _ in range(t):
	n = int(input())
	grid = []
	for i in range(n):
		grid.append(list(input()))
	top1 = grid[0][1]
	top2 = grid[1][0]
	down1 = grid[n - 2][n - 1]
	down2 = grid[n - 1][n - 2]
	if top1 == '0' and top2 == '0':
		if down1 == '0' and down2 == '0':
			print(2)
			print(1, 2)
			print(2, 1)
		elif down1 == '0' and down2 == '1':
			print(1)
			print(n - 1, n)
		elif down1 == '1' and down2 == '0':
			print(1)
			print(n, n - 1)
		else:
			print(0)
	elif top1 == '1' and top2 == '1':
		if down1 == '0' and down2 == '0':
			print(0)
		elif down1 == '0' and down2 == '1':
			print(1)
			print(n, n - 1)
		elif down1 == '1' and down2 == '0':
			print(1)
			print(n - 1, n)
		else:
			print(2)
			print(1, 2)
			print(2, 1)
	elif top1 == '0' and top2 == '1':
		if down1 == '0' and down2 == '0':
			print(1)
			print(1, 2)
		elif down1 == '0' and down2 == '1':
			print(2)
			print(n - 1, n)
			print(2, 1)
		elif down1 == '1' and down2 == '0':
			print(2)
			print(2, 1)
			print(n, n - 1)
		else:
			print(1)
			print(2, 1)
	elif down1 == '0' and down2 == '0':
		print(1)
		print(2, 1)
	elif down1 == '0' and down2 == '1':
		print(2)
		print(n, n - 1)
		print(2, 1)
	elif down1 == '1' and down2 == '0':
		print(2)
		print(2, 1)
		print(n - 1, n)
	else:
		print(1)
		print(1, 2)


t = int(input())
for _ in range(t):
	n = int(input())
	lst = [list(input()) for _ in range(n)]
	ans = []
	b1 = int(lst[0][1])
	b2 = int(lst[1][0])
	b3 = int(lst[n - 1][n - 2])
	b4 = int(lst[n - 2][n - 1])
	if b1 == b2 == b3 == b4:
		ans.append((1, 2))
		ans.append((2, 1))
	elif b1 == b2 and b3 != b4:
		if b1 == b3:
			ans.append((n, n - 1))
		else:
			ans.append((n - 1, n))
	elif b3 == b4 and b1 != b2:
		if b3 == b1:
			ans.append((1, 2))
		else:
			ans.append((2, 1))
	elif b1 == b3 and b2 == b4:
		ans.append((1, 2))
		ans.append((n - 1, n))
	elif b1 == b4 and b2 == b3:
		ans.append((1, 2))
		ans.append((n, n - 1))
	if ans:
		print(len(ans))
		for i in ans:
			print(*i)
	else:
		print(0)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = []
	for _ in range(n):
		arr.append(input())
	topright = int(arr[0][1])
	topbtm = int(arr[1][0])
	btmup = int(arr[-2][-1])
	btmleft = int(arr[-1][-2])
	if topright == 0 and topbtm == 0:
		if btmup == 0 and btmleft == 0:
			print(2)
			print('%i %i' % (n - 1, n))
			print('%i %i' % (n, n - 1))
		elif btmup == 0 and btmleft == 1:
			print(1)
			print('%i %i' % (n - 1, n))
		elif btmup == 1 and btmleft == 0:
			print(1)
			print('%i %i' % (n, n - 1))
		else:
			print(0)
	elif topright == 1 and topbtm == 1:
		if btmup == 0 and btmleft == 0:
			print(0)
		elif btmup == 0 and btmleft == 1:
			print(1)
			print('%i %i' % (n, n - 1))
		elif btmup == 1 and btmleft == 0:
			print(1)
			print('%i %i' % (n - 1, n))
		else:
			print(2)
			print('%i %i' % (n - 1, n))
			print('%i %i' % (n, n - 1))
	elif topright == 0 and topbtm == 1:
		if btmup == 0 and btmleft == 0:
			print(1)
			print('1 2')
		elif btmup == 0 and btmleft == 1:
			print(2)
			print('1 2')
			print('%i %i' % (n, n - 1))
		elif btmup == 1 and btmleft == 0:
			print(2)
			print('1 2')
			print('%i %i' % (n - 1, n))
		else:
			print(1)
			print('2 1')
	elif topright == 1 and topbtm == 0:
		if btmup == 0 and btmleft == 0:
			print(1)
			print('2 1')
		elif btmup == 0 and btmleft == 1:
			print(2)
			print('2 1')
			print('%i %i' % (n, n - 1))
		elif btmup == 1 and btmleft == 0:
			print(2)
			print('2 1')
			print('%i %i' % (n - 1, n))
		else:
			print(1)
			print('1 2')


t = int(input())
for i in range(t):
	n = int(input())
	m = [[i for i in input()] for i in range(n)]
	q = int(m[1][0])
	w = int(m[0][1])
	a = int(m[-1][-2])
	s = int(m[-2][-1])
	e = n - 1
	if q == w:
		if a == s:
			if q == a:
				print('2', '\n', '1 2', '\n', '2 1', sep='')
			else:
				print('0')
		elif q == a:
			print('1', '\n', n, ' ', e, sep='')
		else:
			print('1', '\n', e, ' ', n, sep='')
	elif a == s:
		if q == a:
			print('1', '\n', '2 1', sep='')
		else:
			print('1', '\n', '1 2', sep='')
	elif q == a:
		print('2', '\n', '1 2', '\n', n, ' ', e, sep='')
	else:
		print('2', '\n', '1 2', '\n', e, ' ', n, sep='')


from collections import defaultdict
mod = 10 ** 9 + 7
INF = float('inf')

def getlist():
	return list(map(int, input().split()))

def main():
	T = int(input())
	for _ in range(T):
		N = int(input())
		L = []
		for i in range(N):
			l = list(input())
			L.append(l)
		a1 = int(L[0][1])
		a2 = int(L[1][0])
		a3 = int(L[-2][-1])
		a4 = int(L[-1][-2])
		ans1 = []
		cnt1 = 0
		if a1 != 0:
			ans1.append([1, 2])
			cnt1 += 1
		if a2 != 0:
			ans1.append([2, 1])
			cnt1 += 1
		if a3 != 1:
			ans1.append([N - 1, N])
			cnt1 += 1
		if a4 != 1:
			ans1.append([N, N - 1])
			cnt1 += 1
		ans2 = []
		cnt2 = 0
		if a1 != 1:
			ans2.append([1, 2])
			cnt2 += 1
		if a2 != 1:
			ans2.append([2, 1])
			cnt2 += 1
		if a3 != 0:
			ans2.append([N - 1, N])
			cnt2 += 1
		if a4 != 0:
			ans2.append([N, N - 1])
			cnt2 += 1
		if cnt1 <= cnt2:
			print(cnt1)
			for i in range(len(ans1)):
				print(*ans1[i])
		else:
			print(cnt2)
			for i in range(len(ans2)):
				print(*ans2[i])
main()


for tc in range(int(input())):
	n = int(input())
	mat = []
	for i in range(n):
		mat.append(input())
	x = mat[0][1]
	y = mat[1][0]
	p = mat[-1][-2]
	q = mat[-2][-1]
	if x == y and p == q:
		if x == p:
			print('2')
			print('1 2')
			print('2 1')
		else:
			print('0')
	elif x == y:
		print('1')
		if p != x:
			print(n - 1, n)
		elif q != x:
			print(n, n - 1)
	elif p == q:
		print('1')
		if x != p:
			print('2 1')
		elif y != p:
			print('1 2')
	else:
		print('2')
		if x == p:
			print('1 2')
			print(n - 1, n)
		else:
			print('1 2')
			print(n, n - 1)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	grid = [[]]
	for i in range(n):
		line = ' ' + input().strip('\n')
		grid.append(line)
	(a, b) = (grid[1][2], grid[2][1])
	(x, y) = (grid[n][n - 1], grid[n - 1][n])
	if a == b and x == y and (x != a):
		print(0)
		continue
	if x == a == b == y:
		print(2)
		print(1, 2)
		print(2, 1)
		continue
	ans = []
	if a != b:
		if x == y:
			if b != x:
				a = b
				ans.append((1, 2))
			else:
				b = a
				ans.append((2, 1))
		else:
			a = b
			ans.append((1, 2))
	if x == a:
		ans.append((n, n - 1))
	elif y == b:
		ans.append((n - 1, n))
	print(len(ans))
	for i in ans:
		print(*i)


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
from collections import *
ORDA = 97

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return [int(i) for i in input().split()]

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	new_number = 0
	while number > 0:
		new_number += number % base
		number //= base
	return new_number

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True

def main():
	for _ in range(int(input())):
		n = int(input())
		arr = [list(input()) for _ in range(n)]
		res = []
		if arr[n - 2][n - 1] == arr[n - 1][n - 2]:
			if arr[0][1] == arr[n - 2][n - 1]:
				res.append((1, 2))
			if arr[1][0] == arr[n - 2][n - 1]:
				res.append((2, 1))
		elif arr[0][1] == arr[1][0]:
			if arr[n - 2][n - 1] == arr[0][1]:
				res.append((n - 1, n))
			if arr[n - 1][n - 2] == arr[0][1]:
				res.append((n, n - 1))
		else:
			if arr[0][1] == '1':
				res.append((1, 2))
			if arr[1][0] == '1':
				res.append((2, 1))
			if arr[n - 2][n - 1] == '0':
				res.append((n - 1, n))
			if arr[n - 1][n - 2] == '0':
				res.append((n, n - 1))
		print(len(res))
		for e in res:
			print(*e)
main()


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, grid):
	vals = [(x, y, int(grid[x][y])) for (x, y) in [(0, 1), (1, 0), (N - 1, N - 2), (N - 2, N - 1)]]
	patterns = [[0, 0, 1, 1], [1, 1, 0, 0]]
	for pattern in patterns:
		flips = []
		for (p, (x, y, z)) in zip(pattern, vals):
			if p != z:
				flips.append(str(x + 1) + ' ' + str(y + 1))
		if len(flips) <= 2:
			return str(len(flips)) + '\n' + '\n'.join(flips)
	assert False
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = int(input())
for tc in range(1, TC + 1):
	(N,) = [int(x) for x in input().split()]
	grid = [list(input().decode().rstrip()) for i in range(N)]
	ans = solve(N, grid)
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	dim = int(input())
	a1 = None
	a2 = None
	a3 = None
	a4 = None
	if dim >= 4:
		a1 = int(input()[1])
		a2 = int(input()[0])
		for i in range(dim - 4):
			inp = input()
		a3 = int(input()[dim - 1])
		a4 = int(input()[dim - 2])
	elif dim == 3:
		a1 = int(input()[1])
		midInp = input()
		a2 = int(midInp[0])
		a3 = int(midInp[2])
		a4 = int(input()[1])
	L = []
	if a1 == a2:
		changeTo = 1 - a1
		if a3 != changeTo:
			L.append(3)
		if a4 != changeTo:
			L.append(4)
	elif a3 == a4:
		changeTo = 1 - a3
		if a1 != changeTo:
			L.append(1)
		else:
			L.append(2)
	else:
		L.append(1)
		if a3 != a1:
			L.append(3)
		else:
			L.append(4)
	print(len(L))
	for i in L:
		if i == 1:
			print('1 2')
		if i == 2:
			print('2 1')
		if i == 3:
			print(str(dim - 1) + ' ' + str(dim))
		if i == 4:
			print(str(dim) + ' ' + str(dim - 1))


import sys

def swap(x, y, a):
	temp = a[x]
	a[x] = a[y]
	a[y] = temp
	return a

def solve():
	return None

def main():
	q = []
	for line in sys.stdin.readlines():
		q.append(line)
	for i in range(len(q)):
		q[i] = q[i].rstrip().split(' ')
	i = 1
	while i < len(q):
		n = int(q[i][0])
		matrix = [q[i + j + 1][0] for j in range(n)]
		c = 0
		flag1 = 0
		flag2 = 0
		if matrix[0][1] == '0' and matrix[1][0] == '0':
			if matrix[n - 1][n - 2] == '0':
				flag1 = 1
				c += 1
			if matrix[n - 2][n - 1] == '0':
				flag2 = 1
				c += 1
			print(c)
			if flag1 == 1:
				print(n, n - 1)
			if flag2 == 1:
				print(n - 1, n)
		if matrix[0][1] == '1' and matrix[1][0] == '1':
			if matrix[n - 1][n - 2] == '1':
				flag1 = 1
				c += 1
			if matrix[n - 2][n - 1] == '1':
				flag2 = 1
				c += 1
			print(c)
			if flag1 == 1:
				print(n, n - 1)
			if flag2 == 1:
				print(n - 1, n)
		if matrix[0][1] == '1' and matrix[1][0] == '0':
			if matrix[n - 1][n - 2] == '0':
				flag1 = 1
				c += 1
			if matrix[n - 2][n - 1] == '0':
				flag2 = 1
				c += 1
			if c == 0:
				print(1)
				print(1, 2)
			elif c == 2:
				print(1)
				print(2, 1)
			else:
				print(2)
				print(1, 2)
				if flag1 == 1:
					print(n, n - 1)
				if flag2 == 1:
					print(n - 1, n)
		if matrix[0][1] == '0' and matrix[1][0] == '1':
			if matrix[n - 1][n - 2] == '0':
				flag1 = 1
				c += 1
			if matrix[n - 2][n - 1] == '0':
				flag2 = 1
				c += 1
			if c == 0:
				print(1)
				print(2, 1)
			elif c == 2:
				print(1)
				print(1, 2)
			else:
				print(2)
				print(2, 1)
				if flag1 == 1:
					print(n, n - 1)
				if flag2 == 1:
					print(n - 1, n)
		i += n + 1
main()


from collections import Counter as cnt, defaultdict as dic
iin = lambda : int(input())
lin = lambda : list(map(int, input().rstrip().split()))
TEST_CASES = True

def main():
	n = iin()
	mat = [input() for i in range(n)]
	if int(mat[1][0]) + int(mat[0][1]) == 0:
		if int(mat[n - 2][n - 1]) + int(mat[n - 1][n - 2]) == 0:
			print(2)
			print(n, n - 1)
			print(n - 1, n)
		elif int(mat[n - 2][n - 1]) + int(mat[n - 1][n - 2]) == 1:
			print(1)
			if int(mat[n - 1][n - 2]) == 0:
				print(n, n - 1)
			else:
				print(n - 1, n)
		else:
			print(0)
		return
	elif int(mat[1][0]) + int(mat[0][1]) == 2:
		if int(mat[n - 2][n - 1]) + int(mat[n - 1][n - 2]) == 0:
			print(0)
		elif int(mat[n - 2][n - 1]) + int(mat[n - 1][n - 2]) == 1:
			print(1)
			if int(mat[n - 1][n - 2]) == 1:
				print(n, n - 1)
			else:
				print(n - 1, n)
		else:
			print(2)
			print(n, n - 1)
			print(n - 1, n)
		return
	else:
		if int(mat[n - 1][n - 2]) + int(mat[n - 2][n - 1]) == 0:
			print(1)
			if mat[0][1] == '0':
				print(1, 2)
			else:
				print(2, 1)
		elif int(mat[n - 1][n - 2]) + int(mat[n - 2][n - 1]) == 2:
			print(1)
			if mat[0][1] == '1':
				print(1, 2)
			else:
				print(2, 1)
		else:
			majority = int(mat[n - 2][n - 2])
			print(2)
			if int(mat[n - 1][n - 2]) == majority:
				print(n - 1, n)
			else:
				print(n, n - 1)
			if int(mat[0][1]) == majority:
				print(1, 2)
			else:
				print(2, 1)
		return
if not TEST_CASES:
	main()
else:
	[main() for _ in range(int(input()))]


nn = int(input())
mm = []
for _ in range(nn):
	n = int(input())
	mm.append([])
	for _ in range(n):
		s = input()
		mm[-1].append(s)
for i in range(nn):
	m = mm[i]
	n = len(m)
	(a, b, c, d) = (int(m[0][1]), int(m[1][0]), int(m[-1][-2]), int(m[-2][-1]))
	if a == b == 0 and c == d == 1 or (a == b == 1 and c == d == 0):
		print(0)
	elif a == b == c == d == 0 or a == b == c == d == 1:
		print(2)
		print('1 2')
		print('2 1')
	elif a + b == 1 and c + d == 2:
		print(1)
		if a == 1:
			print('1 2')
		else:
			print('2 1')
	elif a + b == 1 and c + d == 0:
		print(1)
		if a == 0:
			print('1 2')
		else:
			print('2 1')
	elif a + b == 1 and c + d == 1:
		print(2)
		if a == 1:
			print('1 2')
		else:
			print('2 1')
		if c == 0:
			print('{} {}'.format(n, n - 1))
		else:
			print('{} {}'.format(n - 1, n))
	elif c + d == 1 and a + b == 2:
		print(1)
		if c == 1:
			print('{} {}'.format(n, n - 1))
		else:
			print('{} {}'.format(n - 1, n))
	elif c + d == 1 and a + b == 0:
		print(1)
		if c == 0:
			print('{} {}'.format(n, n - 1))
		else:
			print('{} {}'.format(n - 1, n))


for _ in range(int(input())):
	n = int(input())
	array = []
	for _ in range(n):
		array.append(list(input()))
	important = []
	important.append(int(array[0][1]))
	important.append(int(array[1][0]))
	important.append(int(array[n - 2][n - 1]))
	important.append(int(array[n - 1][n - 2]))
	count = important.count(0)
	if count == 0 or count == 4:
		print('2')
		print('1 2')
		print('2 1')
	elif count == 2:
		if important[0] == important[1]:
			print('0')
		else:
			print('2')
			if important[0] == 0:
				print('2 1')
			else:
				print('1 2')
			if important[2] == 1:
				print(str(n) + ' ' + str(n - 1))
			else:
				print(str(n - 1) + ' ' + str(n))
	elif count == 3:
		x = important.index(1)
		print('1')
		if x == 0:
			print('2 1')
		elif x == 1:
			print('1 2')
		elif x == 2:
			print(str(n) + ' ' + str(n - 1))
		else:
			print(str(n - 1) + ' ' + str(n))
	elif count == 1:
		x = important.index(0)
		print('1')
		if x == 0:
			print('2 1')
		elif x == 1:
			print('1 2')
		elif x == 2:
			print(str(n) + ' ' + str(n - 1))
		else:
			print(str(n - 1) + ' ' + str(n))


for _ in range(int(input())):
	n = int(input())
	grid = [[*input()] for _ in range(n)]
	sr = grid[0][1]
	sd = grid[1][0]
	fu = grid[-2][-1]
	fl = grid[-1][-2]
	if sr == sd == '0' and fu == fl == '1' or (sr == sd == '1' and fu == fl == '0'):
		print(0)
	elif sr == sd and fu != fl:
		print(1)
		if fu == sr:
			print(n - 1, n)
		else:
			print(n, n - 1)
	elif fu == fl and sr != sd:
		print(1)
		if sr == fu:
			print(1, 2)
		else:
			print(2, 1)
	elif sr == sd == fu == fl:
		print(2)
		print(1, 2)
		print(2, 1)
	elif sr != sd and fu != fl:
		print(2)
		if sr == '1':
			print(1, 2)
		else:
			print(2, 1)
		if fu == '0':
			print(n - 1, n)
		else:
			print(n, n - 1)


def solve():
	n = int(input())
	grid = []
	for _ in range(n):
		grid.append(input())
	g01 = grid[0][1]
	g10 = grid[1][0]
	g_12 = grid[n - 1][n - 2]
	g_21 = grid[n - 2][n - 1]
	if g01 == g10:
		if g_12 == g_21:
			if g01 == g_12:
				print('2')
				print('1 2')
				print('2 1')
			else:
				print('0')
		elif g01 == '0':
			if g_12 == '0':
				print('1')
				print(str(n) + ' ' + str(n - 1))
			else:
				print('1')
				print(str(n - 1) + ' ' + str(n))
		elif g_12 == '0':
			print('1')
			print(str(n - 1) + ' ' + str(n))
		else:
			print('1')
			print(str(n) + ' ' + str(n - 1))
	elif g_12 == g_21:
		if g_12 == '0':
			if g01 == '0':
				print('1')
				print('1 2')
			else:
				print('1')
				print('2 1')
		elif g01 == '1':
			print('1')
			print('1 2')
		else:
			print('1')
			print('2 1')
	else:
		print('2')
		if g01 == '0':
			print('2 1')
		else:
			print('1 2')
		if g_12 == '0':
			print(str(n) + ' ' + str(n - 1))
		else:
			print(str(n - 1) + ' ' + str(n))

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


import sys
import math

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	n = int(input())
	z = []
	for i in range(n):
		z.append(input())
	ans = []
	if z[0][1] == '0' and z[1][0] == '0':
		if z[n - 2][n - 1] == '0':
			ans.append(list([n - 2 + 1, n - 1 + 1]))
		if z[n - 1][n - 2] == '0':
			ans.append(list([n - 1 + 1, n - 2 + 1]))
	elif z[0][1] == '1' and z[1][0] == '1':
		if z[n - 2][n - 1] == '1':
			ans.append(list([n - 2 + 1, n - 1 + 1]))
		if z[n - 1][n - 2] == '1':
			ans.append(list([n - 1 + 1, n - 2 + 1]))
	elif z[0][1] == '1' and z[1][0] == '0':
		if z[n - 2][n - 1] == '0' and z[n - 1][n - 2] == '0':
			ans.append(list([2, 1]))
		elif z[n - 1][n - 2] == '1' and z[n - 2][n - 1] == '1':
			ans.append(list([1, 2]))
		elif z[n - 1][n - 2] == '1' and z[n - 2][n - 1] == '0':
			ans.append(list([1, 2]))
			ans.append(list([n - 2 + 1, n - 1 + 1]))
		elif z[n - 1][n - 2] == '0' and z[n - 2][n - 1] == '1':
			ans.append(list([2, 1]))
			ans.append(list([n - 2 + 1, n - 1 + 1]))
	elif z[0][1] == '0' and z[1][0] == '1':
		if z[n - 2][n - 1] == '0' and z[n - 1][n - 2] == '0':
			ans.append(list([1, 2]))
		elif z[n - 1][n - 2] == '1' and z[n - 2][n - 1] == '1':
			ans.append(list([2, 1]))
		elif z[n - 1][n - 2] == '1' and z[n - 2][n - 1] == '0':
			ans.append(list([2, 1]))
			ans.append(list([n - 2 + 1, n - 1 + 1]))
		elif z[n - 1][n - 2] == '0' and z[n - 2][n - 1] == '1':
			ans.append(list([1, 2]))
			ans.append(list([n - 2 + 1, n - 1 + 1]))
	if len(ans) == 0:
		print(0)
	else:
		print(len(ans))
		for i in range(len(ans)):
			print(*ans[i])


tt = int(input())
for _ in range(tt):
	n = int(input())
	s = []
	for i in range(n):
		s += [input()]
	a = (s[0][1], (1, 2))
	b = (s[1][0], (2, 1))
	c = (s[n - 2][n - 1], (n - 1, n))
	d = (s[n - 1][n - 2], (n, n - 1))
	A = [a, b]
	B = [c, d]
	res = []
	if A[0][0] != A[1][0] and B[0][0] != B[1][0]:
		if A[0][0] == '0':
			res += [A[0][1]]
		else:
			res += [A[1][1]]
		if B[0][0] == '1':
			res += [B[0][1]]
		else:
			res += [B[1][1]]
	elif A[0][0] == A[1][0]:
		if B[0][0] == A[0][0]:
			res += [B[0][1]]
		if B[1][0] == A[0][0]:
			res += [B[1][1]]
	elif B[0][0] == B[1][0]:
		if A[0][0] == B[0][0]:
			res += [A[0][1]]
		if A[1][0] == B[0][0]:
			res += [A[1][1]]
	print(len(res))
	for (x, y) in res:
		print(x, y)


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	n = int(input())
	s = [list(input()) for _ in range(n)]
	start = [s[0][1], s[1][0]]
	goal = [s[n - 1][n - 2], s[n - 2][n - 1]]
	ans = []
	if goal[0] == goal[1]:
		memo = goal[0]
		if start[0] == memo:
			ans.append([1, 2])
		if start[1] == memo:
			ans.append([2, 1])
	else:
		memo = start[0]
		if start[1] != memo:
			ans.append([2, 1])
		if goal[0] == memo:
			ans.append([n, n - 1])
		if goal[1] == memo:
			ans.append([n - 1, n])
	print(len(ans))
	for j in ans:
		print(j[0], j[1])


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi, inf
from collections import deque, defaultdict
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(str(x) + '\n')
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 6 + 6
for _ in range(I()):
	n = I()
	a = [S() for i in range(n)]
	cnt = 0
	ans = []
	if a[0][1] != '0':
		cnt += 1
		ans += ((1, 2),)
	if a[1][0] != '0':
		cnt += 1
		ans += ((2, 1),)
	if a[-1][-2] != '1':
		cnt += 1
		ans += ((n, n - 1),)
	if a[-2][-1] != '1':
		cnt += 1
		ans += ((n - 1, n),)
	if cnt <= 2:
		print(cnt)
		for i in ans:
			print(*i)
		continue
	cnt = 0
	ans = []
	if a[0][1] != '1':
		cnt += 1
		ans += ((1, 2),)
	if a[1][0] != '1':
		cnt += 1
		ans += ((2, 1),)
	if a[-1][-2] != '0':
		cnt += 1
		ans += ((n, n - 1),)
	if a[-2][-1] != '0':
		cnt += 1
		ans += ((n - 1, n),)
	print(cnt)
	for i in ans:
		print(*i)


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	l = []
	for i in range(n):
		s = input()
		l.append(s)
	a1 = int(l[0][1])
	a2 = int(l[1][0])
	b1 = int(l[n - 1][n - 2])
	b2 = int(l[n - 2][n - 1])
	x = [a1, a2, b1, b2]
	d = Counter(x)
	if len(set(x)) == 1:
		print(2)
		print(1, 2)
		print(2, 1)
	elif len(set([a1, a2])) == 1 and len(set([b1, b2])) == 1:
		print(0)
	elif len(set([a1, a2])) == 2 and len(set([b1, b2])) == 1:
		if a1 == b1:
			print(1)
			print(1, 2)
		elif a2 == b1:
			print(1)
			print(2, 1)
	elif len(set([a1, a2])) == 1 and len(set([b1, b2])) == 2:
		if b1 == a1:
			print(1)
			print(n, n - 1)
		elif b2 == a1:
			print(1)
			print(n - 1, n)
	elif len(set([a1, a2])) == 2 and len(set([b1, b2])) == 2:
		if a1 == b1:
			print(2)
			print(1, 2)
			print(n - 1, n)
		else:
			print(2)
			print(1, 2)
			print(n, n - 1)


for _ in range(int(input())):
	n = int(input())
	m = [input() for _ in range(n)]
	p = [[1, 2], [2, 1], [n - 1, n], [n, n - 1]]
	w = ['0011', '1100']
	for u in w:
		c = []
		for i in range(4):
			(x, y) = (p[i][0], p[i][1])
			if m[x - 1][y - 1] != u[i]:
				c.append((x, y))
		if len(c) <= 2:
			print(len(c))
			for e in c:
				print(*e)
			break


import sys
from collections import deque
from itertools import product
from copy import deepcopy
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7

def resolve():

	def bfs(num):
		que = deque([[0, 0]])
		visited = [[False] * n for _ in range(n)]
		visited[0][0] = True
		while que:
			(h, w) = que.popleft()
			for (dh, dw) in ((1, 0), (-1, 0), (0, 1), (0, -1)):
				(next_h, next_w) = (h + dh, w + dw)
				if next_h < 0 or next_h >= n or next_w < 0 or (next_w >= n):
					continue
				if visited[next_h][next_w]:
					continue
				elif S[next_h][next_w] == num or S[next_h][next_w] == 'F':
					visited[next_h][next_w] = True
					que.append([next_h, next_w])
		return visited[-1][-1]
	t = int(input())
	for j in range(t):
		n = int(input())
		S_init = [list(input().rstrip()) for _ in range(n)]
		target = [(0, 1), (1, 0), (n - 2, n - 1), (n - 1, n - 2)]
		flg = False
		for pattern in product([0, 1], repeat=4):
			if flg:
				break
			if sum(pattern) > 2:
				continue
			S = deepcopy(S_init)
			res = []
			for (idx, p) in enumerate(pattern):
				if p == 1:
					(y, x) = target[idx]
					S[y][x] = '0' if S[y][x] == '1' else '1'
					res.append([y + 1, x + 1])
			if not bfs('0') and (not bfs('1')):
				print(len(res))
				for i in res:
					print(*i)
				flg = True
resolve()


import math
import sys
import collections
import bisect
input = sys.stdin.readline
flush = sys.stdout.flush
readint = lambda : int(input())
readintm = lambda : map(int, input().strip().split())
readintl = lambda : list(map(int, input().strip().split()))
readfloatm = lambda : map(float, input().strip().split())
readfloatl = lambda : list(map(float, input().strip().split()))
readstr = lambda : input().strip()
readstrl = lambda : list(input().strip())
join = lambda x, l: x.join(map(str, l))
print = lambda *x: sys.stdout.write(' '.join(map(str, x)) + '\n')
printl = lambda l: sys.stdout.write(' '.join(map(str, l)) + '\n')
ceil = lambda x, y: (x + y - 1) // y
mod = 1000000007
for _ in range(readint()):
	n = readint()
	board = [readstrl() for i in range(n)]
	(a, b) = (board[1][0], board[0][1])
	(x, y) = (board[-1][-2], board[-2][-1])
	c = 0
	out = []
	if a == b:
		if x == a:
			c += 1
			out.append(f'{n} {n - 1}')
		if y == a:
			c += 1
			out.append(f'{n - 1} {n}')
		print(c)
	elif x == y:
		if a == x:
			out.append('2 1')
		else:
			out.append('1 2')
		print(1)
	else:
		if a == '1':
			out.append('2 1')
		elif b == '1':
			out.append('1 2')
		if x == '0':
			out.append(f'{n} {n - 1}')
		elif y == '0':
			out.append(f'{n - 1} {n}')
		print(2)
	for point in out:
		print(point)


def find(arr, N):
	R = []
	if arr[N - 1][N - 2] == arr[N - 2][N - 1]:
		a = arr[N - 1][N - 2]
		if arr[1][0] == a:
			R.append((2, 1))
		if arr[0][1] == a:
			R.append((1, 2))
	elif arr[1][0] == arr[0][1]:
		a = arr[1][0]
		if arr[N - 1][N - 2] == a:
			R.append((N, N - 1))
		if arr[N - 2][N - 1] == a:
			R.append((N - 1, N))
	else:
		R.append((N, N - 1))
		a = arr[N - 1][N - 2]
		if arr[1][0] != a:
			R.append((2, 1))
		else:
			R.append((1, 2))
	print(len(R))
	for (x, y) in R:
		print(x, y)

def main():
	for _ in range(int(input())):
		N = int(input())
		arr = [input().strip() for _ in range(N)]
		find(arr, N)
main()


for t in range(int(input())):
	n = int(input())
	mat = []
	for i in range(n):
		mat.append(list(input()))
	out = 0
	ans = []
	if mat[0][1] == mat[1][0]:
		if mat[-1][-2] == mat[0][1]:
			out += 1
			ans.append([n, n - 1])
		if mat[n - 2][n - 1] == mat[0][1]:
			out += 1
			ans.append([n - 1, n])
	elif mat[n - 1][n - 2] == mat[n - 2][n - 1]:
		if mat[0][1] == mat[n - 1][n - 2]:
			ans.append([1, 2])
			out += 1
		if mat[1][0] == mat[n - 1][n - 2]:
			ans.append([2, 1])
			out += 1
	else:
		out = 2
		ans.append([1, 2])
		if mat[0][1] == mat[n - 1][n - 2]:
			ans.append([n - 1, n])
		else:
			ans.append([n, n - 1])
	print(out)
	for i in ans:
		print(*i)


import os
import sys
from io import BytesIO, IOBase
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def main():
	try:
		for _ in range(inp()):
			n = int(input())
			arr = []
			for i in range(n):
				arr.append(input())
			x1 = int(arr[1][0])
			y1 = int(arr[0][1])
			(x2, y2) = (int(arr[n - 1][n - 2]), int(arr[n - 2][n - 1]))
			if x1 == x2 == y1 == y2:
				print('2')
				print('1 2')
				print('2 1')
			elif x1 == (not x2) and y1 == (not y2) and (x1 == y1):
				print('0')
			elif x1 == y1 and x2 != y2:
				print('1')
				if x2 == x1:
					print(n, n - 1)
				else:
					print(n - 1, n)
			elif x2 == y2 and x1 != y1:
				print('1')
				if x2 == x1:
					print('2 1')
				else:
					print('1 2')
			elif x1 != y1 and x2 != y2:
				print('2')
				if y1 != x2:
					print('1 2')
					print(n, n - 1)
				else:
					print('2 1')
					print(n, n - 1)
	except Exception as e:
		print(e)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for _ in range(t):
	n = int(input())
	arr = []
	for i in range(n):
		arr += [input()]
	(a, b) = (int(arr[0][1]), int(arr[1][0]))
	(x, y) = (int(arr[-1][-2]), int(arr[-2][-1]))
	ans = []
	if x == 0 and y == 0:
		if a == 0:
			ans += [[1, 2]]
		if b == 0:
			ans += [[2, 1]]
	elif x == 1 and y == 1:
		if a == 1:
			ans += [[1, 2]]
		if b == 1:
			ans += [[2, 1]]
	elif a == 0 and b == 0:
		if x == 0:
			ans += [[n, n - 1]]
		if y == 0:
			ans += [[n - 1, n]]
	elif a == 1 and b == 1:
		if x == 1:
			ans += [[n, n - 1]]
		if y == 1:
			ans += [[n - 1, n]]
	else:
		if a == 0:
			ans += [[2, 1]]
		else:
			ans += [[1, 2]]
		if x == 0:
			ans += [[n, n - 1]]
		if y == 0:
			ans += [[n - 1, n]]
	print(len(ans))
	for x in ans:
		print(*x)


import sys
input = lambda : sys.stdin.readline().rstrip()
t = int(input())
g = []
for i in range(t):
	a = int(input())
	x = []
	for j in range(a):
		b = list(input())
		x.append(b)
	g.append(x)
ans = []
for i in range(t):
	v = len(g[i])
	x1 = g[i][0][1]
	x2 = g[i][1][0]
	y1 = g[i][v - 2][v - 1]
	y2 = g[i][v - 1][v - 2]
	if x1 == '1' and x2 == '1':
		if y1 == '1' and y2 == '1':
			ans.append([2, [v - 1, v], [v, v - 1]])
		elif y1 == '1' and y2 == '0':
			ans.append([1, [v - 1, v]])
		elif y1 == '0' and y2 == '1':
			ans.append([1, [v, v - 1]])
		else:
			ans.append(0)
	elif x1 == '1' and x2 == '0':
		if y1 == '1' and y2 == '1':
			ans.append([1, [1, 2]])
		elif y1 == '1' and y2 == '0':
			ans.append([2, [2, 1], [v - 1, v]])
		elif y1 == '0' and y2 == '1':
			ans.append([2, [2, 1], [v, v - 1]])
		else:
			ans.append([1, [2, 1]])
	elif x1 == '0' and x2 == '1':
		if y1 == '1' and y2 == '1':
			ans.append([1, [2, 1]])
		elif y1 == '1' and y2 == '0':
			ans.append([2, [1, 2], [v - 1, v]])
		elif y1 == '0' and y2 == '1':
			ans.append([2, [1, 2], [v, v - 1]])
		else:
			ans.append([1, [1, 2]])
	elif y1 == '1' and y2 == '1':
		ans.append(0)
	elif y1 == '1' and y2 == '0':
		ans.append([1, [v, v - 1]])
	elif y1 == '0' and y2 == '1':
		ans.append([1, [v - 1, v]])
	else:
		ans.append([2, [1, 2], [2, 1]])
for i in range(t):
	if ans[i] != 0:
		x = ans[i][0]
		print(x)
		for j in range(x):
			print(*ans[i][j + 1])
	else:
		print(0)


t = int(input())
for _ in range(t):
	n = int(input())
	l = []
	for i in range(n):
		l.append(input())
	(x1, x2) = (l[0][1], l[1][0])
	(y1, y2) = (l[-2][-1], l[-1][-2])
	x = []
	if x1 == x2:
		if y1 != str(1 - int(x1)):
			x.append([n - 1, n])
		if y2 != str(1 - int(x1)):
			x.append([n, n - 1])
	elif y1 == y2:
		if x1 != str(1 - int(y1)):
			x.append([1, 2])
		if x2 != str(1 - int(y1)):
			x.append([2, 1])
	else:
		if x1 != '1':
			x.append([1, 2])
		else:
			x.append([2, 1])
		if y1 != '0':
			x.append([n - 1, n])
		else:
			x.append([n, n - 1])
	print(len(x))
	for i in x:
		print(*i)


t = int(input())
for _ in range(t):
	n = int(input())
	matrix = list()
	for i in range(n):
		a = list(input())
		matrix.append(a)
	switch = list()
	count = 0
	if matrix[0][1] == matrix[1][0]:
		common = matrix[0][1]
		if matrix[n - 1][n - 2] == common:
			switch.append(str(n) + ' ' + str(n - 1))
			count += 1
		if matrix[n - 2][n - 1] == common:
			switch.append(str(n - 1) + ' ' + str(n))
			count += 1
	elif matrix[n - 1][n - 2] == matrix[n - 2][n - 1]:
		common = matrix[n - 1][n - 2]
		if matrix[1][0] == common:
			switch.append(str(2) + ' ' + str(1))
			count += 1
		if matrix[0][1] == common:
			switch.append(str(1) + ' ' + str(2))
			count += 1
	else:
		if matrix[0][1] != '0':
			switch.append(str(1) + ' ' + str(2))
			count += 1
		if matrix[1][0] != '0':
			switch.append(str(2) + ' ' + str(1))
			count += 1
		if matrix[n - 1][n - 2] != '1':
			switch.append(str(n) + ' ' + str(n - 1))
			count += 1
		if matrix[n - 2][n - 1] != '1':
			switch.append(str(n - 1) + ' ' + str(n))
			count += 1
	print(count)
	print(*switch, sep='\n')


for _ in range(int(input())):
	n = int(input())
	s = [input() for i in range(n)]
	f1 = [int(s[0][1]), int(s[1][0])]
	f2 = [int(s[-1][-2]), int(s[-2][-1])]
	ans = []
	if f1 == [0, 0]:
		if f2[0] == 0:
			ans.append([n, n - 1])
		if f2[1] == 0:
			ans.append([n - 1, n])
	elif f1 == [1, 1]:
		if f2[0] == 1:
			ans.append([n, n - 1])
		if f2[1] == 1:
			ans.append([n - 1, n])
	elif f2 == [0, 0]:
		if f1[0] == 0:
			ans.append([1, 2])
		if f1[1] == 0:
			ans.append([2, 1])
	elif f2 == [1, 1]:
		if f1[0] == 1:
			ans.append([1, 2])
		if f1[1] == 1:
			ans.append([2, 1])
	elif f1 == [0, 1] or f1 == [1, 0]:
		if f1 == [0, 1]:
			ans.append([2, 1])
		else:
			ans.append([1, 2])
		if f2[0] == 0:
			ans.append([n, n - 1])
		if f2[1] == 0:
			ans.append([n - 1, n])
	print(len(ans))
	for i in range(len(ans)):
		print(ans[i][0], ans[i][1])


t = int(input(''))
for _ in range(t):
	ans = []
	n = int(input(''))
	for j in range(n):
		ans.append(list(input('')))
	x = ans[0][1]
	y = ans[1][0]
	z = ans[n - 1][n - 2]
	a = ans[n - 2][n - 1]
	if x == y:
		if z == x:
			if x == a:
				print(2)
				print(1, 2)
				print(2, 1)
			else:
				print(1)
				print(n, n - 1)
		elif x == a:
			print(1)
			print(n - 1, n)
		else:
			print(0)
		continue
	if z == a:
		if x == y:
			if x == z:
				print(2)
				print(1, 2)
				print(2, 1)
			else:
				print(0)
		elif x == z:
			print(1)
			print(1, 2)
		else:
			print(1)
			print(2, 1)
		continue
	if x == z:
		print(2)
		print(1, 2)
		print(n - 1, n)
	else:
		print(2)
		print(1, 2)
		print(n, n - 1)


def main(input_f):
	t = int(input_f())
	for _ in range(t):
		n = int(input_f())
		cells = [list(input_f()) for _ in range(n)]
		(start_right, start_bottom) = (cells[0][1], cells[1][0])
		(finish_left, finish_top) = (cells[n - 1][n - 2], cells[n - 2][n - 1])
		inverted_cells = []
		if start_right == start_bottom:
			if finish_left == start_right:
				inverted_cells.append((n - 1, n - 2))
			if finish_top == start_right:
				inverted_cells.append((n - 2, n - 1))
		elif finish_left == finish_top:
			if start_right == finish_left:
				inverted_cells.append((0, 1))
			if start_bottom == finish_left:
				inverted_cells.append((1, 0))
		else:
			if start_right != '0':
				inverted_cells.append((0, 1))
			if start_bottom != '0':
				inverted_cells.append((1, 0))
			if finish_left != '1':
				inverted_cells.append((n - 1, n - 2))
			if finish_top != '1':
				inverted_cells.append((n - 2, n - 1))
		print(len(inverted_cells))
		for (x, y) in inverted_cells:
			print(x + 1, y + 1)
main(input)


from sys import stdin, stdout
n = int(stdin.readline())
for i in range(n):
	ans = []
	k = int(stdin.readline())
	for j in range(k):
		s = stdin.readline()
		if j == 0:
			top = s[1]
		if j == 1:
			left = s[0]
		if j == k - 2:
			right = s[-2]
		if j == k - 1:
			down = s[-3]
	if top == left and down == right and (top == right):
		cng = 2
		ans = [[1, 2], [2, 1]]
	if top == left and down == right and (top != right):
		cng = 0
	if top != left and down != right:
		cng = 2
		if top == down:
			ans = [[1, 2], [k - 1, k]]
		if top == right:
			ans = [[1, 2], [k, k - 1]]
	if top == left and down != right:
		cng = 1
		if left == right:
			ans = [[k - 1, k]]
		else:
			ans = [[k, k - 1]]
	if top != left and down == right:
		cng = 1
		if right == left:
			ans = [[2, 1]]
		else:
			ans = [[1, 2]]
	stdout.write(str(cng) + '\n')
	for q in ans:
		stdout.write(str(q[0]) + ' ' + str(q[1]) + '\n')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))
for _ in range(N()):
	n = N()
	g = []
	for _ in range(n):
		g.append(input().strip())
	s = int(g[0][1] + g[1][0], base=2)
	e = int(g[-1][-2] + g[-2][-1], base=2)
	if s == 3:
		if e == 3:
			print(2)
			print(n, n - 1)
			print(n - 1, n)
		if e == 0:
			print(0)
		if e == 1:
			print(1)
			print(n - 1, n)
		if e == 2:
			print(1)
			print(n, n - 1)
	elif s == 0:
		if e == 0:
			print(2)
			print(n, n - 1)
			print(n - 1, n)
		if e == 3:
			print(0)
		if e == 1:
			print(1)
			print(n, n - 1)
		if e == 2:
			print(1)
			print(n - 1, n)
	elif s == 1:
		if e == 0:
			print(1)
			print(1, 2)
		if e == 1:
			print(2)
			print(1, 2)
			print(n - 1, n)
		if e == 2:
			print(2)
			print(1, 2)
			print(n, n - 1)
		if e == 3:
			print(1)
			print(2, 1)
	elif s == 2:
		if e == 0:
			print(1)
			print(2, 1)
		if e == 1:
			print(2)
			print(2, 1)
			print(n - 1, n)
		if e == 2:
			print(2)
			print(2, 1)
			print(n, n - 1)
		if e == 3:
			print(1)
			print(1, 2)


t = int(input())
ans = []
for u in range(t):
	n = int(input())
	way = []
	key = ['0', '1']
	for i in range(n):
		way.append(input())
	if way[0][1] == way[1][0]:
		if way[n - 1][n - 2] == way[n - 2][n - 1]:
			if way[n - 1][n - 2] == way[0][1]:
				ans.append(2)
				ans.append(str(n) + ' ' + str(n - 1))
				ans.append(str(n - 1) + ' ' + str(n))
			else:
				ans.append(0)
		elif way[n - 1][n - 2] == way[0][1]:
			ans.append(1)
			ans.append(str(n) + ' ' + str(n - 1))
		else:
			ans.append(1)
			ans.append(str(n - 1) + ' ' + str(n))
	elif way[n - 1][n - 2] == way[n - 2][n - 1]:
		if way[n - 1][n - 2] == way[0][1]:
			ans.append(1)
			ans.append(str(1) + ' ' + str(2))
		else:
			ans.append(1)
			ans.append(str(2) + ' ' + str(1))
	elif way[1][0] == way[n - 1][n - 2]:
		ans.append(2)
		ans.append(str(1) + ' ' + str(2))
		ans.append(str(n) + ' ' + str(n - 1))
	else:
		ans.append(2)
		ans.append(str(2) + ' ' + str(1))
		ans.append(str(n) + ' ' + str(n - 1))
for a in ans:
	print(a)


test_count = int(input())
tests = []
for _ in range(test_count):
	x = int(input())
	y = []
	for _ in range(x):
		y.append(list(input()))
	tests.append((x, y))
for test in tests:
	(size, grid) = test
	start_right = int(grid[0][1])
	start_down = int(grid[1][0])
	end_up = int(grid[size - 2][size - 1])
	end_left = int(grid[size - 1][size - 2])
	x = (start_right, start_down, end_up, end_left)
	if x == (0, 0, 0, 0):
		print(2)
		print(size - 1, size)
		print(size, size - 1)
	elif x == (0, 0, 0, 1):
		print(1)
		print(size - 1, size)
	elif x == (0, 0, 1, 0):
		print(1)
		print(size, size - 1)
	elif x == (0, 0, 1, 1):
		print(0)
	elif x == (0, 1, 0, 0):
		print(1)
		print(1, 2)
	elif x == (0, 1, 0, 1):
		print(2)
		print(1, 2)
		print(size, size - 1)
	elif x == (0, 1, 1, 0):
		print(2)
		print(1, 2)
		print(size - 1, size)
	elif x == (0, 1, 1, 1):
		print(1)
		print(2, 1)
	elif x == (1, 0, 0, 0):
		print(1)
		print(2, 1)
	elif x == (1, 0, 0, 1):
		print(2)
		print(1, 2)
		print(size - 1, size)
	elif x == (1, 0, 1, 0):
		print(2)
		print(1, 2)
		print(size, size - 1)
	elif x == (1, 0, 1, 1):
		print(1)
		print(1, 2)
	elif x == (1, 1, 0, 0):
		print(0)
	elif x == (1, 1, 0, 1):
		print(1)
		print(size, size - 1)
	elif x == (1, 1, 1, 0):
		print(1)
		print(size - 1, size)
	elif x == (1, 1, 1, 1):
		print(2)
		print(size - 1, size)
		print(size, size - 1)


def one_indexed(pair):
	return [item + 1 for item in pair]
t = int(input())
for i in range(t):
	n = int(input())
	grid = [[int(i) if i != 'S' and i != 'F' else i for i in list(input())] for j in range(n)]
	doors = [(0, 1), (1, 0), (n - 2, n - 1), (n - 1, n - 2)]
	door_vals = [grid[i][j] for (i, j) in doors]
	(sr, sd, fu, fl) = door_vals
	if sr == sd and fu == fl and (sr != fu):
		print(0)
	else:
		if door_vals.count(0) == 1:
			diff_ind = door_vals.index(0)
		elif door_vals.count(1) == 1:
			diff_ind = door_vals.index(1)
		else:
			diff_ind = None
		if not diff_ind is None:
			print(1)
			get_other = {0: 1, 1: 0, 2: 3, 3: 2}
			change_ind = get_other[diff_ind]
			change = doors[change_ind]
			print(*one_indexed(change))
		else:
			print(2)
			if len(set(door_vals)) == 1:
				for coords in [doors[0], doors[1]]:
					print(*one_indexed(coords))
			elif sr in (fu, fl) and sd in (fu, fl) and (fu != fl):
				changes = [doors[i] for i in range(4) if i <= 1 and door_vals[i] == 0 or (i >= 2 and door_vals[i] == 1)]
				for coords in changes:
					print(*one_indexed(coords))


for _ in range(int(input())):
	n = int(input())
	a = [input() for _ in range(n)]
	for color in range(2):
		result = []
		if int(a[0][1]) != color:
			result.append((0, 1))
		if int(a[1][0]) != color:
			result.append((1, 0))
		if int(a[n - 1][n - 2]) == color:
			result.append((n - 1, n - 2))
		if int(a[n - 2][n - 1]) == color:
			result.append((n - 2, n - 1))
		if len(result) < 3:
			print(len(result))
			for (x, y) in result:
				print(x + 1, y + 1)
			break


from sys import stdin
input = stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = [list(input().rstrip()) for _ in range(n)]
	ans = []
	if a[0][1] == a[1][0]:
		if a[-1][-2] == a[0][1]:
			ans.append((n, n - 1))
		if a[-2][-1] == a[0][1]:
			ans.append((n - 1, n))
	elif a[-1][-2] == a[-2][-1]:
		if a[0][1] == a[-1][-2]:
			ans.append((1, 2))
		if a[1][0] == a[-1][-2]:
			ans.append((2, 1))
	else:
		if a[0][1] == '1':
			ans.append((1, 2))
		if a[1][0] == '1':
			ans.append((2, 1))
		if a[-1][-2] == '0':
			ans.append((n, n - 1))
		if a[-2][-1] == '0':
			ans.append((n - 1, n))
	print(len(ans))
	for i in ans:
		print(*i)


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
sys.setrecursionlimit(10 ** 6)
I = sys.stdin.readline

def ii():
	return int(I().strip())

def li():
	return list(map(int, I().strip().split()))

def mi():
	return map(int, I().strip().split())

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def valid(row, col, rows, cols, rcross, lcross):
	return rows[row] == 0 and cols[col] == 0 and (rcross[col + row] == 0) and (lcross[col - row] == 0)

def main():
	ans = ''
	for _ in range(ii()):
		n = ii()
		grid = []
		for i in range(n):
			grid.append(I().strip())
		if grid[0][1] == grid[1][0]:
			if grid[-1][-2] == grid[-2][-1]:
				if grid[0][1] == grid[-1][-2]:
					print(2)
					print(n - 1, len(grid[0]))
					print(n, len(grid[0]) - 1)
				else:
					print(0)
			elif grid[-1][-2] == grid[0][1]:
				print(1)
				print(n, len(grid[0]) - 1)
			else:
				print(1)
				print(n - 1, len(grid[0]))
		elif grid[-1][-2] != grid[-2][-1]:
			if grid[0][1] == '1':
				print(2)
				print(1, 2)
				if grid[-1][-2] == '0':
					print(n, len(grid[0]) - 1)
				else:
					print(n - 1, len(grid[0]))
			else:
				print(2)
				print(1, 2)
				if grid[-1][-2] == '1':
					print(n, len(grid[0]) - 1)
				else:
					print(n - 1, len(grid[0]))
		elif grid[0][1] == grid[-1][-2]:
			print(1)
			print(1, 2)
		else:
			print(1)
			print(2, 1)
main()


def i():
	return int(input())

def mp():
	return map(str, input().split())

def si():
	return input()
from collections import defaultdict as dd, deque as dq, Counter as c
from math import factorial as f, ceil, gcd, sqrt
for _ in range(i()):
	a = i()
	b = []
	for _ in range(a):
		b.append(list(input()))
	t = b[0][1]
	r = b[1][0]
	y = b[a - 1][a - 2]
	u = b[a - 2][a - 1]
	ans = []
	if t == r:
		if y == t:
			ans.append([a, a - 1])
		if u == t:
			ans.append([a - 1, a])
		print(len(ans))
		for k in range(len(ans)):
			print(*ans[k])
	elif y == u:
		if t == y:
			ans.append([1, 2])
		if r == y:
			ans.append([2, 1])
		print(len(ans))
		for k in range(len(ans)):
			print(*ans[k])
	else:
		ans.append([2, 1])
		if y == t:
			ans.append([a, a - 1])
		if u == t:
			ans.append([a - 1, a])
		print(len(ans))
		for k in range(len(ans)):
			print(*ans[k])


for _ in range(int(input())):
	n = int(input())
	mat = []
	for i in range(n):
		temp = input()
		temp = list(temp)
		mat.append(temp)
	a = int(mat[0][1])
	b = int(mat[1][0])
	x = int(mat[n - 1][n - 2])
	y = int(mat[n - 2][n - 1])
	if a == b == 0 and x == y == 1 or (a == b == 1 and x == y == 0):
		print(0)
	elif a == b == 0 and x == 0 and (y == 1):
		print(1)
		print(n, n - 1)
	elif a == b == 0 and x == 1 and (y == 0):
		print(1)
		print(n - 1, n)
	elif a == b == 0 and x == 0 and (y == 0):
		print(2)
		print(n, n - 1)
		print(n - 1, n)
	elif a == 1 and b == 0 and (x == 0) and (y == 0):
		print(1)
		print(2, 1)
	elif a == 1 and b == 0 and (x == 1) and (y == 0):
		print(2)
		print(2, 1)
		print(n, n - 1)
	elif a == 1 and b == 0 and (x == 0) and (y == 1):
		print(2)
		print(2, 1)
		print(n - 1, n)
	elif a == 1 and b == 0 and (x == 1) and (y == 1):
		print(1)
		print(1, 2)
	elif a == 0 and b == 1 and (x == 0) and (y == 0):
		print(1)
		print(1, 2)
	elif a == 0 and b == 1 and (x == 1) and (y == 0):
		print(2)
		print(2, 1)
		print(n - 1, n)
	elif a == 0 and b == 1 and (x == 0) and (y == 1):
		print(2)
		print(2, 1)
		print(n, n - 1)
	elif a == 0 and b == 1 and (x == 1) and (y == 1):
		print(1)
		print(2, 1)
	elif a == 1 and b == 1 and (x == 1) and (y == 0):
		print(1)
		print(n, n - 1)
	elif a == 1 and b == 1 and (x == 0) and (y == 1):
		print(1)
		print(n - 1, n)
	elif a == 1 and b == 1 and (x == 1) and (y == 1):
		print(2)
		print(1, 2)
		print(2, 1)


from collections import *
from functools import *
import math
import sys
inp = sys.stdin.readline
out = sys.stdout.write

def mi():
	return map(int, inp().split())

def li():
	return list(mi())

def ii():
	return int(inp())

def main():
	for _ in range(ii()):
		n = ii()
		grid = []
		for _ in range(n):
			grid.append(input())
		ans = []
		ans1 = []
		a = grid[0][1]
		b = grid[1][0]
		c = grid[-1][-2]
		d = grid[-2][-1]
		if a != '0':
			ans.append([1, 2])
		if b != '0':
			ans.append([2, 1])
		if c != '1':
			ans.append([n, n - 1])
		if d != '1':
			ans.append([n - 1, n])
		if a != '1':
			ans1.append([1, 2])
		if b != '1':
			ans1.append([2, 1])
		if c != '0':
			ans1.append([n, n - 1])
		if d != '0':
			ans1.append([n - 1, n])
		if len(ans) <= len(ans1):
			print(len(ans))
			for i in ans:
				print(*i)
		else:
			print(len(ans1))
			for i in ans1:
				print(*i)
main()


import re
import sys
exit = sys.exit
from bisect import bisect_left as bsl, bisect_right as bsr
from collections import Counter, defaultdict as ddict, deque
from functools import lru_cache
cache = lru_cache(None)
from heapq import *
from itertools import *
from math import inf
from pprint import pprint as pp
enum = enumerate
ri = lambda : int(rln())
ris = lambda : list(map(int, rfs()))
rln = sys.stdin.readline
rl = lambda : rln().rstrip('\n')
rfs = lambda : rln().split()
mod = 1000000007
d4 = [(0, -1), (1, 0), (0, 1), (-1, 0)]
d8 = [(-1, -1), (0, -1), (1, -1), (-1, 0), (1, 0), (-1, 1), (0, 1), (1, 1)]
t = ri()
for _ in range(t):
	n = ri()
	grid = [rl() for _ in range(n)]
	pos = [(0, 1), (1, 0), (n - 2, n - 1), (n - 1, n - 2)]
	have = ''.join((grid[r][c] for (r, c) in pos))
	for want in ('0011', '1100'):
		ans = []
		for (rc, x, y) in zip(pos, have, want):
			if x != y:
				ans.append(rc)
		if len(ans) <= 2:
			print(len(ans))
			for (r, c) in ans:
				print(r + 1, c + 1)
			break


for _ in range(int(input())):
	n = int(input())
	mat = []
	for i in range(n):
		mat.append(list(input()))
	ans = []
	if mat[0][1] == mat[1][0]:
		v = int(mat[0][1])
		if int(mat[n - 1][n - 2]) != abs(v - 1):
			ans.append([n, n - 1])
		if int(mat[n - 2][n - 1]) != abs(v - 1):
			ans.append([n - 1, n])
	elif int(mat[n - 2][n - 1]) == int(mat[n - 1][n - 2]):
		v = int(mat[n - 2][n - 1])
		if int(mat[0][1]) != abs(v - 1):
			ans.append([1, 2])
		if int(mat[1][0]) != abs(v - 1):
			ans.append([2, 1])
	else:
		if mat[0][1] == '1':
			ans.append([1, 2])
		else:
			ans.append([2, 1])
		if mat[n - 1][n - 2] == '0':
			ans.append([n, n - 1])
		else:
			ans.append([n - 1, n])
	print(len(ans))
	for i in ans:
		print(i[0], i[1])


t = int(input())
for _ in range(t):
	n = int(input())
	m = []
	for _ in range(n):
		m.append(input())
	(a, b, c, d) = (m[1][0], m[0][1], m[-1][-2], m[-2][-1])
	t = 8 * int(a) + 4 * int(b) + 2 * int(c) + 1 * int(d)
	a2 = 0
	if t in [0, 15]:
		a2 = [(1, 2), (2, 1)]
	elif t in [1, 14]:
		a2 = [(n, n - 1)]
	elif t in [2, 13]:
		a2 = [(n - 1, n)]
	elif t in [3, 12]:
		a2 = []
	elif t in [4, 11]:
		a2 = [(2, 1)]
	elif t in [5, 10]:
		a2 = [(2, 1), (n - 1, n)]
	elif t in [6, 9]:
		a2 = [(2, 1), (n, n - 1)]
	elif t in [7, 8]:
		a2 = [(1, 2)]
	print(len(a2))
	for e in a2:
		print(e[0], e[1])


import queue
t = int(input())
while t:
	n = int(input())
	grid = []
	for i in range(n):
		grid.append(input())
	ans = []
	if grid[0][1] == grid[1][0]:
		if grid[-1][-2] == grid[0][1]:
			ans.append((n, n - 1))
		if grid[-2][-1] == grid[0][1]:
			ans.append((n - 1, n))
	elif grid[-1][-2] == grid[-2][-1]:
		if grid[0][1] == grid[-1][-2]:
			ans.append((1, 2))
		if grid[1][0] == grid[-1][-2]:
			ans.append((2, 1))
	elif grid[0][1] != grid[-1][-2]:
		ans = [(1, 2), (n, n - 1)]
	elif grid[0][1] != grid[-2][-1]:
		ans = [(1, 2), (n - 1, n)]
	elif grid[1][0] != grid[-1][-2]:
		ans = [(2, 1), (n, n - 1)]
	else:
		ans = [(2, 1), (n - 1, n)]
	print(len(ans))
	for a in ans:
		print(a[0], a[1])
	t -= 1


for _ in range(int(input())):
	n = int(input())
	data = []
	for i in range(n):
		data.append(input())
	s1 = data[0][1]
	s2 = data[1][0]
	f1 = data[n - 2][n - 1]
	f2 = data[n - 1][n - 2]
	if s1 == '0' and s2 == '0':
		if f1 == '0' and f2 == '0':
			print(2)
			print(n - 1, n)
			print(n, n - 1)
		if f1 == '0' and f2 == '1':
			print(1)
			print(n - 1, n)
		if f1 == '1' and f2 == '0':
			print(1)
			print(n, n - 1)
		if f1 == '1' and f2 == '1':
			print(0)
	if s1 == '0' and s2 == '1':
		if f1 == '0' and f2 == '0':
			print(1)
			print(1, 2)
		if f1 == '0' and f2 == '1':
			print(2)
			print(2, 1)
			print(n - 1, n)
		if f1 == '1' and f2 == '0':
			print(2)
			print(2, 1)
			print(n, n - 1)
		if f1 == '1' and f2 == '1':
			print(1)
			print(2, 1)
	if s1 == '1' and s2 == '0':
		if f1 == '0' and f2 == '0':
			print(1)
			print(2, 1)
		if f1 == '0' and f2 == '1':
			print(2)
			print(2, 1)
			print(n, n - 1)
		if f1 == '1' and f2 == '0':
			print(2)
			print(2, 1)
			print(n - 1, n)
		if f1 == '1' and f2 == '1':
			print(1)
			print(1, 2)
	if s1 == '1' and s2 == '1':
		if f1 == '0' and f2 == '0':
			print(0)
		if f1 == '0' and f2 == '1':
			print(1)
			print(n, n - 1)
		if f1 == '1' and f2 == '0':
			print(1)
			print(n - 1, n)
		if f1 == '1' and f2 == '1':
			print(2)
			print(n - 1, n)
			print(n, n - 1)


from sys import stdin, stdout
n = int(stdin.readline())
for i in range(n):
	arr = []
	b = int(stdin.readline())
	for _ in range(b):
		arr.append(stdin.readline())
	count1s = arr[0][1] + arr[1][0]
	count2s = arr[b - 1][b - 2] + arr[b - 2][b - 1]
	noms = 0
	cod = []
	if count1s == '00':
		if count2s[0] == '0':
			noms += 1
			cod.append([b, b - 1])
		if count2s[1] == '0':
			noms += 1
			cod.append([b - 1, b])
	elif count1s == '11':
		if count2s[0] == '1':
			noms += 1
			cod.append([b, b - 1])
		if count2s[1] == '1':
			noms += 1
			cod.append([b - 1, b])
	elif count1s == '10':
		if count2s == '00':
			noms += 1
			cod.append([2, 1])
		elif count2s == '01':
			noms = 2
			cod.append([1, 2])
			cod.append([b, b - 1])
		elif count2s == '10':
			noms = 2
			cod.append([1, 2])
			cod.append([b - 1, b])
		elif count2s == '11':
			noms = 1
			cod.append([1, 2])
	elif count1s == '01':
		if count2s == '00':
			noms += 1
			cod.append([1, 2])
		elif count2s == '01':
			noms = 2
			cod.append([1, 2])
			cod.append([b - 1, b])
		elif count2s == '10':
			noms = 2
			cod.append([1, 2])
			cod.append([b, b - 1])
		elif count2s == '11':
			noms = 1
			cod.append([2, 1])
	print(noms)
	for i in cod:
		print('{} {}'.format(i[0], i[1]))


for tt in range(int(input())):
	n = int(input())
	l = []
	for i in range(n):
		l.append(list(input()))
	j = []
	cnt = 0
	if l[0][1] == l[1][0]:
		if l[n - 1][n - 2] == l[1][0]:
			cnt += 1
			j.append((n, n - 1))
		if l[n - 2][n - 1] == l[1][0]:
			cnt += 1
			j.append((n - 1, n))
	elif l[n - 1][n - 2] == l[n - 2][n - 1]:
		if l[0][1] == l[n - 1][n - 2]:
			cnt += 1
			j.append((1, 2))
		if l[n - 2][n - 1] == l[1][0]:
			cnt += 1
			j.append((2, 1))
	else:
		if l[0][1] == '1':
			cnt += 1
			j.append((1, 2))
		else:
			cnt += 1
			j.append((2, 1))
		if l[n - 1][n - 2] == '0':
			cnt += 1
			j.append((n, n - 1))
		else:
			cnt += 1
			j.append((n - 1, n))
	print(cnt)
	for i in j:
		print(i[0], i[1])


t = int(input())
for j in range(t):
	n = int(input())
	a = []
	for i in range(n):
		temp = str(input())
		a.append([str(x) for x in temp])
	count = 0
	ans = [[a[0][1], 1, 2], [a[1][0], 2, 1], [a[0][2], 1, 3], [a[1][1], 2, 2], [a[2][0], 3, 1]]
	check1 = ['1', '1', '0', '0', '0']
	check2 = ['0', '0', '1', '1', '1']
	co = []
	for i in range(5):
		if ans[i][0] != check1[i]:
			count += 1
			co.append(ans[i])
	if count > 2:
		co = []
		count = 0
		for i in range(5):
			if ans[i][0] != check2[i]:
				count += 1
				co.append(ans[i])
	if count == 0:
		print(0)
	else:
		print(count)
		for i in co:
			print(str(i[1]) + ' ' + str(i[2]))


import sys
from itertools import permutations
from itertools import combinations
from itertools import combinations_with_replacement
for _ in range(int(input())):
	n = int(input())
	a = ''
	b = ''
	c = ''
	d = ''
	for i in range(0, n):
		li = list(input())
		if i == 0:
			a = li[1]
		if i == 1:
			b = li[0]
		if i == n - 2:
			c = li[n - 1]
		if i == n - 1:
			d = li[n - 2]
	comp = [a, b, c, d]
	a1 = ['0', '0', '1', '1']
	a2 = ['1', '1', '0', '0']
	n1 = 0
	n2 = 0
	for i in range(0, 4):
		if comp[i] != a1[i]:
			n1 += 1
		if comp[i] != a2[i]:
			n2 += 1
	ctr = 0
	if n1 <= 2:
		print(n1)
		if comp[0] != a1[0]:
			print('1 2')
		if comp[1] != a1[1]:
			print('2 1')
		if comp[2] != a1[2]:
			print(n - 1, n)
		if comp[3] != a1[3]:
			print(n, n - 1)
	else:
		print(n2)
		if comp[0] != a2[0]:
			print('1 2')
		if comp[1] != a2[1]:
			print('2 1')
		if comp[2] != a2[2]:
			print(n - 1, n)
		if comp[3] != a2[3]:
			print(n, n - 1)


import math
for _ in range(int(input())):
	n = int(input())
	mat = []
	for i in range(n):
		temp = input()
		mat.append(list(temp))
	a = mat[0][1]
	b = mat[1][0]
	c = mat[n - 1][n - 2]
	d = mat[n - 2][n - 1]
	if a == b and c == d:
		if a != c:
			print(0)
		else:
			print(2)
			print(n, n - 1)
			print(n - 1, n)
	elif a == d and b == c:
		print(2)
		print(1, 2)
		print(n, n - 1)
	elif a == c and b == d and (a != b):
		print(2)
		print(1, 2)
		print(n - 1, n)
	elif a == b and c != d:
		if c == a:
			print(1)
			print(n, n - 1)
		elif d == a:
			print(1)
			print(n - 1, n)
	elif c == d and a != b:
		if a == c:
			print(1)
			print(1, 2)
		elif c == b:
			print(1)
			print(2, 1)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math
import bisect
from collections import Counter
import bisect
import heapq as h
from collections import defaultdict
from collections import deque
for _ in range(int(input())):
	n = int(input())
	g = []
	for i in range(n):
		s = list(input())
		g.append(s)
	if g[0][1] == g[1][0] and g[0][1] == '0':
		ans = []
		if g[n - 1][-2] == '0':
			ans.append([n, n - 1])
		if g[n - 2][n - 1] == '0':
			ans.append([n - 1, n])
		print(len(ans))
		for k in ans:
			print(*k)
	elif g[0][1] == g[1][0] and g[0][1] == '1':
		ans = []
		if g[n - 1][-2] == '1':
			ans.append([n, n - 1])
		if g[n - 2][n - 1] == '1':
			ans.append([n - 1, n])
		print(len(ans))
		for k in ans:
			print(*k)
	elif g[n - 1][n - 2] == g[n - 2][n - 1] == '0':
		ans = []
		if g[0][1] != '1':
			ans.append([1, 2])
		if g[1][0] != '1':
			ans.append([2, 1])
		print(len(ans))
		for k in ans:
			print(*k)
	elif g[n - 1][n - 2] == g[n - 2][n - 1] == '1':
		ans = []
		if g[0][1] != '0':
			ans.append([1, 2])
		if g[1][0] != '0':
			ans.append([2, 1])
		print(len(ans))
		for k in ans:
			print(*k)
	else:
		ans = []
		if g[0][1] != '1':
			ans.append([1, 2])
		if g[1][0] != '1':
			ans.append([2, 1])
		if g[n - 1][n - 2] != '0':
			ans.append([n, n - 1])
		if g[n - 2][n - 1] != '0':
			ans.append([n - 1, n])
		print(len(ans))
		for k in ans:
			print(*k)


test_case_num = int(input())
for i in range(test_case_num):
	a = int(input())
	list = []
	for k in range(a):
		list.append(input())
	x = list[0][1]
	y = list[1][0]
	z = list[a - 1][a - 2]
	p = list[a - 2][a - 1]
	if x == '0' and y == '0' and (z == '0') and (p == '1'):
		print(1)
		print(a, a - 1)
	elif x == '0' and y == '0' and (z == '1') and (p == '0'):
		print(1)
		print(a - 1, a)
	elif x == '1' and y == '0' and (z == '0') and (p == '0'):
		print(1)
		print(2, 1)
	elif x == '0' and y == '1' and (z == '0') and (p == '0'):
		print(1)
		print(1, 2)
	elif x == '1' and y == '1' and (z == '1') and (p == '1'):
		print(2)
		print(1, 2)
		print(2, 1)
	elif x == '0' and y == '0' and (z == '0') and (p == '0'):
		print(2)
		print(1, 2)
		print(2, 1)
	elif x == '0' and y == '0' and (z == '1') and (p == '1'):
		print(0)
	elif x == '1' and y == '1' and (z == '0') and (p == '0'):
		print(0)
	elif x == '0' and y == '1' and (z == '0') and (p == '1'):
		print(2)
		print(1, 2)
		print(a - 1, a)
	elif x == '0' and y == '1' and (z == '1') and (p == '0'):
		print(2)
		print(1, 2)
		print(a, a - 1)
	elif x == '0' and y == '1' and (z == '1') and (p == '1'):
		print(1)
		print(2, 1)
	elif x == '1' and y == '0' and (z == '0') and (p == '1'):
		print(2)
		print(1, 2)
		print(a, a - 1)
	elif x == '1' and y == '0' and (z == '1') and (p == '0'):
		print(2)
		print(1, 2)
		print(a - 1, a)
	elif x == '1' and y == '0' and (z == '1') and (p == '1'):
		print(1)
		print(1, 2)
	elif x == '1' and y == '1' and (z == '0') and (p == '1'):
		print(1)
		print(a - 1, a)
	elif x == '1' and y == '1' and (z == '1') and (p == '0'):
		print(1)
		print(a, a - 1)


import sys
tests = int(sys.stdin.readline())
for i in range(tests):
	msize = int(sys.stdin.readline())
	matrix = []
	for j in range(msize):
		line = sys.stdin.readline().strip()
		matrix.append(line)
	changes = []
	sr = int(matrix[0][1])
	sd = int(matrix[1][0])
	fl = int(matrix[msize - 1][msize - 2])
	fu = int(matrix[msize - 2][msize - 1])
	if sr == sd:
		if fl == sr:
			fl = (fl + 1) % 2
			changes.append((msize, msize - 1))
		if fu == sr:
			fu = (fl + 1) % 2
			changes.append((msize - 1, msize))
	if sr != sd:
		if fl == fu:
			if sr == fl:
				sr = (fl + 1) % 2
				changes.append((1, 2))
			else:
				sd = (fl + 1) % 2
				changes.append((2, 1))
		elif sr == fl:
			sd = (sd + 1) % 2
			changes.append((2, 1))
			fl = (fl + 1) % 2
			changes.append((msize, msize - 1))
		else:
			sr = (sr + 1) % 2
			changes.append((1, 2))
			fl = (fl + 1) % 2
			changes.append((msize, msize - 1))
	print(len(changes))
	for change in changes:
		print(f'{change[0]} {change[1]}')


import math, sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda : int(input())
li = lambda : list(map(int, input().split()))

def solve():
	n = I()
	a = []
	for i in range(n):
		a.append(input().strip())
	p = a[0][1]
	q = a[1][0]
	r = a[n - 1][n - 2]
	s = a[n - 2][n - 1]
	ans = []
	if p == '0' and q == '0':
		if r == '0':
			ans.append([n, n - 1])
		if s == '0':
			ans.append([n - 1, n])
	elif p == '1' and q == '1':
		if r == '1':
			ans.append([n, n - 1])
		if s == '1':
			ans.append([n - 1, n])
	elif r == '0' and s == '0':
		if p == '0':
			ans.append([1, 2])
		if q == '0':
			ans.append([2, 1])
	elif r == '1' and s == '1':
		if p == '1':
			ans.append([1, 2])
		if q == '1':
			ans.append([2, 1])
	else:
		if p == '1':
			ans.append([1, 2])
		if q == '1':
			ans.append([2, 1])
		if r == '0':
			ans.append([n, n - 1])
		if s == '0':
			ans.append([n - 1, n])
	print(len(ans))
	for i in ans:
		print(*i)
for _ in range(I()):
	solve()


from __future__ import division, print_function
import os, sys
import math
import collections
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

class my_dictionary(dict):

	def __init__(self):
		self = dict()

	def add(self, key, value):
		self[key] = value

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def sli():
	return list(msi())

def dmain():
	sys.setrecursionlimit(100000000)
	threading.stack_size(40960000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey, reverse=True)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def factorial(n):
	return 1 if n == 1 or n == 0 else n * factorial(n - 1)

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(n - r))

def binary_search(arr, low, high, x):
	if high >= low:
		mid = (high + low) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] > x:
			return binary_search(arr, low, mid - 1, x)
		else:
			return binary_search(arr, mid + 1, high, x)
	else:
		return -1

def ceil(x, y):
	if x % y == 0:
		return x // y
	else:
		return x // y + 1

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def nCr(n, r):
	return fact(n) / (fact(r) * fact(n - r))

def fact(n):
	res = 1
	for i in range(2, n + 1):
		res = res * i
	return res

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def padded_bin_with_complement(x):
	if x < 0:
		return bin(2 ** 16 - abs(x))[2:].zfill(16)
	else:
		return bin(x)[2:].zfill(16)

def binaryToDecimal(binary):
	binary1 = binary
	(decimal, i, n) = (0, 0, 0)
	while binary != 0:
		dec = binary % 10
		decimal = decimal + dec * pow(2, i)
		binary = binary // 10
		i += 1
	print(decimal)

def CountFrequency(my_list):
	freq = {}
	for item in my_list:
		if item in freq:
			freq[item] += 1
		else:
			freq[item] = 1
	return freq

def pos(a):
	b = [0] * len(a)
	c = sorted(a)
	for i in range(len(a)):
		for j in range(len(a)):
			if c[j] == a[i]:
				b[i] = j
				break
	return b

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n

def commonn(a, b, n):
	c = []
	for i in range(n):
		if a[i] == b[i]:
			c.append('-1')
		else:
			c.append(b[i])
	return c

def find_lcm(num1, num2):
	if num1 > num2:
		num = num1
		den = num2
	else:
		num = num2
		den = num1
	rem = num % den
	while rem != 0:
		num = den
		den = rem
		rem = num % den
	gcd = den
	lcm = int(int(num1 * num2) / int(gcd))
	return lcm

def sumdigit(n):
	n = str(n)
	k = 0
	for i in range(len(n)):
		k += int(n[i])
	return k

def main():
	for _ in range(ii()):
		n = ii()
		a = []
		for i in range(n):
			jk = si()
			a.append(jk)
		x = int(a[0][1])
		y = int(a[1][0])
		z = int(a[n - 2][n - 1])
		s = int(a[n - 1][n - 2])
		d = []
		if x + y >= z + s:
			if x == 0:
				d.append([1, 2])
			if y == 0:
				d.append([2, 1])
			if z == 1:
				d.append([n - 1, n])
			if s == 1:
				d.append([n, n - 1])
		else:
			if x == 1:
				d.append([1, 2])
			if y == 1:
				d.append([2, 1])
			if z == 0:
				d.append([n - 1, n])
			if s == 0:
				d.append([n, n - 1])
		print(len(d))
		for i in range(len(d)):
			print(*d[i])
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	n = int(input())
	l = []
	for i in range(n):
		l.append(list(str(input())))
	l2 = []
	a1 = 0
	a2 = 0
	a3 = 0
	a4 = 0
	c = 0
	a1 += 2 - (int(l[0][1]) + int(l[1][0]))
	a2 += int(l[0][1]) + int(l[1][0])
	a3 = 2 - (int(l[n - 1][n - 2]) + int(l[n - 2][n - 1]))
	a4 += int(l[n - 1][n - 2]) + int(l[n - 2][n - 1])
	if a1 == 0:
		if l[n - 1][n - 2] == '1':
			c += 1
			l2.append([n, n - 1])
		if l[n - 2][n - 1] == '1':
			l2.append([n - 1, n])
			c += 1
	elif a1 == 1:
		if a3 == 0:
			if l[1][0] == '1':
				c += 1
				l2.append([2, 1])
			if l[0][1] == '1':
				l2.append([1, 2])
				c += 1
		elif a3 == 1:
			if l[1][0] == '1':
				c += 1
				l2.append([2, 1])
			if l[0][1] == '1':
				l2.append([1, 2])
				c += 1
			if l[n - 1][n - 2] == '0':
				c += 1
				l2.append([n, n - 1])
			if l[n - 2][n - 1] == '0':
				l2.append([n - 1, n])
				c += 1
		else:
			if l[1][0] == '0':
				c += 1
				l2.append([2, 1])
			if l[0][1] == '0':
				l2.append([1, 2])
				c += 1
	else:
		if l[n - 1][n - 2] == '0':
			c += 1
			l2.append([n, n - 1])
		if l[n - 2][n - 1] == '0':
			l2.append([n - 1, n])
			c += 1
	if len(l2) == 0:
		print(0)
	else:
		print(c)
		for i in l2:
			print(*i)


r = int(input())
for t in range(r):
	n = int(input())
	mas = [[x for x in input()] for i in range(n)]
	sright = mas[0][1]
	sbottom = mas[1][0]
	fleft = mas[-1][-2]
	ftop = mas[-2][-1]
	if sright == sbottom and fleft == ftop and (sright != fleft):
		print(0)
	elif sright == sbottom:
		if fleft == ftop:
			print(2)
			print('1 2')
			print('2 1')
		elif fleft == sright:
			print(1)
			print(str(n) + ' ' + str(n - 1))
		elif ftop == sright:
			print(1)
			print(str(n - 1) + ' ' + str(n))
	elif fleft == ftop:
		if sright == fleft:
			print(1)
			print('1 2')
		elif sbottom == fleft:
			print(1)
			print('2 1')
	elif sright != ftop:
		print(2)
		print('1 2')
		print(str(n - 1) + ' ' + str(n))
	else:
		print(2)
		print('1 2')
		print(str(n) + ' ' + str(n - 1))


import math
from collections import Counter, defaultdict, deque

def f(n, grid):
	r1c2 = grid[0][1]
	r2c1 = grid[1][0]
	up = grid[n - 2][n - 1]
	left = grid[n - 1][n - 2]
	if r1c2 == r2c1 and up == left:
		if r1c2 != up:
			return [0]
		else:
			return [2, '{0} {1}'.format(2, 1), '{0} {1}'.format(1, 2)]
	elif r1c2 != r2c1 and up == left:
		if r1c2 != up:
			return [1, '{0} {1}'.format(2, 1)]
		else:
			return [1, '{0} {1}'.format(1, 2)]
	elif r1c2 == r2c1 and up != left:
		if r1c2 != up:
			return [1, '{0} {1}'.format(n, n - 1)]
		else:
			return [1, '{0} {1}'.format(n - 1, n)]
	elif r1c2 != up:
		return [2, '{0} {1}'.format(2, 1), '{0} {1}'.format(n, n - 1)]
	else:
		return [2, '{0} {1}'.format(2, 1), '{0} {1}'.format(n - 1, n)]
t = int(input())
result = []
for i in range(t):
	n = int(input())
	grid = []
	for row in range(n):
		grid.append(input())
	result.append(f(n, grid))
for i in range(t):
	print(result[i][0])
	for j in range(result[i][0]):
		print(result[i][j + 1])


def main():
	for _ in range(int(input())):
		n = int(input())
		matx = []
		for j in range(n):
			matx.append([str(x) for x in input()])
		x = [int(matx[0][1]), int(matx[1][0])]
		y = [int(matx[n - 1][n - 2]), int(matx[n - 2][n - 1])]
		if x == [0, 0] and y == [1, 1]:
			print(0)
		elif x == [1, 1] and y == [0, 0]:
			print(0)
		elif x == [1, 1] and y == [1, 1]:
			print(2)
			print(1, 2)
			print(2, 1)
		elif x == [0, 0] and y == [0, 0]:
			print(2)
			print(1, 2)
			print(2, 1)
		else:
			if x == [1, 0]:
				if y == [1, 0]:
					print(2)
					print(1, 2)
					print(n - 1, n)
				elif y == [0, 1]:
					print(2)
					print(1, 2)
					print(n, n - 1)
				elif y == [0, 0]:
					print(1)
					print(2, 1)
				else:
					print(1)
					print(1, 2)
			if x == [0, 1]:
				if y == [1, 0]:
					print(2)
					print(1, 2)
					print(n, n - 1)
				elif y == [0, 1]:
					print(2)
					print(1, 2)
					print(n - 1, n)
				elif y == [0, 0]:
					print(1)
					print(1, 2)
				else:
					print(1)
					print(2, 1)
			if x == [1, 1]:
				if y == [1, 0]:
					print(1)
					print(n, n - 1)
				elif y == [0, 1]:
					print(1)
					print(n - 1, n)
			if x == [0, 0]:
				if y == [1, 0]:
					print(1)
					print(n - 1, n)
				elif y == [0, 1]:
					print(1)
					print(n, n - 1)
main()


def solve():
	n = int(input())
	mat = []
	for i in range(n):
		mat.append(input())
	x1 = mat[0][1]
	x2 = mat[1][0]
	y1 = mat[n - 2][n - 1]
	y2 = mat[n - 1][n - 2]
	if x1 == x2 and y1 == y2 and (x1 != y1):
		print(0)
		return
	if x1 == x2 and y1 == y2:
		print(2)
		print('1 2')
		print('2 1')
		return
	if x1 == x2:
		print(1)
		if y1 == x1:
			print(n - 1, end=' ')
			print(n)
			return
		if y2 == x1:
			print(n, end=' ')
			print(n - 1)
			return
	if y1 == y2:
		print(1)
		if x1 == y1:
			print('1 2')
			return
		if x2 == y1:
			print('2 1')
			return
	if x1 == y2:
		print(2)
		print('1 2')
		print(n - 1, end=' ')
		print(n)
		return
	if x1 == y1:
		print(2)
		print('1 2')
		print(n, end=' ')
		print(n - 1)
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	arr = input()
	el12 = int(arr[1])
	arr = input()
	el21 = int(arr[0])
	if n == 3:
		el34 = int(arr[n - 1])
		arr = input()
		el43 = int(arr[n - 2])
	else:
		for _ in range(n - 4):
			arr = input()
		arr = input()
		el34 = int(arr[n - 1])
		arr = input()
		el43 = int(arr[n - 2])
	need = 2 - abs(el12 + el21 - (el34 + el43))
	print(need)
	if need == 2:
		if el12 == el21 == el34 == el43:
			print(1, 2)
			print(2, 1)
		else:
			if el12 != 1:
				print(1, 2)
			if el21 != 1:
				print(2, 1)
			if el34 != 0:
				print(n - 1, n)
			if el43 != 0:
				print(n, n - 1)
	if need == 1:
		if el12 == el21:
			if el34 == el12:
				print(n - 1, n)
			else:
				print(n, n - 1)
		elif el12 == el34:
			print(1, 2)
		else:
			print(2, 1)


from sys import stdin, gettrace
if gettrace():
	inputi = input
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def solve():
	n = int(input())
	grid = []
	for _ in range(n):
		grid.append(input())
	res = []
	if grid[0][1] == grid[1][0]:
		if grid[-1][-2] == grid[0][1]:
			res.append((n, n - 1))
		if grid[-2][-1] == grid[0][1]:
			res.append((n - 1, n))
	elif grid[-1][-2] == grid[-2][-1]:
		if grid[0][1] == grid[-1][-2]:
			res.append((1, 2))
		if grid[1][0] == grid[-2][-1]:
			res.append((2, 1))
	else:
		if grid[0][1] == '1':
			res.append((1, 2))
		else:
			res.append((2, 1))
		if grid[-1][-2] == '0':
			res.append((n, n - 1))
		else:
			res.append((n - 1, n))
	print(len(res))
	for (x, y) in res:
		print(x, y)

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


test = int(input())
for _ in range(test):
	n = int(input())
	mat = []
	for i in range(n):
		mat.append(list(input()))
	a = int(mat[-1][-2])
	b = int(mat[-2][-1])
	c = int(mat[0][1])
	d = int(mat[1][0])
	ans = []
	if a == b:
		ans = []
		if c == a:
			ans.append((1, 2))
		if d == a:
			ans.append((2, 1))
	elif c == d:
		if c == a:
			ans.append((n, n - 1))
		if c == b:
			ans.append((n - 1, n))
	elif a != c:
		ans.append((n, n - 1))
		ans.append((1, 2))
	else:
		ans.append((n, n - 1))
		ans.append((2, 1))
	print(len(ans))
	for (x, y) in ans:
		print(x, y)


import os
import sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		n = getint()
		s = []
		for _ in range(n):
			s.append(input())
		(a, b, c, d) = (s[0][1], s[1][0], s[n - 2][n - 1], s[n - 1][n - 2])
		ans = []
		if a == b:
			if c == a:
				ans.append((n - 1, n))
			if d == a:
				ans.append((n, n - 1))
		elif c == d:
			if c == a:
				ans.append((1, 2))
			if c == b:
				ans.append((2, 1))
		else:
			ans.append((2, 1))
			if c == a:
				ans.append((n - 1, n))
			if d == a:
				ans.append((n, n - 1))
		print(len(ans))
		for (x, y) in ans:
			print(x, y)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def getint():
	return int(input())

def getints():
	return list(map(int, input().split()))

def getint1():
	return list(map(lambda x: int(x) - 1, input().split()))
main()


from sys import stdin
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	lst = []
	for i in range(n):
		lst.append(stdin.readline())
	d1 = (lst[-1][-4], lst[-2][-3], lst[-3][-2])
	d2 = (lst[-1][-3], lst[-2][-2])
	ans = []
	if d2[0] == d2[1]:
		if d1[0] == d1[1] == d1[2] == d2[0]:
			ans.append((n - 1, n))
			ans.append((n, n - 1))
		elif d1[0] == d1[1] == d1[2] != d2[0]:
			pass
		else:
			if d1[0] == d2[0]:
				ans.append((n, n - 2))
			if d1[1] == d2[0]:
				ans.append((n - 1, n - 1))
			if d1[2] == d2[0]:
				ans.append((n - 2, n))
	elif d1.count('1') > d1.count('0'):
		if d1[0] == '0':
			ans.append((n, n - 2))
		if d1[1] == '0':
			ans.append((n - 1, n - 1))
		if d1[2] == '0':
			ans.append((n - 2, n))
		if d2[0] == '1':
			ans.append((n, n - 1))
		if d2[1] == '1':
			ans.append((n - 1, n))
	else:
		if d1[0] == '1':
			ans.append((n, n - 2))
		if d1[1] == '1':
			ans.append((n - 1, n - 1))
		if d1[2] == '1':
			ans.append((n - 2, n))
		if d2[0] == '0':
			ans.append((n, n - 1))
		if d2[1] == '0':
			ans.append((n - 1, n))
	print(len(ans))
	for a in ans:
		print(a[0], a[1])


for i in range(int(input())):
	n = int(input())
	p = []
	for i in range(n):
		x = input()
		p.append(x)
	if p[0][1] == '1' and p[1][0] == '1':
		if p[-2][-1] == '1' and p[-1][-2] == '1':
			print(2)
			print(n, n - 1)
			print(n - 1, n)
		elif p[-2][-1] == '1' and p[-1][-2] == '0':
			print(1)
			print(n - 1, n)
		elif p[-2][-1] == '0' and p[-1][-2] == '1':
			print(1)
			print(n, n - 1)
		elif p[-2][-1] == '0' and p[-1][-2] == '0':
			print(0)
	elif p[0][1] == '0' and p[1][0] == '0':
		if p[-2][-1] == '1' and p[-1][-2] == '1':
			print(0)
		elif p[-2][-1] == '1' and p[-1][-2] == '0':
			print(1)
			print(n, n - 1)
		elif p[-2][-1] == '0' and p[-1][-2] == '1':
			print(1)
			print(n - 1, n)
		elif p[-2][-1] == '0' and p[-1][-2] == '0':
			print(2)
			print(n, n - 1)
			print(n - 1, n)
	elif p[0][1] == '0' and p[1][0] == '1':
		if p[-2][-1] == '1' and p[-1][-2] == '1':
			print(1)
			print(2, 1)
		elif p[-2][-1] == '1' and p[-1][-2] == '0':
			print(2)
			print(2, 1)
			print(n, n - 1)
		elif p[-2][-1] == '0' and p[-1][-2] == '1':
			print(2)
			print(2, 1)
			print(n - 1, n)
		elif p[-2][-1] == '0' and p[-1][-2] == '0':
			print(1)
			print(1, 2)
	elif p[0][1] == '1' and p[1][0] == '0':
		if p[-2][-1] == '1' and p[-1][-2] == '1':
			print(1)
			print(1, 2)
		elif p[-2][-1] == '1' and p[-1][-2] == '0':
			print(2)
			print(1, 2)
			print(n, n - 1)
		elif p[-2][-1] == '0' and p[-1][-2] == '1':
			print(2)
			print(2, 1)
			print(n, n - 1)
		elif p[-2][-1] == '0' and p[-1][-2] == '0':
			print(1)
			print(2, 1)


l = [(1, 0), (0, 1), (-1, -2), (-2, -1)]
t = int(input())
for _ in range(t):
	n = int(input())
	s = [input() for _ in range(n)]
	cnt = 0
	for (x, y) in l:
		if (s[x][y] == '1') ^ (x >= 0):
			cnt += 1
	if cnt >= 2:
		print(4 - cnt)
		for (x, y) in l:
			if (s[x][y] == '1') ^ (x < 0):
				print(x % n + 1, y % n + 1)
	else:
		print(cnt)
		for (x, y) in l:
			if (s[x][y] == '1') ^ (x >= 0):
				print(x % n + 1, y % n + 1)


t = int(input())
answers = []
for _ in range(t):
	n = int(input())
	start = []
	finish = []
	answer = []
	grids = []
	c = 0
	for i in range(n):
		grid = input()
		grids.append(grid)
	start.append(grids[0][1])
	start.append(grids[1][0])
	finish.append(grids[n - 2][n - 1])
	finish.append(grids[n - 1][n - 2])
	if start[0] != start[1] and finish[0] == finish[1]:
		c = 1
		if start[0] == finish[0]:
			answer.append([str(1), str(2)])
		else:
			answer.append([str(2), str(1)])
	elif start[0] == start[1] and finish[0] == finish[1]:
		if start[0] == finish[0]:
			c = 2
			answer.append([str(1), str(2)])
			answer.append([str(2), str(1)])
		else:
			c = 0
	elif start[0] != start[1] and finish[0] != finish[1]:
		c = 2
		if start[0] == finish[0]:
			answer.append([str(1), str(2)])
			answer.append([str(n), str(n - 1)])
		else:
			answer.append([str(1), str(2)])
			answer.append([str(n - 1), str(n)])
	elif start[0] == start[1] and finish[0] != finish[1]:
		c = 1
		if start[0] == finish[0]:
			answer.append([str(n - 1), str(n)])
		else:
			answer.append([str(n), str(n - 1)])
	answers.append([c, answer])
for j in range(t):
	print(answers[j][0])
	for cord in answers[j][1]:
		print(' '.join(cord))


t = int(input())
for case in range(t):
	n = int(input())
	grid = []
	for row in range(n):
		grid.append([int(q) if q in '01' else q for q in input()])
	changes = []
	q = sum([grid[0][2], grid[1][1], grid[2][0]])
	if q in (0, 3):
		if q // 3 == grid[0][1]:
			changes.append([1, 2])
		if q // 3 == grid[1][0]:
			changes.append([2, 1])
		print(len(changes))
		for change in changes:
			print(*change)
		continue
	assert q in (1, 2)
	majority = 0 if q == 1 else 1
	if grid[0][1] == majority and grid[1][0] == majority:
		if grid[n - 1][n - 2] == majority:
			changes.append([n, n - 1])
		if grid[n - 2][n - 1] == majority:
			changes.append([n - 1, n])
	else:
		if grid[0][1] == majority:
			changes.append([1, 2])
		if grid[1][0] == majority:
			changes.append([2, 1])
		if grid[0][2] != majority:
			changes.append([1, 3])
		if grid[1][1] != majority:
			changes.append([2, 2])
		if grid[2][0] != majority:
			changes.append([3, 1])
	assert len(changes) <= 2
	print(len(changes))
	for change in changes:
		print(*change)


def pink(matrix, n):
	counter = 0
	final1 = matrix[n - 1][n - 2]
	final2 = matrix[n - 2][n - 1]
	entrada1 = matrix[0][1]
	entrada2 = matrix[1][0]
	if final1 == final2:
		if entrada1 == final1:
			counter += 1
			(x, y) = (1, 2)
			if entrada2 == final1:
				(z, v) = (2, 1)
				counter += 1
				print(counter)
				print(x, y, end=' ')
				print()
				print(z, v, end=' ')
				print()
			else:
				print(counter)
				print(x, y, end=' ')
				print()
		elif entrada2 == final1:
			counter += 1
			(z, v) = (2, 1)
			print(counter)
			print(z, v, end=' ')
			print()
		else:
			print(counter)
	elif entrada1 == entrada2:
		if entrada1 == final1:
			counter += 1
			(z, v) = (n, n - 1)
			print(counter)
			print(z, v, end=' ')
			print()
		elif entrada1 == final2:
			counter += 1
			(z, v) = (n - 1, n)
			print(counter)
			print(z, v, end=' ')
			print()
	else:
		counter = 2
		print(counter)
		(x, y) = (1, 2)
		print(x, y, end=' ')
		print()
		if entrada1 == final1:
			(z, v) = (n - 1, n)
			print(z, v, end=' ')
			print()
		else:
			(z, v) = (n, n - 1)
			print(z, v, end=' ')
			print()
test = int(input())
for i in range(test):
	matrix = []
	n = int(input())
	for j in range(n):
		fila = input()
		matrix.append(fila)
	pink(matrix, n)


t = int(input())
for _ in range(t):
	n = int(input())
	grid = []
	for i in range(n):
		l = input()
		grid.append(l)
	a = grid[0][1]
	b = grid[1][0]
	c = grid[n - 2][n - 1]
	d = grid[n - 1][n - 2]
	if a == b:
		if c == d:
			if a == c:
				print('2')
				print(n, n - 1)
				print(n - 1, n)
			else:
				print('0')
		else:
			print('1')
			if a == c:
				print(n - 1, n)
			else:
				print(n, n - 1)
	elif c == d:
		print('1')
		if a == c:
			print('1 2')
		else:
			print('2 1')
	else:
		print('2')
		if a == c:
			print('2 1')
			print(n - 1, n)
		else:
			print('2 1')
			print(n, n - 1)


from sys import stdin
_input = stdin.readline
(_range, _list, _str, _int) = (range, list, str, int)

def solution():
	for _ in _range(_int(_input())):
		n = _int(_input())
		arr = []
		for i in _range(n):
			arr.append(_list(_input().rstrip('\n')))
		(a, b, c, d) = (_int(arr[0][1]), _int(arr[1][0]), _int(arr[n - 1][n - 2]), _int(arr[n - 2][n - 1]))
		(l, r) = (a + b, c + d)
		if l == 0 and r == 2 or (l == 2 and r == 0):
			print(0)
		elif l == 0 and r == 0 or (l == 2 and r == 2):
			print(2)
			print(1, 2)
			print(2, 1)
		elif r == 2:
			if a == 0:
				print(1)
				print(2, 1)
			else:
				print(1)
				print(1, 2)
		elif l == 2:
			if c == 0:
				print(1)
				print(n - 1, n)
			else:
				print(1)
				print(n, n - 1)
		elif l == 0:
			if c == 0:
				print(1)
				print(n, n - 1)
			else:
				print(1)
				print(n - 1, n)
		elif r == 0:
			if a == 0:
				print(1)
				print(1, 2)
			else:
				print(1)
				print(2, 1)
		elif a == 0:
			print(2)
			print(1, 2)
			if c == 0:
				print(n - 1, n)
			else:
				print(n, n - 1)
		else:
			print(2)
			print(2, 1)
			if c == 0:
				print(n - 1, n)
			else:
				print(n, n - 1)
solution()


t = int(input())
for _ in range(0, t):
	n = int(input())
	s = []
	for i in range(0, n):
		ss = [k for k in input()]
		s.append(ss)
	ans = []
	kk = [s[0][1], s[1][0], s[-2][-1], s[-1][-2]]
	(z, o) = (kk.count('0'), kk.count('1'))
	if z == 0 or o == 0:
		ans.append([1, 2])
		ans.append([2, 1])
	if z == 1 and o == 3:
		if kk[0] != kk[1]:
			if kk[0] == '1':
				ans.append([1, 2])
			else:
				ans.append([2, 1])
		elif kk[2] == '1':
			ans.append([n - 1, n])
		else:
			ans.append([n, n - 1])
	if z == 2 and o == 2 and (kk[0] != kk[1]):
		if kk[0] == '0':
			ans.append([1, 2])
		if kk[1] == '0':
			ans.append([2, 1])
		if kk[2] == '1':
			ans.append([n - 1, n])
		if kk[3] == '1':
			ans.append([n, n - 1])
	if z == 3 and o == 1:
		if kk[0] != kk[1]:
			if kk[0] == '0':
				ans.append([1, 2])
			else:
				ans.append([2, 1])
		elif kk[2] == '0':
			ans.append([n - 1, n])
		else:
			ans.append([n, n - 1])
	print(len(ans))
	for i in ans:
		print(*i)


from sys import stdin, stdout
import math
import heapq
import collections
input = stdin.readline

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputstrings():
	return [x for x in input().split()]

def inputstringnum():
	return [ord(x) - ord('a') for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	n = inputnum()
	m = inputmatrixchar(n)
	ans1 = []
	ans2 = []
	a = m[0][1]
	b = m[1][0]
	c = m[n - 1][n - 2]
	d = m[n - 2][n - 1]
	if a == '0' and b == '0':
		if c == '0':
			ans1.append(n)
			ans1.append(n - 1)
		if d == '0':
			ans2.append(n - 1)
			ans2.append(n)
	elif a == '1' and b == '0':
		if c == '0' and d == '0':
			ans1.append(2)
			ans1.append(1)
		if c == '1' and d == '0':
			ans1.append(1)
			ans1.append(2)
			ans2.append(n - 1)
			ans2.append(n)
		if c == '0' and d == '1':
			ans1.append(1)
			ans1.append(2)
			ans2.append(n)
			ans2.append(n - 1)
		if c == '1' and d == '1':
			ans1.append(1)
			ans1.append(2)
	elif a == '0' and b == '1':
		if c == '0' and d == '0':
			ans1.append(1)
			ans1.append(2)
		if c == '1' and d == '0':
			ans1.append(1)
			ans1.append(2)
			ans2.append(n)
			ans2.append(n - 1)
		if c == '0' and d == '1':
			ans1.append(1)
			ans1.append(2)
			ans2.append(n - 1)
			ans2.append(n)
		if c == '1' and d == '1':
			ans1.append(2)
			ans1.append(1)
	else:
		if c == '1':
			ans1.append(n)
			ans1.append(n - 1)
		if d == '1':
			ans2.append(n - 1)
			ans2.append(n)
	cnt = (len(ans1) != 0) + (len(ans2) != 0)
	print(cnt)
	if len(ans1) != 0:
		print(*ans1)
	if len(ans2) != 0:
		print(*ans2)


t = int(input())
for _ in range(t):
	n = int(input())
	mt = []
	for i in range(n):
		s = input()
		mt.append(s)
	a = mt[0][1]
	b = mt[1][0]
	c = mt[-1][-2]
	d = mt[-2][-1]
	if c == d == '1':
		if a == b == '0':
			print(0)
		elif a == b == '1':
			print(2)
			print(1, 2)
			print(2, 1)
		elif a == '0' and b == '1':
			print(1)
			print(2, 1)
		else:
			print(1)
			print(1, 2)
	elif c == d == '0':
		if a == b == '1':
			print(0)
		elif a == b == '0':
			print(2)
			print(1, 2)
			print(2, 1)
		elif a == '0' and b == '1':
			print(1)
			print(1, 2)
		else:
			print(1)
			print(2, 1)
	elif c == '0' and d == '1':
		if a == '0' and b == '0':
			print(1)
			print(n, n - 1)
		elif a == '0' and b == '1':
			print(2)
			print(2, 1)
			print(n, n - 1)
		elif a == '1' and b == '0':
			print(2)
			print(1, 2)
			print(n, n - 1)
		else:
			print(1)
			print(n - 1, n)
	elif a == '0' and b == '0':
		print(1)
		print(n - 1, n)
	elif a == '0' and b == '1':
		print(2)
		print(1, 2)
		print(n, n - 1)
	elif a == '1' and b == '0':
		print(2)
		print(2, 1)
		print(n, n - 1)
	else:
		print(1)
		print(n, n - 1)


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	M = [list(input().strip()) for _ in range(n)]
	ans = []
	(a, b, c, d) = (M[0][1], M[1][0], M[n - 1][n - 2], M[n - 2][n - 1])
	if c == d:
		if a == d:
			ans.append((1, 2))
		if b == d:
			ans.append((2, 1))
	elif a == b:
		if c == a:
			ans.append((n, n - 1))
		if d == a:
			ans.append((n - 1, n))
	else:
		if a == '1':
			ans.append((1, 2))
		if b == '1':
			ans.append((2, 1))
		if c == '0':
			ans.append((n, n - 1))
		if d == '0':
			ans.append((n - 1, n))
	print(len(ans))
	for i in ans:
		print(*i)
for _ in range(int(input())):
	solve()


m = {'0000': (3, 4), '0001': (3,), '0010': (4,), '0011': (), '0100': (1,), '0101': (2, 3), '0110': (2, 4), '0111': (2,), '1000': (2,), '1001': (2, 4), '1010': (2, 3), '1011': (1,), '1100': (), '1101': (4,), '1110': (3,), '1111': (3, 4)}
t = int(input())
for _ in range(t):
	n = int(input())
	f = [list(input()) for _ in range(n)]
	c11 = f[0][1]
	c12 = f[1][0]
	c21 = f[-2][-1]
	c22 = f[-1][-2]
	s = f'{c11}{c12}{c21}{c22}'
	r = m[s]
	print(len(r))
	for rr in r:
		if rr == 1:
			print('1 2')
		elif rr == 2:
			print('2 1')
		elif rr == 3:
			print(f'{n - 1} {n}')
		else:
			print(f'{n} {n - 1}')


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	arr = []
	for i in range(n):
		a = input()
		b = []
		for i in range(n):
			b.append(a[i])
		arr.append(b)
	if arr[0][1] == arr[1][0]:
		ans = []
		if arr[2][0] == arr[0][1]:
			ans.append([2, 0])
		if arr[1][1] == arr[0][1]:
			ans.append([1, 1])
		if arr[0][2] == arr[0][1]:
			ans.append([0, 2])
		if len(ans) < 3:
			print(len(ans))
			for i in range(len(ans)):
				print(ans[i][0] + 1, ans[i][1] + 1)
		else:
			print(2)
			print(1, 2)
			print(2, 1)
	else:
		if arr[1][1] == arr[2][0] and arr[1][1] == arr[0][2]:
			print(1)
			if arr[1][0] == arr[1][1]:
				print(2, 1)
			else:
				print(1, 2)
			continue
		if arr[2][0] == arr[1][1]:
			print(2)
			if arr[0][2] == arr[1][0]:
				print(1, 2)
			else:
				print(2, 1)
			print(1, 3)
		elif arr[1][1] == arr[0][2]:
			print(2)
			print(3, 1)
			if arr[2][0] != arr[1][0]:
				print(2, 1)
			else:
				print(1, 2)
		else:
			print(2)
			print(2, 2)
			if arr[1][1] != arr[1][0]:
				print(2, 1)
			else:
				print(1, 2)


t = int(input())
while t:
	t = t - 1
	n = int(input())
	for i in range(n):
		s = input()
		if i == 0:
			ur = s[1]
		if i == 1:
			ud = s[0]
		if i == n - 2:
			du = s[-1]
		if i == n - 1:
			dl = s[-2]
	if ur == '1' and ud == '1':
		if du == '0' and dl == '0':
			print(0)
			continue
		elif du == '1' and dl == '1':
			print(2)
			print(n - 1, n)
			print(n, n - 1)
			continue
		elif du == '0' and dl == '1':
			print(1)
			print(n, n - 1)
			continue
		else:
			print(1)
			print(n - 1, n)
			continue
	elif ur == '0' and ud == '0':
		if du == '1' and dl == '1':
			print(0)
			continue
		elif du == '0' and dl == '0':
			print(2)
			print(n - 1, n)
			print(n, n - 1)
			continue
		elif du == '0' and dl == '1':
			print(1)
			print(n - 1, n)
			continue
		else:
			print(1)
			print(n, n - 1)
			continue
	elif ur == '0' and ud == '1':
		if du == '1' and dl == '1':
			print(1)
			print(2, 1)
			continue
		elif du == '0' and dl == '0':
			print(1)
			print(1, 2)
			continue
		elif du == '0' and dl == '1':
			print(2)
			print(1, 2)
			print(n, n - 1)
			continue
		else:
			print(2)
			print(1, 2)
			print(n - 1, n)
			continue
	elif du == '1' and dl == '1':
		print(1)
		print(1, 2)
		continue
	elif du == '0' and dl == '0':
		print(1)
		print(2, 1)
		continue
	elif du == '0' and dl == '1':
		print(2)
		print(1, 2)
		print(n - 1, n)
		continue
	else:
		print(2)
		print(1, 2)
		print(n, n - 1)
		continue


import sys
input = lambda : sys.stdin.readline().rstrip()
t = int(input())
for _ in range(t):
	n = int(input())
	s = []
	for _ in range(n):
		s.append(input())
	(x0, x1, x2, x3) = (int(s[0][1]), int(s[1][0]), int(s[-1][-2]), int(s[-2][-1]))
	ans = []
	if x0 == 1:
		ans.append((1, 2))
	if x1 == 1:
		ans.append((2, 1))
	if x2 == 0:
		ans.append((n, n - 1))
	if x3 == 0:
		ans.append((n - 1, n))
	if len(ans) <= 2:
		print(len(ans))
		for i in ans:
			print(*i)
		continue
	ans = []
	if x0 == 0:
		ans.append((1, 2))
	if x1 == 0:
		ans.append((2, 1))
	if x2 == 1:
		ans.append((n, n - 1))
	if x3 == 1:
		ans.append((n - 1, n))
	print(len(ans))
	for i in ans:
		print(*i)


for _ in range(int(input())):
	n = int(input())
	matrix = []
	for i in range(n):
		s = input()
		matrix.append(s)
	s = ''
	s += matrix[0][1] + matrix[1][0] + matrix[-1][-2] + matrix[-2][-1]
	(z, o) = (s.count('0'), s.count('1'))
	if s[:2] == '00' and s[2:] == '11' or (s[:2] == '11' and s[2:] == '00'):
		print(0)
	elif z == 4 or o == 4:
		print(2)
		print(1, 2)
		print(2, 1)
	else:
		print(min(z, o))
		if z != o:
			if s[:2] == '00':
				if s[2] == '0':
					print(n, n - 1)
				elif s[3] == '0':
					print(n - 1, n)
			elif s[:2] == '11':
				if s[2] == '1':
					print(n, n - 1)
				elif s[3] == '1':
					print(n - 1, n)
			elif s[2:] == '00':
				if s[0] == '0':
					print(1, 2)
				elif s[1] == '0':
					print(2, 1)
			elif s[2:] == '11':
				if s[0] == '1':
					print(1, 2)
				elif s[1] == '1':
					print(2, 1)
		elif s[:2] == '01' and s[2:] == '01':
			print(1, 2)
			print(n - 1, n)
		elif s[:2] == '10' and s[2:] == '01':
			print(2, 1)
			print(n - 1, n)
		elif s[:2] == '01' and s[2:] == '10':
			print(1, 2)
			print(n, n - 1)
		elif s[:2] == '10' and s[2:] == '10':
			print(2, 1)
			print(n, n - 1)


t = int(input())
for _ in range(t):
	n = int(input())
	imp = []
	for i in range(n):
		temp = input()
		if i == 0:
			imp.append(temp[1])
			imp.append(temp[2])
		elif i == 1:
			imp.append(temp[0])
			imp.append(temp[1])
		elif i == 2:
			imp.append(temp[0])
	count = 0
	ans = []
	if imp[0] != '0':
		ans.append([1, 2])
		count += 1
	if imp[2] != '0':
		ans.append([2, 1])
		count += 1
	if imp[1] != '1':
		ans.append([1, 3])
		count += 1
	if imp[3] != '1':
		ans.append([2, 2])
		count += 1
	if imp[4] != '1':
		ans.append([3, 1])
		count += 1
	if count <= 2:
		print(count)
		for i in ans:
			print(i[0], i[1])
	else:
		count = 0
		ans = []
		if imp[0] != '1':
			ans.append([1, 2])
			count += 1
		if imp[2] != '1':
			ans.append([2, 1])
			count += 1
		if imp[1] != '0':
			ans.append([1, 3])
			count += 1
		if imp[3] != '0':
			ans.append([2, 2])
			count += 1
		if imp[4] != '0':
			ans.append([3, 1])
			count += 1
		if count <= 2:
			print(count)
			for i in ans:
				print(i[0], i[1])


from collections import Counter, OrderedDict
from itertools import permutations as perm
from sys import setrecursionlimit
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
import threading
import math
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(t,) = gil()
for _ in range(t):
	(n,) = gil()
	mat = []
	for _ in range(n):
		mat.append(g())
	(start, end) = ([mat[1][0], mat[0][1]], [mat[-1][-2], mat[-2][-1]])
	start.sort()
	end.sort()
	if start == end and start[0] == start[1]:
		print(2)
		print(0 + 1, 1 + 1)
		print(1 + 1, 0 + 1)
	elif start == end and start[0] != start[1]:
		print(2)
		print(0 + 1, 1 + 1)
		state = mat[0][1]
		if state != mat[n - 1][n - 2]:
			print(n - 1 + 1, n - 2 + 1)
		else:
			print(n - 2 + 1, n - 1 + 1)
	elif start[0] == start[1] and end[0] == end[1] and (start[0] != end[0]):
		print(0)
	elif start[0] == start[1]:
		state = mat[0][1]
		print(1)
		if state == mat[n - 1][n - 2]:
			print(n - 1 + 1, n - 2 + 1)
		else:
			print(n - 2 + 1, n - 1 + 1)
	elif end[0] == end[1]:
		state = mat[n - 1][n - 2]
		print(1)
		if state == mat[0][1]:
			print(0 + 1, 1 + 1)
		else:
			print(1 + 1, 0 + 1)
	else:
		print(0)


for u in range(int(input())):
	n = int(input())
	l = []
	(x, y) = ([], [])
	for i in range(n):
		l.append(list(input()))
	d = [l[0][1], l[1][0], l[n - 1][n - 2], l[n - 2][n - 1]]
	if d[0] == '1':
		x.append([1, 2])
	if d[1] == '1':
		x.append([2, 1])
	if d[2] == '0':
		x.append([n, n - 1])
	if d[3] == '0':
		x.append([n - 1, n])
	if d[0] == '0':
		y.append([1, 2])
	if d[1] == '0':
		y.append([2, 1])
	if d[2] == '1':
		y.append([n, n - 1])
	if d[3] == '1':
		y.append([n - 1, n])
	if len(x) <= len(y):
		print(len(x))
		for i in x:
			print(*i)
	else:
		print(len(y))
		for i in y:
			print(*i)


def main():
	for _ in range(int(input())):
		n = int(input())
		l = [list(map(lambda x: int(x) if not (x == 'S' or x == 'F') else x, input())) for i in range(n)]
		if l[0][1] == l[1][0] and l[n - 1][n - 2] == l[n - 2][n - 1] and (l[n - 1][n - 2] == 1 - l[1][0]):
			print(0)
		elif l[0][1] == l[1][0] and l[n - 1][n - 2] == l[n - 2][n - 1]:
			print(2)
			print(1, 2)
			print(2, 1)
		elif l[0][1] != l[1][0] and l[n - 1][n - 2] == l[n - 2][n - 1]:
			print(1)
			print(*([1, 2] if l[0][1] == l[n - 1][n - 2] else [2, 1]))
		elif l[0][1] == l[1][0] and l[n - 1][n - 2] != l[n - 2][n - 1]:
			print(1)
			print(*([n, n - 1] if l[0][1] == l[n - 1][n - 2] else [n - 1, n]))
		else:
			print(2)
			print(*([1, 2] if l[0][1] == 0 else [2, 1]))
			print(*([n, n - 1] if l[n - 1][n - 2] == 1 else [n - 1, n]))
main()


import os
import sys
from io import BytesIO, IOBase
import threading
from bisect import bisect_right
from math import gcd, log
from collections import Counter
from pprint import pprint
from itertools import combinations

def fun(val, grid, n):
	bfs = [(0, 0)]
	delta = [(1, 0), (-1, 0), (0, 1), (0, -1)]
	visited = [[0] * n for i in range(n)]
	visited[0][0] = 1
	while len(bfs):
		(x, y) = bfs.pop()
		if x == y == n - 1:
			return True
		for (dx, dy) in delta:
			nx = x + dx
			ny = y + dy
			if 0 <= nx < n and 0 <= ny < n and (visited[nx][ny] == 0) and (grid[nx][ny] in [val, 'F']):
				visited[nx][ny] = 1
				bfs.append((nx, ny))
	return False

def main():
	n = int(input())
	arr = []
	for i in range(n):
		arr.append([c for c in input()])
	l = [(1, 0), (0, 1), (n - 1, n - 2), (n - 2, n - 1)]
	c = list(combinations(l, 0)) + list(combinations(l, 1)) + list(combinations(l, 2))
	for li in c:
		for (x, y) in li:
			arr[x][y] = '1' if arr[x][y] == '0' else '0'
		if fun('0', arr, n) or fun('1', arr, n):
			pass
		else:
			print(len(li))
			for (x, y) in li:
				print(x + 1, y + 1)
			return
		for (x, y) in li:
			arr[x][y] = '1' if arr[x][y] == '0' else '0'
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	main()


t = int(input())
for i in range(t):
	n = int(input())
	x = []
	for j in range(n):
		w = input()
		x.append(w)
	if x[0][1] == x[1][0]:
		if x[-1][-2] == x[-2][-1]:
			if x[0][1] == x[-1][-2]:
				print(2)
				print(1, 2)
				print(2, 1)
			else:
				print(0)
		elif x[0][1] == x[-1][-2]:
			print(1)
			print(n, n - 1)
		else:
			print(1)
			print(n - 1, n)
	elif x[-1][-2] == x[-2][-1]:
		if x[0][1] == x[-1][-2]:
			print(1)
			print(1, 2)
		else:
			print(1)
			print(2, 1)
	elif x[0][1] == x[-1][-2]:
		print(2)
		print(2, 1)
		print(n, n - 1)
	else:
		print(2)
		print(2, 1)
		print(n - 1, n)


from sys import stdin
input = stdin.readline

def solve():
	n = int(input())
	s = [''] * n
	for i in range(n):
		s[i] = input().strip()
	s1 = int(s[0][1])
	s2 = int(s[1][0])
	e1 = int(s[-1][-2])
	e2 = int(s[-2][-1])
	res = 0
	r = []
	if s1 == s2:
		if e1 == s1:
			res += 1
			r.append(f'{n} {n - 1}')
		if e2 == s1:
			res += 1
			r.append(f'{n - 1} {n}')
	elif e1 == e2:
		if s1 == e1:
			res += 1
			r.append('1 2')
		if s2 == e1:
			res += 1
			r.append('2 1')
	else:
		if s1 == 0:
			res += 1
			r.append('1 2')
		if s2 == 0:
			res += 1
			r.append('2 1')
		if e1 == 1:
			res += 1
			r.append(f'{n} {n - 1}')
		if e2 == 1:
			res += 1
			r.append(f'{n - 1} {n}')
	print(res)
	if res != 0:
		print('\n'.join(r))
t = int(input())
for _ in range(t):
	solve()


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def gift():
	for _ in range(t):
		n = int(input())
		grid = []
		for i in range(n):
			tem = input()
			grid.append(tem)
		f1 = grid[0][1]
		f2 = grid[1][0]
		l1 = grid[n - 1][n - 2]
		l2 = grid[n - 2][n - 1]
		if f1 == f2:
			if l1 == l2:
				if f1 == l1:
					yield 2
					yield '1 2'
					yield '2 1'
				else:
					yield 0
			elif f1 == l1:
				yield 1
				yield '{} {}'.format(n, n - 1)
			else:
				yield 1
				yield '{} {}'.format(n - 1, n)
		elif l1 == l2:
			if f1 == l1:
				yield 1
				yield '1 2'
			else:
				yield 1
				yield '2 1'
		elif f1 == l1:
			yield 2
			yield '1 2'
			yield '{} {}'.format(n - 1, n)
		else:
			yield 2
			yield '1 2'
			yield '{} {}'.format(n, n - 1)
t = int(input())
ans = gift()
print(*ans, sep='\n')


import sys

def gt():
	return list(map(int, input().split()))
pr = lambda x: print(*x[1])
(t,) = gt()
while t:
	t -= 1
	mp = []
	(n,) = gt()
	for i in range(n):
		mp.append(input())
	a = (int(mp[0][1]), (1, 2))
	b = (int(mp[1][0]), (2, 1))
	c = (int(mp[-1][-2]), (n, n - 1))
	d = (int(mp[-2][-1]), (n - 1, n))
	if c[0] == d[0]:
		(a, b, c, d) = (c, d, a, b)
	if a[0] == b[0]:
		if c[0] == d[0]:
			if a[0] == c[0]:
				print(2)
				pr(c)
				pr(d)
			else:
				print(0)
		elif a[0] == c[0]:
			print(1)
			pr(c)
		else:
			print(1)
			pr(d)
	elif a[0] == c[0]:
		print(2)
		pr(b)
		pr(c)
	else:
		print(2)
		pr(a)
		pr(c)


for _ in range(int(input())):
	ans = 0
	ind = [[0] * 2 for i in range(4)]
	n = int(input())
	s = [input() for i in range(n)]
	if s[1][0] == '1':
		ans += 1
		ind[0][0] = 2
		ind[0][1] = 1
	if s[0][1] == '1':
		ans += 1
		ind[1][0] = 1
		ind[1][1] = 2
	if s[n - 1][n - 2] == '0':
		ans += 1
		ind[2][0] = n
		ind[2][1] = n - 1
	if s[n - 2][n - 1] == '0':
		ans += 1
		ind[3][0] = n - 1
		ind[3][1] = n
	if ans <= 2:
		print(ans)
		for i in range(4):
			if ind[i][0] == 0:
				continue
			else:
				print(ind[i][0], ind[i][1])
	else:
		ans = 0
		ind = [[0] * 2 for i in range(4)]
		if s[1][0] == '0':
			ans += 1
			ind[0][0] = 2
			ind[0][1] = 1
		if s[0][1] == '0':
			ans += 1
			ind[1][0] = 1
			ind[1][1] = 2
		if s[n - 1][n - 2] == '1':
			ans += 1
			ind[2][0] = n
			ind[2][1] = n - 1
		if s[n - 2][n - 1] == '1':
			ans += 1
			ind[3][0] = n - 1
			ind[3][1] = n
		print(ans)
		for i in range(4):
			if ind[i][0] == 0:
				continue
			else:
				print(ind[i][0], ind[i][1])


import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.buffer.readline())

def MI():
	return map(int, sys.stdin.buffer.readline().split())

def LI():
	return list(map(int, sys.stdin.buffer.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def BI():
	return sys.stdin.buffer.readline().rstrip()

def SI():
	return sys.stdin.buffer.readline().rstrip().decode()
for _ in range(II()):
	n = II()
	ss = [SI() for _ in range(n)]
	ans = []
	if ss[0][1] == ss[1][0]:
		c = ss[0][1]
		if ss[-1][-2] == c:
			ans.append((n, n - 1))
		if ss[-2][-1] == c:
			ans.append((n - 1, n))
	elif ss[-1][-2] == ss[-2][-1]:
		c = ss[-1][-2]
		if ss[0][1] == c:
			ans.append((1, 2))
		if ss[1][0] == c:
			ans.append((2, 1))
	else:
		if ss[-1][-2] == '1':
			ans.append((n, n - 1))
		if ss[-2][-1] == '1':
			ans.append((n - 1, n))
		if ss[0][1] == '0':
			ans.append((1, 2))
		if ss[1][0] == '0':
			ans.append((2, 1))
	print(len(ans))
	for (i, j) in ans:
		print(i, j)


t = int(input())
for i in range(t):
	n = int(input())
	a = [['.'] * n for j in range(n)]
	res = 0
	ans = []
	for k in range(n):
		a[k] = list(input())
	if a[0][1] == '0' and a[1][0] == '0':
		if a[-2][-1] == '0':
			res += 1
			ans.append((n - 1, n))
		if a[-1][-2] == '0':
			res += 1
			ans.append((n, n - 1))
	if a[0][1] == '1' and a[1][0] == '1':
		if a[-2][-1] == '1':
			res += 1
			ans.append((n - 1, n))
		if a[-1][-2] == '1':
			res += 1
			ans.append((n, n - 1))
	if a[0][1] == '0' and a[1][0] == '1':
		if a[-2][-1] == '0' and a[-1][-2] == '0':
			res += 1
			ans.append((1, 2))
		if a[-2][-1] == '1' and a[-1][-2] == '1':
			res += 1
			ans.append((2, 1))
		if a[-2][-1] == '0' and a[-1][-2] == '1':
			res += 1
			ans.append((2, 1))
			res += 1
			ans.append((n - 1, n))
		if a[-2][-1] == '1' and a[-1][-2] == '0':
			res += 1
			ans.append((2, 1))
			res += 1
			ans.append((n, n - 1))
	if a[0][1] == '1' and a[1][0] == '0':
		if a[-2][-1] == '0' and a[-1][-2] == '0':
			res += 1
			ans.append((2, 1))
		if a[-2][-1] == '1' and a[-1][-2] == '1':
			res += 1
			ans.append((1, 2))
		if a[-2][-1] == '0' and a[-1][-2] == '1':
			res += 1
			ans.append((1, 2))
			res += 1
			ans.append((n - 1, n))
		if a[-2][-1] == '1' and a[-1][-2] == '0':
			res += 1
			ans.append((1, 2))
			res += 1
			ans.append((n, n - 1))
	print(res)
	for x in ans:
		print(*x)


import math
import sys
from collections import OrderedDict

class Graph:

	def __init__(self, Nodes, is_directed=False):
		self.nodes = Nodes
		self.adj_list = {}
		self.is_directed = is_directed
		for node in self.nodes:
			self.adj_list[node] = []

	def add_edge(self, u, v):
		self.adj_list[u].append(v)
		if self.is_directed == False:
			self.adj_list[v].append(u)

	def print_graph(self):
		for node in self.nodes:
			print(node, '->', self.adj_list[node])

	def degree_node(self, node):
		return len(self.adj_list[node])

	def dfsUTIL(self, v, visited, parents=[]):
		visited[v] = True
		for i in self.adj_list[v]:
			if visited[i] == False:
				self.dfsUTIL(i, visited, parents)
				parents.append(i)

	def dfs(self, v):
		visited = [False] * (max(self.adj_list) + 1)
		parents = [v]
		self.dfsUTIL(v, visited, parents)
		return parents

def dict_sort(ans):
	ans = sorted(ans.items(), reverse=True, key=lambda kv: kv[1])

def is_prime(n):
	if n == 1:
		return 0
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def seive_primes(n):
	flag = [0] * (n + 10)
	flag[1] = flag[0] = 1
	i = 2
	while i * i <= n + 1:
		if flag[i] == 0:
			j = i * i
			while j <= n + 1:
				flag[j] = 1
				j += i
		i += 1
	return flag

def factors(n):
	d = {}
	while n % 2 == 0:
		if 2 in d:
			d[2] += 1
		else:
			d[2] = 1
		n /= 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
			n /= i
	n = int(n)
	if n > 1:
		d[n] = 1
	return d

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)

def alphabates():
	return 'abcdefghijklmnopqrstuvwxyz'

def binary_search(ls, n, flag):
	low = 0
	hi = n - 1
	while low <= hi:
		mid = (low + hi) // 2
		if ls[mid] == flag:
			return mid
		elif ls[mid] > flag:
			hi = mid - 1
		else:
			low = mid + 1
	return -1

def qdrt(a, b, c):
	chk = b * b - 4 * a * c
	if chk >= 0:
		ans1 = (-b + chk ** 0.5) / (2 * a)
		ans2 = (-b - chk ** 0.5) / (2 * a)
		return [int(ans1), int(ans2)]
	return -1

def permutation(n, r):
	if n < r:
		return 0
	ans = 1
	for i in range(n - r + 1, n + 1):
		ans *= i
	return ans

def combination(n, r):
	if n < r:
		return 0
	ans = 1
	for i in range(r):
		ans *= n - i
	div = 1
	for i in range(2, r + 1):
		div *= i
	return ans // div

def ispow2(n):
	ans = int(math.log(n, 2))
	if 2 ** ans == n:
		return True
	return False

def _2dmat(n):
	flag = [[i + 1 for i in range(n)]]
	for i in range(2, n + 1):
		new = []
		for j in range((i - 1) * n + 1, i * n + 1):
			new.append(j)
		flag.append(new)
	return flag

def sumn(n):
	return n * (n + 1) // 2

def arrinp():
	ls = list(map(int, input().split()))
	return ls

def mult_inp():
	return map(int, input().split())

def chk(arr, a, b, c):
	if arr[a][b] == c:
		print(a + 1, b + 1)

def main():
	n = int(input())
	grid = []
	for i in range(n):
		grid.append(input())
	_0 = 0
	if grid[0][1] == '0':
		_0 += 1
	if grid[1][0] == '0':
		_0 += 1
	if grid[n - 1][n - 2] == '1':
		_0 += 1
	if grid[n - 2][n - 1] == '1':
		_0 += 1
	if _0 > 2:
		print(4 - _0)
		chk(grid, 0, 1, '1')
		chk(grid, 1, 0, '1')
		chk(grid, n - 1, n - 2, '0')
		chk(grid, n - 2, n - 1, '0')
	else:
		print(_0)
		chk(grid, 0, 1, '0')
		chk(grid, 1, 0, '0')
		chk(grid, n - 1, n - 2, '1')
		chk(grid, n - 2, n - 1, '1')
for _ in range(int(input())):
	main()


for _ in range(int(input())):
	n = int(input())
	mat = []
	for i in range(n):
		mat.append(list(input()))
	a = int(mat[0][1])
	b = int(mat[1][0])
	c = int(mat[n - 1][n - 2])
	d = int(mat[n - 2][n - 1])
	change = []
	if a == b:
		if c == d and c != a:
			do = 1
		elif c == d and c == a:
			change.append([n - 1, n - 2])
			change.append([n - 2, n - 1])
		elif c != d:
			if c == a:
				change.append([n - 1, n - 2])
			else:
				change.append([n - 2, n - 1])
	elif c == d:
		if a == c:
			change.append([0, 1])
		else:
			change.append([1, 0])
	else:
		if a != 0:
			change.append([0, 1])
		else:
			change.append([1, 0])
		if c != 1:
			change.append([n - 1, n - 2])
		else:
			change.append([n - 2, n - 1])
	print(len(change))
	for i in change:
		print(i[0] + 1, i[1] + 1)


from sys import stdin, stdout
from math import gcd
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = [input() for i in range(n)]
	ans = [(i, j) for (i, j) in [(0, 1), (1, 0), (n - 2, n - 1), (n - 1, n - 2)] if (a[i][j] == '0') ^ (min(i, j) == 0)]
	if len(ans) <= 2:
		print(len(ans))
		for i in ans:
			print(i[0] + 1, i[1] + 1)
	else:
		ans = [(i, j) for (i, j) in [(0, 1), (1, 0), (n - 2, n - 1), (n - 1, n - 2)] if (a[i][j] == '0') ^ (min(i, j) != 0)]
		print(len(ans))
		for i in ans:
			print(i[0] + 1, i[1] + 1)


for _ in range(int(input())):
	n = int(input())
	arr = []
	for i in range(n):
		temp = list(str(input()))
		arr.append(temp)
	change = []
	if arr[0][1] == arr[1][0]:
		if arr[0][1] == '1':
			if arr[n - 2][n - 1] != '0':
				change.append([n - 1, n])
			if arr[n - 1][n - 2] != '0':
				change.append([n, n - 1])
		else:
			if arr[n - 2][n - 1] != '1':
				change.append([n - 1, n])
			if arr[n - 1][n - 2] != '1':
				change.append([n, n - 1])
	elif arr[n - 2][n - 1] == arr[n - 1][n - 2]:
		if arr[n - 2][n - 1] == '1':
			if arr[0][1] != '0':
				change.append([1, 2])
			if arr[1][0] != '0':
				change.append([2, 1])
		else:
			if arr[0][1] != '1':
				change.append([1, 2])
			if arr[1][0] != '1':
				change.append([2, 1])
	else:
		if arr[0][1] != '0':
			change.append([1, 2])
		if arr[1][0] != '0':
			change.append([2, 1])
		if arr[n - 1][n - 2] != '1':
			change.append([n, n - 1])
		if arr[n - 2][n - 1] != '1':
			change.append([n - 1, n])
	print(len(change))
	for ar in change:
		ar = list(map(str, ar))
		l = ' '.join(ar)
		print(l)


t = int(input())
for i in range(t):
	n = int(input())
	r = []
	for j in range(n):
		temp = input()
		r.append(temp)
	(s1, s2) = (int(r[0][1]), int(r[1][0]))
	(f1, f2) = (int(r[-1][-2]), int(r[-2][-1]))
	if s1 == s2 and f1 == f2:
		if s1 != f1:
			print(0)
		else:
			print(2)
			print(1, 2)
			print(2, 1)
	elif s1 == s2 and f1 != f2:
		if s1 == f1:
			print(1)
			print(n, n - 1)
		else:
			print(1)
			print(n - 1, n)
	elif s1 != s2 and f1 == f2:
		if f1 == s1:
			print(1)
			print(1, 2)
		else:
			print(1)
			print(2, 1)
	elif s1 == f1:
		print(2)
		print(1, 2)
		print(n - 1, n)
	else:
		print(2)
		print(2, 1)
		print(n - 1, n)


cases = int(input())
for c in range(cases):
	n = int(input())
	mat = []
	for i in range(n):
		row = input()
		mat.append(row)
	r0c1 = mat[0][1]
	r1c0 = mat[1][0]
	rncp = mat[n - 1][n - 2]
	rpcn = mat[n - 2][n - 1]
	if r0c1 == r1c0:
		changes = []
		if rncp == r0c1:
			changes.append(str(n - 0) + ' ' + str(n - 1))
		if rpcn == r0c1:
			changes.append(str(n - 1) + ' ' + str(n - 0))
		print(len(changes))
		for u in changes:
			print(u)
	elif rncp == rpcn:
		changes = []
		if rncp == r0c1:
			changes.append('1' + ' ' + '2')
		if rpcn == r1c0:
			changes.append('2' + ' ' + '1')
		print(len(changes))
		for u in changes:
			print(u)
	else:
		changes = []
		if r0c1 != '0':
			changes.append('1' + ' ' + '2')
		if r1c0 != '0':
			changes.append('2' + ' ' + '1')
		if rncp != '1':
			changes.append(str(n - 0) + ' ' + str(n - 1))
		if rpcn != '1':
			changes.append(str(n - 1) + ' ' + str(n - 0))
		print(len(changes))
		for u in changes:
			print(u)


t = int(input())
while t > 0:
	n = int(input())
	grid = []
	for i in range(n):
		a = input()
		grid.append(a)
	lol = [grid[0][1], grid[0][2], grid[1][0], grid[2][0], grid[1][1]]
	ans1 = ['0', '1', '0', '1', '1']
	ans2 = ['1', '0', '1', '0', '0']
	count = 0
	l = []
	for i in range(5):
		if ans1[i] == lol[i]:
			l.append('0')
		else:
			count += 1
			l.append('1')
	if count < 3:
		print(count)
		if l[0] == '1':
			print('1 2')
		if l[1] == '1':
			print('1 3')
		if l[2] == '1':
			print('2 1')
		if l[3] == '1':
			print('3 1')
		if l[4] == '1':
			print('2 2')
	else:
		print(5 - count)
		if l[0] == '0':
			print('1 2')
		if l[1] == '0':
			print('1 3')
		if l[2] == '0':
			print('2 1')
		if l[3] == '0':
			print('3 1')
		if l[4] == '0':
			print('2 2')
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	l = []
	for i in range(n):
		l.append(input())
	(a, b) = (l[0][1], l[1][0])
	(x, y) = (l[n - 1][n - 2], l[n - 2][n - 1])
	if a == b:
		ans = 0
		k = []
		if x == a:
			k.append([n - 1 + 1, n - 2 + 1])
			ans += 1
		if y == a:
			k.append([n - 2 + 1, n - 1 + 1])
			ans += 1
		print(ans)
		for i in k:
			print(*i)
	elif x == y:
		ans = 0
		k = []
		if x == a:
			k.append([1, 2])
			ans += 1
		if y == b:
			k.append([2, 1])
			ans += 1
		print(ans)
		for i in k:
			print(*i)
	else:
		ans = 0
		k = []
		if a == '0':
			k.append([1, 2])
			ans += 1
		if b == '0':
			k.append([2, 1])
			ans += 1
		if x == '1':
			k.append([n - 1 + 1, n - 2 + 1])
			ans += 1
		if y == '1':
			k.append([n - 2 + 1, n - 1 + 1])
			ans += 1
		print(ans)
		for i in k:
			print(*i)


for _ in range(int(input())):
	n = int(input())
	grid = []
	for i in range(n):
		grid.append(list(input()))
	s1 = grid[0][1]
	s2 = grid[1][0]
	e1 = grid[n - 2][n - 1]
	e2 = grid[n - 1][n - 2]
	ans = []
	if s1 == s2:
		if e1 == s1:
			ans.append([n - 1, n])
		if e2 == s2:
			ans.append([n, n - 1])
	elif e1 != e2:
		if s1 == '1':
			ans.append([2, 1])
		else:
			ans.append([1, 2])
		if e1 == '1':
			ans.append([n - 1, n])
		else:
			ans.append([n, n - 1])
	elif e1 == '0':
		if s1 == '1':
			ans.append([2, 1])
		else:
			ans.append([1, 2])
	elif s1 == '0':
		ans.append([2, 1])
	else:
		ans.append([1, 2])
	print(len(ans))
	for i in ans:
		print(*i)


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = [list(input()) for _ in range(n)]
	ans = []
	if a[0][1] == a[1][0] == '0':
		if a[-2][-1] == '0':
			ans += [[n - 1, n]]
		if a[-1][-2] == '0':
			ans += [[n, n - 1]]
	elif a[0][1] == a[1][0] == '1':
		if a[-2][-1] == '1':
			ans += [[n - 1, n]]
		if a[-1][-2] == '1':
			ans += [[n, n - 1]]
	elif a[-1][-2] == a[-2][-1] == '0':
		if a[0][1] == '0':
			ans += [[1, 2]]
		if a[1][0] == '0':
			ans += [[2, 1]]
	elif a[-1][-2] == a[-2][-1] == '1':
		if a[0][1] == '1':
			ans += [[1, 2]]
		if a[1][0] == '1':
			ans += [[2, 1]]
	elif a[0][1] != a[-1][-2]:
		ans += [[1, 2], [n, n - 1]]
	elif a[0][1] != a[-2][-1]:
		ans += [[1, 2], [n - 1, n]]
	print(len(ans))
	for (k, v) in ans:
		print(k, v)


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))
for _ in range(inp()):
	n = inp()
	s = [input() for _ in range(n)]
	ind = [(0, 1), (1, 0), (n - 2, n - 1), (n - 1, n - 2)]
	for pt in ['0011', '1100']:
		cnt = 0
		res = []
		for (i, (y, x)) in enumerate(ind):
			if pt[i] != s[y][x]:
				cnt += 1
				res.append((y, x))
		if cnt <= 2:
			print(cnt)
			for (y, x) in res:
				print(y + 1, x + 1)
			break


import sys
t = int(input())
for _ in range(t):
	n = int(input())
	arr = []
	for _ in range(n):
		arr.append(list(input()))
	candidate = [[1, 2], [2, 1], [n - 1, n], [n, n - 1]]
	ans = [arr[0][1], arr[1][0], arr[n - 2][n - 1], arr[n - 1][n - 2]]
	tmp = [['1', '1', '0', '0'], ['0', '0', '1', '1']]
	for i in range(2):
		realAns = []
		for j in range(4):
			if tmp[i][j] != ans[j]:
				realAns.append(candidate[j])
		if len(realAns) <= 2:
			break
	print(len(realAns))
	for x in realAns:
		print('%d %d' % (x[0], x[1]))


import sys, collections, itertools, copy

def bfs(num):
	check = [[False] * n for _ in range(n)]
	q = collections.deque()
	q.append((0, 0))
	check[0][0] = True
	while q:
		(x, y) = q.popleft()
		if x == n - 1 and y == n - 1:
			return True
		for i in range(4):
			(nx, ny) = (x + dx[i], y + dy[i])
			if 0 <= nx < n and 0 <= ny < n:
				if temp[nx][ny] != num:
					if not check[nx][ny]:
						check[nx][ny] = True
						q.append((nx, ny))
	return False
tc = int(sys.stdin.readline())
dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]
for _ in range(tc):
	n = int(sys.stdin.readline())
	arr = [list(sys.stdin.readline().rstrip()) for _ in range(n)]
	find = False
	for i in itertools.combinations([(0, 1), (1, 0), (n - 2, n - 1), (n - 1, n - 2)], 2):
		temp = copy.deepcopy(arr)
		for j in i:
			if temp[j[0]][j[1]] == '1':
				temp[j[0]][j[1]] = '0'
			else:
				temp[j[0]][j[1]] = '1'
		if not bfs('0') and (not bfs('1')):
			find = True
			print(2)
			for j in i:
				print(j[0] + 1, j[1] + 1)
			break
	if not find:
		for i in [(0, 1), (1, 0), (n - 2, n - 1), (n - 1, n - 2)]:
			temp = copy.deepcopy(arr)
			if temp[i[0]][i[1]] == '1':
				temp[i[0]][i[1]] = '0'
			else:
				temp[i[0]][i[1]] = '1'
			if not bfs('0') and (not bfs('1')):
				find = True
				print(1)
				print(i[0] + 1, i[1] + 1)
				break
	if not find:
		print(0)


t = int(input())
while t:
	n = int(input())
	s = [list(input()) for x in range(n)]
	c = 0
	x1 = y1 = x2 = y2 = -1
	if s[0][1] == s[1][0]:
		if s[n - 1][n - 2] == s[0][1]:
			(x1, y1) = (n, n - 1)
			c += 1
		if s[n - 2][n - 1] == s[0][1]:
			(x2, y2) = (n - 1, n)
			c += 1
		print(c)
		if x1 != -1:
			print(x1, y1)
		if x2 != -1:
			print(x2, y2)
	elif s[n - 1][n - 2] == s[n - 2][n - 1]:
		if s[n - 1][n - 2] == s[0][1]:
			c += 1
			(x1, y1) = (1, 2)
		if s[n - 1][n - 2] == s[1][0]:
			c += 1
			(x2, y2) = (2, 1)
		print(c)
		if x1 != -1:
			print(x1, y1)
		if x2 != -1:
			print(x2, y2)
	else:
		c = 2
		if s[n - 1][n - 2] == s[0][1]:
			(x1, y1, x2, y2) = (n, n - 1, 2, 1)
		elif s[n - 1][n - 2] == s[1][0]:
			(x1, y1, x2, y2) = (n, n - 1, 1, 2)
		print(c)
		print(x1, y1)
		print(x2, y2)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	strs = [list(input()) for _ in range(n)]
	startright = strs[0][1]
	startdown = strs[1][0]
	endup = strs[n - 2][n - 1]
	endleft = strs[n - 1][n - 2]
	ans = []
	if startright == startdown:
		if endup == startright:
			ans += [(n - 1, n)]
		if endleft == startright:
			ans += [(n, n - 1)]
	elif endleft == endup:
		if startright == endleft:
			ans += [(1, 2)]
		if startdown == endleft:
			ans += [(2, 1)]
	else:
		if startright == '0':
			ans += [(1, 2)]
		if startdown == '0':
			ans += [(2, 1)]
		if endleft == '1':
			ans += [(n, n - 1)]
		if endup == '1':
			ans += [(n - 1, n)]
	print(len(ans))
	for res in ans:
		print(*res)


for t in range(int(input())):
	n = int(input())
	sr = 0
	sd = 0
	fu = 0
	fl = 0
	for i in range(n):
		l = input()
		if i == 0:
			sr = l[1]
		elif i == 1:
			sd = l[0]
		if i == n - 2:
			fu = l[n - 1]
		elif i == n - 1:
			fl = l[n - 2]
	ans = []
	if fu == fl:
		if sr == fu:
			ans += [[1, 2]]
		if sd == fu:
			ans += [[2, 1]]
	elif fu != fl:
		if sd == sr:
			if sr == fu:
				ans += [[n - 1, n]]
			if sr == fl:
				ans += [[n, n - 1]]
		elif sd == fu:
			ans += [[2, 1]]
			ans += [[n, n - 1]]
		elif sd == fl:
			ans += [[2, 1]]
			ans += [[n - 1, n]]
	print(len(ans))
	for i in ans:
		print(str(i[0]), str(i[1]))


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from collections import Counter
from collections import defaultdict as dd
inp = lambda : int(input())
strng = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
strl = lambda : list(input().strip())
mul = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
seq = lambda : list(map(int, input().strip().split()))
ceil = lambda x: int(x) if x == int(x) else int(x) + 1
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
stdarr = lambda : map(int, stdstr().split())
mod = 1000000007
for _ in range(stdint()):
	n = stdint()
	matrix = []
	for __ in range(n):
		row = input()
		matrix.append(row)
	m1 = ['S01' + 'x' * (n - 3), '01' + 'x' * (n - 2), '1' + 'x' * (n - 1)]
	m2 = ['S10' + 'x' * (n - 3), '10' + 'x' * (n - 2), '0' + 'x' * (n - 1)]
	points = dd(list)
	d1 = []
	for i in range(3):
		for j in range(3):
			if m1[i][j] != 'x':
				if m1[i][j] != matrix[i][j]:
					d1.append((i + 1, j + 1))
	d2 = []
	for i in range(3):
		for j in range(3):
			if m2[i][j] != 'x':
				if m2[i][j] != matrix[i][j]:
					d2.append((i + 1, j + 1))
	if len(d1) <= 2:
		print(len(d1))
		for i in d1:
			print(*i)
	else:
		print(len(d2))
		for i in d2:
			print(*i)


for _ in range(int(input())):
	a = []
	for i in range(int(input())):
		a.append(input())
	if a[0][1] == '1' and a[1][0] == '1' and (a[-1][-2] == '1') and (a[-2][-1] == '1') or (a[0][1] == '0' and a[1][0] == '0' and (a[-1][-2] == '0') and (a[-2][-1] == '0')):
		print(2)
		print(1, 2)
		print(2, 1)
	elif a[0][1] == '0' and a[1][0] == '1' and (a[-1][-2] == '1') and (a[-2][-1] == '1') or (a[0][1] == '1' and a[1][0] == '0' and (a[-1][-2] == '0') and (a[-2][-1] == '0')):
		print(1)
		print(2, 1)
	elif a[0][1] == '1' and a[1][0] == '0' and (a[-1][-2] == '1') and (a[-2][-1] == '1') or (a[0][1] == '0' and a[1][0] == '1' and (a[-1][-2] == '0') and (a[-2][-1] == '0')):
		print(1)
		print(1, 2)
	elif a[0][1] == '1' and a[1][0] == '1' and (a[-1][-2] == '0') and (a[-2][-1] == '1') or (a[0][1] == '0' and a[1][0] == '0' and (a[-1][-2] == '1') and (a[-2][-1] == '0')):
		print(1)
		print(len(a) - 1, len(a))
	elif a[0][1] == '1' and a[1][0] == '1' and (a[-1][-2] == '1') and (a[-2][-1] == '0') or (a[0][1] == '0' and a[1][0] == '0' and (a[-1][-2] == '0') and (a[-2][-1] == '1')):
		print(1)
		print(len(a), len(a) - 1)
	elif a[0][1] == '0' and a[1][0] == '0' and (a[-1][-2] == '1') and (a[-2][-1] == '1') or (a[0][1] == '1' and a[1][0] == '1' and (a[-1][-2] == '0') and (a[-2][-1] == '0')):
		print(0)
	elif a[0][1] == '1' and a[1][0] == '0' and (a[-1][-2] == '1') and (a[-2][-1] == '0') or (a[0][1] == '0' and a[1][0] == '1' and (a[-1][-2] == '0') and (a[-2][-1] == '1')):
		print(2)
		print(1, 2)
		print(len(a) - 1, len(a))
	elif a[0][1] == '1' and a[1][0] == '0' and (a[-1][-2] == '0') and (a[-2][-1] == '1') or (a[0][1] == '0' and a[1][0] == '1' and (a[-1][-2] == '1') and (a[-2][-1] == '0')):
		print(2)
		print(1, 2)
		print(len(a), len(a) - 1)


t = int(input())
for _ in range(t):
	n = int(input())
	tab = list()
	for i in range(n):
		s = str(input())
		tab.append(s)
	if tab[0][1] == tab[1][0] and tab[0][1] == '1':
		if tab[n - 1][n - 2] == tab[n - 2][n - 1]:
			if tab[n - 1][n - 2] == '1':
				print(2)
				print(n - 1, n)
				print(n, n - 1)
			else:
				print(0)
		else:
			print(1)
			if tab[n - 1][n - 2] == '1':
				print(n, n - 1)
			else:
				print(n - 1, n)
	elif tab[0][1] == tab[1][0] and tab[0][1] == '0':
		if tab[n - 1][n - 2] == tab[n - 2][n - 1]:
			if tab[n - 1][n - 2] == '0':
				print(2)
				print(n - 1, n)
				print(n, n - 1)
			else:
				print(0)
		else:
			print(1)
			if tab[n - 1][n - 2] == '0':
				print(n, n - 1)
			else:
				print(n - 1, n)
	elif tab[0][1] != tab[1][0] and tab[0][1] == '1':
		if tab[n - 1][n - 2] == tab[n - 2][n - 1]:
			if tab[n - 1][n - 2] == '0':
				print(1)
				print(2, 1)
			else:
				print(1)
				print(1, 2)
		elif tab[n - 1][n - 2] == '0':
			print(2)
			print(2, 1)
			print(n - 1, n)
		else:
			print(2)
			print(2, 1)
			print(n, n - 1)
	elif tab[n - 1][n - 2] == tab[n - 2][n - 1]:
		if tab[n - 1][n - 2] == '1':
			print(1)
			print(2, 1)
		else:
			print(1)
			print(1, 2)
	elif tab[n - 1][n - 2] == '1':
		print(2)
		print(2, 1)
		print(n - 1, n)
	else:
		print(2)
		print(2, 1)
		print(n, n - 1)


T = int(input())
for t in range(T):
	m = []
	n = int(input())
	for i in range(n):
		s = list(input())
		m.append(s)
	p = [m[1][0], m[0][1], m[n - 2][n - 1], m[n - 1][n - 2]]
	result = []
	if p[0] == p[1]:
		if p[2] == p[0]:
			result.append(2)
		if p[3] == p[0]:
			result.append(3)
	elif p[2] == p[3]:
		if p[2] == p[0]:
			result.append(0)
		if p[2] == p[1]:
			result.append(1)
	else:
		result.append(1)
		if p[2] == p[0]:
			result.append(2)
		if p[3] == p[0]:
			result.append(3)
	print(len(result))
	for r in result:
		if r == 0:
			print('2 1')
		if r == 1:
			print('1 2')
		if r == 2:
			print(str(n - 2 + 1) + ' ' + str(n - 1 + 1))
		if r == 3:
			print(str(n - 1 + 1) + ' ' + str(n - 2 + 1))


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = []
	for i in range(n):
		line = list(input())
		a.append(line)
	(x, y, z, w) = (a[0][1], a[1][0], a[n - 2][n - 1], a[n - 1][n - 2])
	if x == y and z == w:
		if x != z:
			print(0)
			continue
		elif x == z:
			print(2)
			print('1 2')
			print('2 1')
			continue
	elif x == y and z != w:
		if x == z:
			print(1)
			print(str(n - 1) + ' ' + str(n))
			continue
		else:
			print(1)
			print(str(n) + ' ' + str(n - 1))
			continue
	elif x != y and z == w:
		if x == z:
			print(1)
			print('1 2')
			continue
		else:
			print(1)
			print('2 1')
			continue
	elif x != y and z != w:
		if x == z:
			print(2)
			print('1 2')
			print(str(n) + ' ' + str(n - 1))
			continue
		else:
			print(2)
			print('1 2')
			print(str(n - 1) + ' ' + str(n))
			continue


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey, reverse=True)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def ceil(x, y):
	if x % y == 0:
		return x // y
	else:
		return x // y + 1

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def main():
	for _ in range(ii()):
		n = ii()
		l = []
		for i in range(n):
			l.append(si())
		x1 = int(l[0][1]) + int(l[1][0])
		x2 = int(l[n - 1][n - 2]) + int(l[n - 2][n - 1])
		if x1 == 2 and x2 == 0 or (x1 == 0 and x2 == 2):
			print(0)
			continue
		if x1 == 0 and x2 == 0 or (x1 == 2 and x2 == 2):
			print(2)
			print(1, 2)
			print(2, 1)
			continue
		x = []
		x.append([int(l[0][1]), 1, 2])
		x.append([int(l[1][0]), 2, 1])
		x.append([int(l[n - 1][n - 2]), n, n - 1])
		x.append([int(l[n - 2][n - 1]), n - 1, n])
		if x1 == 1 and x2 == 1:
			ans = []
			for i in range(2):
				if x[i][0] == 1:
					ans.append([x[i][1], x[i][2]])
			for i in range(2, 4):
				if x[i][0] == 0:
					ans.append([x[i][1], x[i][2]])
			print(len(ans))
			for i in ans:
				print(*i)
			continue
		if x[0][0] == x[1][0] and x[2][0] != x[3][0]:
			ans = []
			for i in range(2, 4):
				if x[i][0] == x[0][0]:
					ans.append([x[i][1], x[i][2]])
			print(len(ans))
			for i in ans:
				print(*i)
			continue
		if x[0][0] != x[1][0] and x[2][0] == x[3][0]:
			ans = []
			for i in range(2):
				if x[i][0] == x[2][0]:
					ans.append([x[i][1], x[i][2]])
			print(len(ans))
			for i in ans:
				print(*i)
			continue
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7

def lcm(x, y):
	return x * y / gcd(x, y)

def fact(x, mod=mod):
	ans = 1
	for i in range(1, x + 1):
		ans = ans * i % mod
	return ans

def arr2D(n, m, default=0):
	return [[default for j in range(m)] for i in range(n)]

def arr3D(n, m, r, default=0):
	return [[[default for k in range(r)] for j in range(m)] for i in range(n)]

def sortDictV(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}

def solve(n, lst):
	ans = []
	if lst[0][1] == '1':
		if lst[1][0] == '0':
			ans.append([2, 1])
		if lst[n - 1][n - 2] == '1':
			ans.append([n, n - 1])
		if lst[n - 2][n - 1] == '1':
			ans.append([n - 1, n])
	else:
		if lst[1][0] == '1':
			ans.append([2, 1])
		if lst[n - 1][n - 2] == '0':
			ans.append([n, n - 1])
		if lst[n - 2][n - 1] == '0':
			ans.append([n - 1, n])
	if len(ans) > 2:
		print(1)
		print(1, 2)
	else:
		print(len(ans))
		for i in ans:
			print(i[0], i[1])
for _ in range(int(input())):
	n = int(input())
	lst = []
	for i in range(n):
		lst.append(list(input()))
	solve(n, lst)


t = int(input())
while t != 0:
	n = int(input())
	list1 = []
	for i in range(n):
		temp = list(input())
		list1.append(temp)
	s1 = list1[0][1]
	s2 = list1[1][0]
	l1 = list1[-2][-1]
	l2 = list1[-1][-2]
	ans = []
	if s1 == s2:
		if s1 == '0':
			if l1 == '0':
				ans.append([n - 1, n])
			if l2 == '0':
				ans.append([n, n - 1])
		else:
			if l1 == '1':
				ans.append([n - 1, n])
			if l2 == '1':
				ans.append([n, n - 1])
	elif l1 == l2:
		if l1 == '0':
			if s1 == '0':
				ans.append([1, 2])
			if s2 == '0':
				ans.append([2, 1])
		else:
			if s1 == '1':
				ans.append([1, 2])
			if s2 == '1':
				ans.append([2, 1])
	elif s1 == '0':
		ans.append([2, 1])
		if l1 == '0':
			ans.append([n - 1, n])
		if l2 == '0':
			ans.append([n, n - 1])
	else:
		ans.append([1, 2])
		if l1 == '0':
			ans.append([n - 1, n])
		if l2 == '0':
			ans.append([n, n - 1])
	print(len(ans))
	for i in range(len(ans)):
		print(*ans[i])
	t -= 1


from collections import deque
from heapq import heapify, heappush, heappop
t = int(input())
for _ in range(t):
	n = int(input())
	ar = []
	for _ in range(n):
		ar.append(input())
	kek = [ar[1][0], ar[0][1], ar[-1][-2], ar[-2][-1]]
	kek = list(map(int, kek))
	p = kek[0] + kek[1]
	z = kek[2] + kek[3]
	res = []
	if p == 0:
		if kek[2] == 0:
			res.append((n, n - 1))
		if kek[3] == 0:
			res.append((n - 1, n))
	if p == 2:
		if kek[2] == 1:
			res.append((n, n - 1))
		if kek[3] == 1:
			res.append((n - 1, n))
	if p == 1:
		if z == 1:
			if kek[0] == 1:
				res.append((2, 1))
			if kek[1] == 1:
				res.append((1, 2))
			if kek[2] == 0:
				res.append((n, n - 1))
			if kek[3] == 0:
				res.append((n - 1, n))
		else:
			if z == 0:
				if kek[0] == 0:
					res.append((2, 1))
				if kek[1] == 0:
					res.append((1, 2))
			if z == 2:
				if kek[0] == 1:
					res.append((2, 1))
				if kek[1] == 1:
					res.append((1, 2))
	print(len(res))
	for x in res:
		print(x[0], x[1])


for _ in range(int(input())):
	n = int(input())
	grid = []
	v1 = []
	v0 = []
	for i in range(n):
		r = input()
		grid.append(r)
	st = grid[0][1] + grid[1][0]
	en = grid[n - 1][n - 2] + grid[n - 2][n - 1]
	s_z = st.count('0')
	e_z = en.count('0')
	if abs(s_z - e_z) == 2:
		print(0)
		continue
	if s_z == e_z:
		print(2)
		if '0' not in st or '1' not in st:
			print(1, 2)
			print(2, 1)
			continue
		if grid[0][1] == '0':
			print(1, 2)
		else:
			print(2, 1)
		if grid[n - 1][n - 2] == '0':
			print(n - 1, n)
		else:
			print(n, n - 1)
	else:
		print(1)
		if '0' not in st:
			if grid[n - 1][n - 2] == '0':
				print(n - 1, n)
			else:
				print(n, n - 1)
			continue
		if '1' not in st:
			if grid[n - 1][n - 2] == '1':
				print(n - 1, n)
			else:
				print(n, n - 1)
			continue
		if '0' not in en:
			if grid[0][1] == '0':
				print(2, 1)
			else:
				print(1, 2)
			continue
		if '1' not in en:
			if grid[0][1] == '1':
				print(2, 1)
			else:
				print(1, 2)
			continue


for _ in range(int(input())):
	n = int(input())
	l = []
	for i in range(n):
		t = list(input())
		l.append(t)
	if l[0][1] == '0' and l[1][0] == '0':
		c = 0
		out = []
		if l[n - 1][n - 2] == '0':
			c += 1
			out.append((n, n - 1))
		if l[n - 2][n - 1] == '0':
			c += 1
			out.append((n - 1, n))
		print(c)
		for i in out:
			print(i[0], i[1])
	elif l[0][1] == '1' and l[1][0] == '1':
		c = 0
		out = []
		if l[n - 1][n - 2] == '1':
			c += 1
			out.append((n, n - 1))
		if l[n - 2][n - 1] == '1':
			c += 1
			out.append((n - 1, n))
		print(c)
		for i in out:
			print(i[0], i[1])
	elif l[0][1] == '0':
		if l[n - 1][n - 2] == '0' and l[n - 2][n - 1] == '0':
			print(1)
			print(1, 2)
		elif l[n - 1][n - 2] == '1' and l[n - 2][n - 1] == '1':
			print(1)
			print(2, 1)
		else:
			print(2)
			print(2, 1)
			if l[n - 1][n - 2] == '0':
				print(n, n - 1)
			elif l[n - 2][n - 1] == '0':
				print(n - 1, n)
	elif l[1][0] == '0':
		if l[n - 1][n - 2] == '0' and l[n - 2][n - 1] == '0':
			print(1)
			print(2, 1)
		elif l[n - 1][n - 2] == '1' and l[n - 2][n - 1] == '1':
			print(1)
			print(1, 2)
		else:
			print(2)
			print(1, 2)
			if l[n - 1][n - 2] == '0':
				print(n, n - 1)
			elif l[n - 2][n - 1] == '0':
				print(n - 1, n)


for _ in range(int(input())):
	n = int(input())
	l = list()
	for i in range(n):
		l.append(input())
	(a, b) = (l[0][1], l[1][0])
	(x, y) = (l[n - 1][n - 2], l[n - 2][n - 1])
	if a == b and x == y:
		if a != x:
			print(0)
		else:
			print(2)
			print(1, 2)
			print(2, 1)
	elif a == b:
		if a == x and x != y:
			print(1)
			print(n, n - 1)
		elif a == y and x != y:
			print(1)
			print(n - 1, n)
		elif a == x and a == y:
			print(2)
			print(n, n - 1)
			print(n - 1, n)
	elif x == y:
		if a == x and a != b:
			print(1)
			print(1, 2)
		elif b == x and a != b:
			print(1)
			print(2, 1)
		elif a == x and a == y:
			print(2)
			print(n, n - 1)
			print(n - 1, n)
	else:
		print(2)
		if a == x:
			print(1, 2)
			print(n - 1, n)
		elif a == y:
			print(1, 2)
			print(n, n - 1)


def main():
	n = int(input())
	lst = []
	for i in range(n):
		line = input()
		lst.append(line)
	top_left = lst[0][1]
	top_right = lst[1][0]
	bot_left = lst[n - 1][n - 2]
	bot_right = lst[n - 2][n - 1]
	if top_left == top_right:
		if bot_left == bot_right and bot_left == top_left:
			print(2)
		elif bot_left != bot_right:
			print(1)
		else:
			print(0)
		if bot_left == top_left:
			print(n, n - 1)
		if bot_right == top_right:
			print(n - 1, n)
	elif bot_left == bot_right:
		print(1)
		if bot_left == top_left:
			print(1, 2)
		if bot_right == top_right:
			print(2, 1)
	else:
		print(2)
		print(2, 1)
		if bot_left == top_left:
			print(n, n - 1)
		else:
			print(n - 1, n)

def __starting_point():
	t = int(input())
	for i in range(t):
		main()
__starting_point()


from sys import stdin, stdout
import math
from collections import deque
input = stdin.readline

def print(*args, end='\n'):
	s = []
	for i in args:
		s.append(str(i) + ' ')
	s = ''.join(s)
	stdout.write(s + end)

def solve():
	n = int(input())
	mat = []
	for i in range(n):
		mat.append(list(input()))
	ans = []
	if mat[0][1] == mat[1][0] and mat[n - 1][n - 2] == mat[n - 2][n - 1] and (mat[n - 1][n - 2] != mat[0][1]):
		print(0)
		return
	elif mat[0][1] == mat[1][0] and mat[n - 1][n - 2] == mat[n - 2][n - 1] and (mat[n - 1][n - 2] == mat[0][1]):
		print(2)
		print(1, 2)
		print(2, 1)
		return
	if mat[0][1] == mat[1][0] or mat[n - 1][n - 2] == mat[n - 2][n - 1]:
		if mat[0][1] == mat[1][0]:
			if mat[n - 2][n - 1] == mat[0][1]:
				print(1)
				print(n - 1, n)
			else:
				print(1)
				print(n, n - 1)
		elif mat[0][1] == mat[n - 1][n - 2]:
			print(1)
			print(1, 2)
		else:
			print(1)
			print(2, 1)
	elif mat[0][1] == mat[n - 1][n - 2]:
		print(2)
		print(1, 2)
		print(n - 1, n)
	elif mat[1][0] == mat[n - 2][n - 1]:
		print(2)
		print(2, 1)
		print(n, n - 1)
	elif mat[1][0] == mat[n - 1][n - 2]:
		print(2)
		print(2, 1)
		print(n - 1, n)
	else:
		print(2)
		print(1, 2)
		print(n, n - 1)
tt = 1
tt = int(input())
for __ in range(tt):
	solve()


from math import *
from sys import *
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	m = []
	ans = []
	for i in range(n):
		a = list(input())
		m.append(a)
	x = m[0][1]
	a = 0
	f = 0
	if m[n - 1][n - 2] == x and m[n - 2][n - 1] == x:
		a += 1
		ans.append([1, 2])
		if x == 0:
			m[0][1] = 1
		else:
			m[0][1] = 0
	elif m[n - 1][n - 2] == x and m[n - 2][n - 1] != x:
		a += 1
		ans.append([n, n - 1])
		f = 1
	elif m[n - 1][n - 2] != x and m[n - 2][n - 1] == x:
		a += 1
		ans.append([n - 1, n])
		f = 1
	if m[1][0] != m[0][1]:
		if f == 1:
			ans.append([2, 1])
			a += 1
		elif m[1][0] == m[n - 1][n - 2]:
			ans.append([2, 1])
			a += 1
	print(a)
	for i in range(a):
		print(*ans[i])


import sys
for i in range(0, int(sys.stdin.readline())):
	msize = int(sys.stdin.readline())
	for j in range(0, msize):
		q = sys.stdin.readline()
		if j == 0:
			a = int(q[1])
		elif j == 1:
			b = int(q[0])
		if j == msize - 2:
			c = int(q[msize - 1])
		elif j == msize - 1:
			d = int(q[msize - 2])
	if a == b:
		if c == d:
			if a == c:
				sys.stdout.write('2\n')
				sys.stdout.write('1 2\n2 1\n')
			else:
				sys.stdout.write('0\n')
				pass
		else:
			sys.stdout.write('1\n')
			if a == c:
				sys.stdout.write(str(msize - 1) + ' ' + str(msize) + '\n')
			else:
				sys.stdout.write(str(msize) + ' ' + str(msize - 1) + '\n')
	elif c == d:
		sys.stdout.write('1\n')
		if a == c:
			sys.stdout.write('1 2\n')
		else:
			sys.stdout.write('2 1\n')
	else:
		sys.stdout.write('2\n')
		sys.stdout.write('1 2\n')
		if a == c:
			sys.stdout.write(str(msize) + ' ' + str(msize - 1) + '\n')
		else:
			sys.stdout.write(str(msize - 1) + ' ' + str(msize) + '\n')


import time, math as mt, bisect as bs, sys
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

def II():
	return int(stdin.readline())

def IP():
	return map(int, stdin.readline().split())

def L():
	return list(map(int, stdin.readline().split()))

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

def lcm(a, b):
	return a * b // gcd(a, b)

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * (2 * 10 ** 5 + 5)
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(2 * 10 ** 5 + 5):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count
mx = 10 ** 7
spf = [mx] * (mx + 1)

def SPF():
	spf[1] = 1
	for i in range(2, mx + 1):
		if spf[i] == mx:
			spf[i] = i
			for j in range(i * i, mx + 1, i):
				if i < spf[j]:
					spf[j] = i
	return

def readTree(n, e):
	adj = [set() for i in range(n + 1)]
	for i in range(e):
		(u1, u2) = IP()
		adj[u1].add(u2)
	return adj
mod = 10 ** 9 + 7

def solve():
	n = II()
	li = []
	for i in range(n):
		s = input()
		li.append(s)
	(w, x, y, z) = (li[0], li[1], li[-2], li[-1])
	cnt = 0
	ans = []
	if w[1] == '0' and x[0] == '0':
		if y[-1] != '1':
			cnt += 1
			ans.append([n - 1, n])
		if z[-2] != '1':
			cnt += 1
			ans.append([n, n - 1])
	elif w[1] == '1' and x[0] == '1':
		if y[-1] != '0':
			cnt += 1
			ans.append([n - 1, n])
		if z[-2] != '0':
			cnt += 1
			ans.append([n, n - 1])
	elif w[1] == '1' and x[0] == '0':
		if y[-1] == '1' and z[-2] == '1':
			cnt += 1
			ans.append([1, 2])
		elif y[-1] == '0' and z[-2] == '0':
			cnt += 1
			ans.append([2, 1])
		else:
			cnt += 1
			ans.append([2, 1])
			cnt += 1
			if y[-1] == '1':
				ans.append([n - 1, n])
			else:
				ans.append([n, n - 1])
	elif y[-1] == '1' and z[-2] == '1':
		cnt += 1
		ans.append([2, 1])
	elif y[-1] == '0' and z[-2] == '0':
		cnt += 1
		ans.append([1, 2])
	else:
		cnt += 1
		ans.append([1, 2])
		cnt += 1
		if y[-1] == '1':
			ans.append([n - 1, n])
		else:
			ans.append([n, n - 1])
	print(cnt)
	if cnt > 0:
		for ele in ans:
			print(*ele)
	return
t = II()
for i in range(t):
	solve()


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c for j in range(b)] for i in range(a)]

def list3d(a, b, c, d):
	return [[[d for k in range(c)] for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e for l in range(d)] for k in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** (-10)
for _ in range(INT()):
	N = INT()
	grid = [[]] * N
	for i in range(N):
		grid[i] = list(input())
	s1 = grid[0][1]
	s2 = grid[1][0]
	g1 = grid[N - 1][N - 2]
	g2 = grid[N - 2][N - 1]
	ans = []
	if s1 == s2 == '0':
		if g1 == '0':
			ans.append((N, N - 1))
		if g2 == '0':
			ans.append((N - 1, N))
	elif s1 == '1' and s2 == '0':
		if g1 == g2 == '1':
			ans.append((1, 2))
		elif g1 == g2 == '0':
			ans.append((2, 1))
		elif g1 == '1' and g2 == '0':
			ans.append((2, 1))
			ans.append((N, N - 1))
		elif g1 == '0' and g2 == '1':
			ans.append((2, 1))
			ans.append((N - 1, N))
	elif s1 == '0' and s2 == '1':
		if g1 == g2 == '1':
			ans.append((2, 1))
		elif g1 == g2 == '0':
			ans.append((1, 2))
		elif g1 == '1' and g2 == '0':
			ans.append((1, 2))
			ans.append((N, N - 1))
		elif g1 == '0' and g2 == '1':
			ans.append((1, 2))
			ans.append((N - 1, N))
	else:
		if g1 == '1':
			ans.append((N, N - 1))
		if g2 == '1':
			ans.append((N - 1, N))
	print(len(ans))
	for a in ans:
		print(*a)


for t in range(int(input())):
	s = []
	n = int(input())
	for i in range(n):
		s.append(input())
	n = n - 1
	seti = {s[0][1], s[1][0], s[n][n - 1], s[n - 1][n]}
	if seti == {'1'} or seti == {'0'}:
		print(2)
		print('1 2')
		print('2 1')
	elif s[0][1] == s[1][0] and s[n][n - 1] == s[n - 1][n]:
		print(0)
	elif s[0][1] == s[n][n - 1] and s[1][0] == s[n - 1][n]:
		print(2)
		print('1 2')
		print('%i %i' % (n, n + 1))
	elif s[0][1] == s[n - 1][n] and s[1][0] == s[n][n - 1]:
		print(2)
		print('1 2')
		print('%i %i' % (n + 1, n))
	elif s[0][1] != s[1][0]:
		print(1)
		if s[0][1] == s[n][n - 1]:
			print('1 2')
		else:
			print('2 1')
	elif s[n][n - 1] != s[n - 1][n]:
		print(1)
		if s[0][1] == s[n][n - 1]:
			print('%i %i' % (n + 1, n))
		else:
			print('%i %i' % (n, n + 1))


T = int(input())
for Tid in range(T):
	n = int(input())
	a = []
	for i in range(n):
		a.append(input())
	(a0, a1, a2) = ([], [], [])

	def add(x, y, c):
		if a[x][y] == c:
			a0.append([x + 1, y + 1])
		else:
			a1.append([x + 1, y + 1])
	add(0, 1, '0')
	add(1, 0, '0')
	add(n - 1, n - 2, '1')
	add(n - 2, n - 1, '1')
	if len(a0) < len(a1):
		a2 = a0
	else:
		a2 = a1
	print(len(a2))
	for i in range(len(a2)):
		print(a2[i][0], a2[i][1])


t = int(input())
for x in range(t):
	n = int(input())
	s = [0]
	for i in range(n):
		s.append(' ' + input())
	if s[1][2] == '0' and s[2][1] == '0':
		s1 = False
		if s[n - 1][n] == '1':
			s1 = True
		s2 = False
		if s[n][n - 1] == '1':
			s2 = True
		if s1 and s2:
			print(0)
		elif s1:
			print(1)
			print(n, n - 1)
		elif s2:
			print(1)
			print(n - 1, n)
		else:
			print(2)
			print(1, 2)
			print(2, 1)
		continue
	if s[1][2] == '1' and s[2][1] == '1':
		s1 = False
		if s[n - 1][n] == '1':
			s1 = True
		s2 = False
		if s[n][n - 1] == '1':
			s2 = True
		if s1 and s2:
			print(2)
			print(1, 2)
			print(2, 1)
		elif s1:
			print(1)
			print(n - 1, n)
		elif s2:
			print(1)
			print(n, n - 1)
		else:
			print(0)
		continue
	if s[1][2] == '1' and s[2][1] == '0':
		s1 = False
		if s[n - 1][n] == '1':
			s1 = True
		s2 = False
		if s[n][n - 1] == '1':
			s2 = True
		if s1 and s2:
			print(1)
			print(1, 2)
		elif s1:
			print(2)
			print(1, 2)
			print(n, n - 1)
		elif s2:
			print(2)
			print(1, 2)
			print(n - 1, n)
		else:
			print(1)
			print(2, 1)
		continue
	if s[1][2] == '0' and s[2][1] == '1':
		s1 = False
		if s[n - 1][n] == '1':
			s1 = True
		s2 = False
		if s[n][n - 1] == '1':
			s2 = True
		if s1 and s2:
			print(1)
			print(2, 1)
		elif s1:
			print(2)
			print(1, 2)
			print(n - 1, n)
		elif s2:
			print(2)
			print(1, 2)
			print(n, n - 1)
		else:
			print(1)
			print(1, 2)
		continue


cases = int(input())
for t in range(cases):
	n = int(input())
	s = []
	for i in range(n):
		s.append(list(input()))
	l = [int(s[-1][-3]), int(s[-1][-2]), int(s[-2][-2]), int(s[-2][-1]), int(s[-3][-1])]
	l1 = [1, 0, 1, 0, 1]
	l2 = [0, 1, 0, 1, 0]
	o1 = [l1[i] != l[i] for i in range(5)]
	o2 = [l2[i] != l[i] for i in range(5)]
	so1 = sum(o1)
	so2 = sum(o2)
	if so1 <= so2:
		print(so1)
		if so1:
			if o1[0]:
				print(n, n - 2)
			if o1[1]:
				print(n, n - 1)
			if o1[2]:
				print(n - 1, n - 1)
			if o1[3]:
				print(n - 1, n)
			if o1[4]:
				print(n - 2, n)
	else:
		print(so2)
		if so2:
			if o2[0]:
				print(n, n - 2)
			if o2[1]:
				print(n, n - 1)
			if o2[2]:
				print(n - 1, n - 1)
			if o2[3]:
				print(n - 1, n)
			if o2[4]:
				print(n - 2, n)


t = int(input())
for case in range(t):
	n = int(input())
	grid = [input() for row in range(n)]
	cnt = 0
	ans = []
	if grid[0][1] == grid[1][0]:
		g = 1 - int(grid[0][1])
		if int(grid[-1][-2]) != g:
			ans.append((n, n - 1))
		if int(grid[-2][-1]) != g:
			ans.append((n - 1, n))
	elif grid[-1][-2] == grid[-2][-1]:
		g = 1 - int(grid[-1][-2])
		if int(grid[0][1]) != g:
			ans.append((1, 2))
		if int(grid[1][0]) != g:
			ans.append((2, 1))
	else:
		if int(grid[0][1]) != 0:
			ans.append((1, 2))
		if int(grid[1][0]) != 0:
			ans.append((2, 1))
		if int(grid[-1][-2]) != 1:
			ans.append((n, n - 1))
		if int(grid[-2][-1]) != 1:
			ans.append((n - 1, n))
	print(len(ans))
	for item in ans:
		print(*item)


for _ in range(int(input())):
	n = int(input())
	ml = []
	kl = []
	for i in range(n):
		ml.append(input())
	x = [ml[0][1], ml[1][0], ml[n - 1][n - 2], ml[n - 2][n - 1]]
	x = [int(i) for i in x]
	if x in [[0, 0, 0, 0], [1, 1, 1, 1]]:
		print(2)
		print(n, n - 1)
		print(n - 1, n)
	elif x in [[1, 1, 0, 0], [0, 0, 1, 1]]:
		print(0)
	elif x in [[0, 0, 0, 1], [1, 1, 1, 0]]:
		print(1)
		print(n, n - 1)
	elif x in [[0, 0, 1, 0], [1, 1, 0, 1]]:
		print(1)
		print(n - 1, n)
	elif x in [[0, 1, 0, 0], [1, 0, 1, 1]]:
		print(1)
		print(1, 2)
	elif x in [[1, 0, 0, 0], [0, 1, 1, 1]]:
		print(1)
		print(2, 1)
	elif x in [[0, 1, 0, 1], [1, 0, 1, 0]]:
		print(2)
		print(2, 1)
		print(n, n - 1)
	elif x in [[0, 1, 1, 0], [1, 0, 0, 1]]:
		print(2)
		print(2, 1)
		print(n - 1, n)


def check(l, s, c):
	if l[0][1] == l[1][0]:
		x = l[0][1]
		a = l[n - 1][n - 2]
		b = l[n - 2][n - 1]
		if a == x:
			c = c + 1
			s.append([n, n - 1])
		if b == x:
			c = c + 1
			s.append([n - 1, n])
		print(c)
		for i in s:
			print(*i)
		return
	a = l[n - 1][n - 2]
	b = l[n - 2][n - 1]
	(x, y) = (l[0][1], l[1][0])
	if a == b:
		z = a
		if x == a:
			c = c + 1
			s.append([1, 2])
		else:
			c = c + 1
			s.append([2, 1])
	else:
		c = c + 1
		s.append([1, 2])
		x = 1 - int(x)
		if int(a) == x:
			c = c + 1
			s.append([n, n - 1])
		else:
			c = c + 1
			s.append([n - 1, n])
	print(c)
	for i in s:
		print(*i)
for _ in range(int(input())):
	n = int(input())
	l = []
	for i in range(n):
		k = list(input())
		l.append(k)
	s = []
	c = 0
	check(l, s, c)


for i in range(int(input())):
	a = int(input())
	b = []
	for i in range(a):
		b.append(input().strip())
	if b[1][1] == b[0][2] and b[1][1] == b[2][0]:
		if b[0][1] == b[1][0]:
			if b[0][1] == b[1][1]:
				print(2)
				print(1, 2)
				print(2, 1)
			else:
				print(0)
		elif b[0][1] == b[1][1]:
			print(1)
			print(1, 2)
		else:
			print(1)
			print(2, 1)
	elif b[0][2] == b[2][0]:
		if b[0][1] == b[1][0]:
			if b[0][1] == b[1][1]:
				print(1)
				print(2, 2)
			else:
				print(2)
				print(1, 3)
				print(3, 1)
		elif b[0][1] == b[1][1]:
			print(2)
			print(2, 2)
			print(2, 1)
		else:
			print(2)
			print(2, 2)
			print(1, 2)
	elif b[0][2] == b[1][1]:
		if b[0][1] == b[1][0]:
			if b[0][1] == b[1][1]:
				print(2)
				print(2, 2)
				print(1, 3)
			else:
				print(1)
				print(3, 1)
		elif b[0][1] == b[1][1]:
			print(2)
			print(1, 2)
			print(3, 1)
		else:
			print(2)
			print(2, 1)
			print(3, 1)
	elif b[2][0] == b[1][1]:
		if b[0][1] == b[1][0]:
			if b[0][1] == b[1][1]:
				print(2)
				print(2, 2)
				print(3, 1)
			else:
				print(1)
				print(1, 3)
		elif b[0][1] == b[1][1]:
			print(2)
			print(1, 2)
			print(1, 3)
		else:
			print(2)
			print(2, 1)
			print(1, 3)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
t = int(input())
for ti in range(t):
	li = []
	n = int(input())
	for ni in range(n):
		s = list(input())
		li.append(s)
	ans = []
	if li[0][1] == li[1][0]:
		if li[1][1] == li[0][2] == li[2][0]:
			if li[1][1] == li[0][1]:
				ans.append((0, 1))
				ans.append((1, 0))
			else:
				pass
		else:
			for (x, y) in [(1, 1), (0, 2), (2, 0)]:
				if li[x][y] == li[0][1]:
					ans.append((x, y))
	elif li[1][1] == li[0][2] == li[2][0]:
		if li[1][1] == li[0][1]:
			ans.append((0, 1))
		else:
			ans.append((1, 0))
	else:
		d = {}
		for (x, y) in [(1, 1), (0, 2), (2, 0)]:
			d[li[x][y]] = d.get(li[x][y], 0) + 1
		if d['0'] > d['1']:
			for (x, y) in [(1, 1), (0, 2), (2, 0)]:
				if li[x][y] == '1':
					ans.append((x, y))
					li[x][y] = '0'
		else:
			for (x, y) in [(1, 1), (0, 2), (2, 0)]:
				if li[x][y] == '0':
					ans.append((x, y))
					li[x][y] = '1'
		for (x, y) in [(0, 1), (1, 0)]:
			if li[x][y] == li[1][1]:
				ans.append((x, y))
	print(len(ans))
	for (x, y) in ans:
		print(x + 1, y + 1)


t = int(input())
for i in range(0, t):
	n = int(input())
	sl1 = sl2 = cz = 0
	for j in range(1, n + 1):
		w = input()
		if j == n - 2:
			a = w[n - 1]
			if a == '1':
				sl1 += 1
		if j == n - 1:
			b = w[n - 2]
			if b == '1':
				sl1 += 1
			e = w[n - 1]
			if e == '1':
				sl2 += 1
		if j == n:
			c = w[n - 3]
			if c == '1':
				sl1 += 1
			f = w[n - 2]
			if f == '1':
				sl2 += 1
	if sl1 == 0 and sl2 == 0 or (sl1 == 3 and sl2 == 2):
		print(2)
		print('%d %d' % (n - 1, n))
		print('%d %d' % (n, n - 1))
	if sl1 == 0 and sl2 == 2 or (sl1 == 3 and sl2 == 0):
		print(0)
	if (sl1 == 0 or sl1 == 3) and sl2 == 1:
		print(1)
		if sl1 == 0:
			if e == '0':
				print('%d %d' % (n - 1, n))
			else:
				print('%d %d' % (n, n - 1))
		elif e == '1':
			print('%d %d' % (n - 1, n))
		else:
			print('%d %d' % (n, n - 1))
	if (sl1 == 1 or sl1 == 2) and sl2 == 1:
		print(2)
		if sl1 == 1:
			if e == '0':
				print('%d %d' % (n - 1, n))
			else:
				print('%d %d' % (n, n - 1))
		elif e == '1':
			print('%d %d' % (n - 1, n))
		else:
			print('%d %d' % (n, n - 1))
		if sl1 == 1:
			if a == '1':
				print('%d %d' % (n - 2, n))
			if b == '1':
				print('%d %d' % (n - 1, n - 1))
			if c == '1':
				print('%d %d' % (n, n - 2))
		else:
			if a == '0':
				print('%d %d' % (n - 2, n))
			if b == '0':
				print('%d %d' % (n - 1, n - 1))
			if c == '0':
				print('%d %d' % (n, n - 2))
	if (sl1 == 1 or sl1 == 2) and (sl2 == 0 or sl2 == 2):
		if sl2 == 0:
			print(3 - sl1)
			if a == '0':
				print('%d %d' % (n - 2, n))
			if b == '0':
				print('%d %d' % (n - 1, n - 1))
			if c == '0':
				print('%d %d' % (n, n - 2))
		else:
			print(sl1)
			if a == '1':
				print('%d %d' % (n - 2, n))
			if b == '1':
				print('%d %d' % (n - 1, n - 1))
			if c == '1':
				print('%d %d' % (n, n - 2))


from collections import defaultdict, deque

def solve():
	n = int(input())
	sq = []
	ans = []
	c = 0
	for i in range(n):
		sq.append(input())
	if sq[0][1] == sq[1][0]:
		if sq[-1][-2] == sq[0][1]:
			c += 1
			ans.append((n, n - 1))
		if sq[-2][-1] == sq[0][1]:
			c += 1
			ans.append((n - 1, n))
	elif sq[-1][-2] == sq[-2][-1]:
		if sq[0][1] == sq[-1][-2]:
			c += 1
			ans.append((1, 2))
		if sq[1][0] == sq[-1][-2]:
			c += 1
			ans.append((2, 1))
	else:
		c = 2
		if sq[0][1] == '1':
			ans.append((1, 2))
		else:
			ans.append((2, 1))
		if sq[-1][-2] == '0':
			ans.append((n, n - 1))
		else:
			ans.append((n - 1, n))
	print(c)
	for i in ans:
		print(i[0], i[1])

def main():
	t = 1
	t = int(input())
	for _ in range(t):
		solve()
main()


def solve(n):
	s = [input() for _ in range(n)]
	ans = []
	cnt = 0
	if s[0][1] == s[1][0]:
		if s[n - 2][n - 1] == s[0][1]:
			ans.append((n - 1, n))
			cnt += 1
		if s[n - 1][n - 2] == s[0][1]:
			ans.append((n, n - 1))
			cnt += 1
	elif s[n - 1][n - 2] == s[n - 2][n - 1]:
		if s[0][1] == s[n - 1][n - 2]:
			ans.append((1, 2))
			cnt += 1
		if s[1][0] == s[n - 1][n - 2]:
			ans.append((2, 1))
			cnt += 1
	else:
		if s[0][1] != '0':
			ans.append((1, 2))
			cnt += 1
		else:
			ans.append((2, 1))
			cnt += 1
		if s[n - 1][n - 2] != '1':
			ans.append((n, n - 1))
			cnt += 1
		else:
			ans.append((n - 1, n))
			cnt += 1
	print(cnt)
	for i in ans:
		print(i[0], i[1])
for _ in range(int(input())):
	n = int(input())
	solve(n)


from collections import Counter, defaultdict
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))
for _ in range(I()):
	n = I()
	a = []
	for i in range(n):
		s = input()
		s = list(s)
		a += [s]
	ans = []
	if a[0][1] == a[1][0]:
		x = a[0][1]
		if a[-1][-2] == x:
			ans.append((n, n - 1))
		if a[-2][-1] == x:
			ans.append((n - 1, n))
	elif a[-1][-2] == a[-2][-1]:
		x = a[-1][-2]
		if a[0][1] == x:
			ans.append((1, 2))
		if a[1][0] == x:
			ans.append((2, 1))
	else:
		x = a[0][1]
		ans.append((2, 1))
		if a[-1][-2] == x:
			ans.append((n, n - 1))
		if a[-2][-1] == x:
			ans.append((n - 1, n))
	print(len(ans))
	for i in range(len(ans)):
		print(*ans[i])


t = int(input())
for i in range(t):
	n = int(input())
	A = []
	for i in range(n):
		b = list(map(str, input().split()))
		b = b[0]
		B = []
		for i in range(n):
			B += b[i]
		A += [B]
	a = A[0][1]
	b = A[1][0]
	c = A[-2][-1]
	d = A[-1][-2]
	change = []
	count = 0
	if a == b:
		if a == c:
			change.append([n - 1, n])
			count += 1
		if a == d:
			change.append([n, n - 1])
			count += 1
	elif c == d:
		if a == c:
			change.append([1, 2])
			count += 1
		if b == c:
			change.append([2, 1])
			count += 1
	else:
		change.append([2, 1])
		count += 1
		if a == c:
			change.append([n - 1, n])
			count += 1
		else:
			change.append([n, n - 1])
			count += 1
	print(count)
	for i in change:
		print(' '.join(map(str, i)))


for _ in range(int(input())):
	n = int(input())
	arr = [list(input()) for i in range(n)]
	t = []
	s = [arr[0][1], arr[1][0]]
	f = [arr[-1][-2], arr[-2][-1]]
	if f[0] == f[1]:
		if f[0] == '0':
			if s[0] == '0':
				t.append([1, 2])
			if s[1] == '0':
				t.append([2, 1])
		else:
			if s[0] == '1':
				t.append([1, 2])
			if s[1] == '1':
				t.append([2, 1])
	elif s[0] == s[1]:
		if s[0] == '0':
			if f[0] == '0':
				t.append([n, n - 1])
			if f[1] == '0':
				t.append([n - 1, n])
		if s[0] == '1':
			if f[0] == '1':
				t.append([n, n - 1])
			if f[1] == '1':
				t.append([n - 1, n])
	else:
		if s[0] == '1':
			t.append([1, 2])
		elif s[1] == '1':
			t.append([2, 1])
		if f[0] == '0':
			t.append([n, n - 1])
		elif f[1] == '0':
			t.append([n - 1, n])
	print(len(t))
	for i in t:
		print(*i)


for _ in range(int(input())):
	n = int(input())
	x = []
	for i in range(n):
		x.append(list(input()))
	if x[0][1] == x[1][0] and x[-1][-2] == x[-2][-1]:
		if x[0][1] != x[-1][-2]:
			print(0)
		else:
			print(2)
			print(1, 2)
			print(2, 1)
	elif x[0][1] != x[1][0]:
		if x[-1][-2] != x[-2][-1]:
			print(2)
			print(1, 2)
			if x[1][0] != x[-1][-2]:
				print(n - 1, n)
			else:
				print(n, n - 1)
		else:
			print(1)
			if x[0][1] == x[-1][-2]:
				print(1, 2)
			else:
				print(2, 1)
	elif x[-1][-2] != x[-2][-1]:
		print(1)
		if x[0][1] != x[-1][-2]:
			print(n - 1, n)
		else:
			print(n, n - 1)
	else:
		print(2)
		print(1, 2)
		print(2, 1)


import typing
import sys
import math
import collections
import bisect
import itertools
import heapq
import decimal
INF = 10 ** 20
MOD = 10 ** 9 + 7

def ni():
	return int(sys.stdin.buffer.readline())

def ns():
	return map(int, sys.stdin.buffer.readline().split())

def na():
	return list(map(int, sys.stdin.buffer.readline().split()))

def main():
	t = int(input())
	res = []
	for _ in range(t):
		n = int(input())
		for i in range(n):
			s = input().strip()
			if i == 0:
				a1 = s[1]
			if i == 1:
				a2 = s[0]
			if i == n - 2:
				b2 = s[-1]
			if i == n - 1:
				b1 = s[-2]
		if a1 == a2 and b1 == b2:
			if a1 != b1:
				res.append([0])
			else:
				res.append([2])
				res.append([1, 2])
				res.append([2, 1])
		elif a1 == a2 or b1 == b2:
			res.append([1])
			if a1 == a2:
				if b1 == a1:
					res.append([n, n - 1])
				else:
					res.append([n - 1, n])
			elif a1 == b1:
				res.append([1, 2])
			else:
				res.append([2, 1])
		else:
			res.append([2])
			if a1 != '0':
				res.append([1, 2])
			if a2 != '0':
				res.append([2, 1])
			if b1 != '1':
				res.append([n, n - 1])
			if b2 != '1':
				res.append([n - 1, n])
	for ri in res:
		print(*ri, sep=' ')
main()


from sys import stdin, stdout
st = lambda : list(stdin.readline().strip())
li = lambda : list(map(int, stdin.readline().split()))
mp = lambda : map(int, stdin.readline().split())
inp = lambda : int(stdin.readline())
pr = lambda n: stdout.write(str(n) + '\n')

def solve():
	n = inp()
	ans = 0
	val = []
	l = [st() for i in range(n)]
	if l[0][1] == l[1][0]:
		x = l[0][1]
		(a, b) = (l[n - 1][n - 2], l[n - 2][n - 1])
		if a == x:
			ans += 1
			val.append((n, n - 1))
		if b == x:
			ans += 1
			val.append((n - 1, n))
		print(ans)
		for i in val:
			print(*i)
		return
	(a, b) = (l[n - 1][n - 2], l[n - 2][n - 1])
	(x, y) = (l[0][1], l[1][0])
	if a == b:
		z = a
		if x == a:
			ans += 1
			val.append((1, 2))
		else:
			ans += 1
			val.append((2, 1))
	else:
		ans += 1
		val.append((1, 2))
		x = 1 - int(x)
		if int(a) == x:
			ans += 1
			val.append((n, n - 1))
		else:
			ans += 1
			val.append((n - 1, n))
	print(ans)
	for i in val:
		print(*i)
for _ in range(inp()):
	solve()


t = int(input())
for i in range(t):
	n = int(input())
	L = []
	for i in range(n):
		ch = input()
		L.append(ch)
	I = []
	if (int(L[0][1]) + int(L[1][0])) % 2 == 0:
		if L[n - 1][n - 2] == L[1][0]:
			I.append((n, n - 1))
		if L[n - 2][n - 1] == L[1][0]:
			I.append((n - 1, n))
	elif (int(L[n - 1][n - 2]) + int(L[n - 2][n - 1])) % 2 == 0:
		if L[n - 1][n - 2] == L[1][0]:
			I.append((2, 1))
		if L[n - 2][n - 1] == L[0][1]:
			I.append((1, 2))
	else:
		if L[0][1] == '1':
			I.append((1, 2))
		else:
			I.append((2, 1))
		if L[n - 1][n - 2] == '0':
			I.append((n, n - 1))
		else:
			I.append((n - 1, n))
	print(len(I))
	for i in I:
		print(i[0], i[1])


T = int(input())
for t in range(T):
	N = int(input())
	M = []
	for i in range(N):
		M.append(input())
	inverts = []
	if M[0][1] == '0' and M[1][0] == '0':
		if M[N - 2][N - 1] == '0':
			inverts.append((N - 2, N - 1))
		if M[N - 1][N - 2] == '0':
			inverts.append((N - 1, N - 2))
	elif M[0][1] == '1' and M[1][0] == '1':
		if M[N - 2][N - 1] == '1':
			inverts.append((N - 2, N - 1))
		if M[N - 1][N - 2] == '1':
			inverts.append((N - 1, N - 2))
	elif M[0][1] == '0' and M[1][0] == '1':
		if M[N - 2][N - 1] == '1' and M[N - 1][N - 2] == '1':
			inverts.append((1, 0))
		if M[N - 2][N - 1] == '0' and M[N - 1][N - 2] == '0':
			inverts.append((0, 1))
		if M[N - 2][N - 1] == '1' and M[N - 1][N - 2] == '0':
			inverts.append((1, 0))
			inverts.append((N - 1, N - 2))
		if M[N - 2][N - 1] == '0' and M[N - 1][N - 2] == '1':
			inverts.append((1, 0))
			inverts.append((N - 2, N - 1))
	elif M[0][1] == '1' and M[1][0] == '0':
		if M[N - 2][N - 1] == '0' and M[N - 1][N - 2] == '0':
			inverts.append((1, 0))
		if M[N - 2][N - 1] == '1' and M[N - 1][N - 2] == '1':
			inverts.append((0, 1))
		if M[N - 2][N - 1] == '0' and M[N - 1][N - 2] == '1':
			inverts.append((1, 0))
			inverts.append((N - 1, N - 2))
		if M[N - 2][N - 1] == '1' and M[N - 1][N - 2] == '0':
			inverts.append((1, 0))
			inverts.append((N - 2, N - 1))
	print(len(inverts))
	for i in inverts:
		print(i[0] + 1, i[1] + 1)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	grid = []
	for i in range(n):
		grid.append(list(input()))
	cnt1 = 0
	ans1 = []
	cnt2 = 0
	ans2 = []
	for i in range(3):
		if grid[n - 1 - i][n - 3 + i] != '0':
			cnt1 += 1
			ans1.append((n - i, n - 2 + i))
	for i in range(2):
		if grid[n - 1 - i][n - 2 + i] != '1':
			cnt1 += 1
			ans1.append((n - i, n - 1 + i))
	for i in range(3):
		if grid[n - 1 - i][n - 3 + i] != '1':
			cnt2 += 1
			ans2.append((n - i, n - 2 + i))
	for i in range(2):
		if grid[n - 1 - i][n - 2 + i] != '0':
			cnt2 += 1
			ans2.append((n - i, n - 1 + i))
	if cnt1 <= 2:
		print(cnt1)
		for i in range(cnt1):
			print(ans1[i][0], ans1[i][1])
	else:
		print(cnt2)
		for i in range(cnt2):
			print(ans2[i][0], ans2[i][1])


import sys, math
import io, os
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write('\n'.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
INF = float('inf')
mod = 10 ** 9 + 7
for t in range(int(data())):
	n = int(data())
	mat = [data() for i in range(n)]
	cnt = 0
	if mat[0][1] != '0':
		cnt += 1
	if mat[0][2] != '1':
		cnt += 1
	if mat[1][0] != '0':
		cnt += 1
	if mat[1][1] != '1':
		cnt += 1
	if mat[2][0] != '1':
		cnt += 1
	if cnt < 3:
		print(cnt)
		if mat[0][1] != '0':
			print(1, 2)
		if mat[0][2] != '1':
			print(1, 3)
		if mat[1][0] != '0':
			print(2, 1)
		if mat[1][1] != '1':
			print(2, 2)
		if mat[2][0] != '1':
			print(3, 1)
		continue
	cnt = 0
	if mat[0][1] != '1':
		cnt += 1
	if mat[0][2] != '0':
		cnt += 1
	if mat[1][0] != '1':
		cnt += 1
	if mat[1][1] != '0':
		cnt += 1
	if mat[2][0] != '0':
		cnt += 1
	if cnt < 3:
		print(cnt)
		if mat[0][1] != '1':
			print(1, 2)
		if mat[0][2] != '0':
			print(1, 3)
		if mat[1][0] != '1':
			print(2, 1)
		if mat[1][1] != '0':
			print(2, 2)
		if mat[2][0] != '0':
			print(3, 1)
		continue


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		grid = []
		for __ in range(n):
			grid.append(input())
		(a, b, c, d) = (grid[0][1], grid[1][0], grid[-1][-2], grid[-2][-1])
		total = 0
		flips = []
		if a == b:
			if a == c:
				total += 1
				flips.append([n, n - 1])
			if a == d:
				total += 1
				flips.append([n - 1, n])
		elif c == d:
			if c == a:
				total += 1
				flips.append([1, 2])
			if c == b:
				total += 1
				flips.append([2, 1])
		else:
			total = 2
			if a == '0':
				flips.append([1, 2])
			else:
				flips.append([2, 1])
			if c == '1':
				flips.append([n, n - 1])
			else:
				flips.append([n - 1, n])
		print(total)
		for flip in flips:
			print(*flip)
main()


from collections import Counter
import string
import math
import sys

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(arrber_of_variables):
	if arrber_of_variables == 1:
		return int(sys.stdin.readline())
	if arrber_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))

def printDivisors(n):
	divisors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				divisors.append(i)
			else:
				divisors.extend((i, n // i))
		i = i + 1
	return divisors

def countTotalBits(num):
	binary = bin(num)[2:]
	return len(binary)
for _ in range(vary(1)):
	n = vary(1)
	arr = []
	for i in range(n):
		arr.append([str(i) for i in input()])
	if arr[0][1] == arr[1][0]:
		count = 0
		tt = []
		if arr[n - 2][n - 1] == arr[0][1]:
			count += 1
			tt.append([n - 1, n])
		if arr[n - 1][n - 2] == arr[0][1]:
			count += 1
			tt.append([n, n - 1])
		print(count)
		for i in tt:
			print(*i)
	elif arr[n - 2][n - 1] == arr[n - 1][n - 2]:
		if arr[0][1] == arr[n - 2][n - 1]:
			print(1)
			print(1, 2)
		else:
			print(1)
			print(2, 1)
	else:
		print(2)
		print(n - 1, n)
		if arr[n - 2][n - 1] != arr[0][1]:
			print(1, 2)
		else:
			print(2, 1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = []
	for i in range(n):
		a.append(list(input()))
	if a[0][1] == a[1][0] and a[n - 1][n - 2] == a[n - 2][n - 1]:
		if a[0][1] == a[n - 1][n - 2]:
			print(2)
			print('{} {}'.format(n, n - 1))
			print('{} {}'.format(n - 1, n))
		else:
			print(0)
	elif a[0][1] == a[1][0] and a[n - 1][n - 2] != a[n - 2][n - 1]:
		if a[0][1] == a[n - 1][n - 2]:
			print(1)
			print('{} {}'.format(n, n - 1))
		else:
			print(1)
			print('{} {}'.format(n - 1, n))
	elif a[0][1] != a[1][0] and a[n - 1][n - 2] == a[n - 2][n - 1]:
		if a[0][1] == a[n - 1][n - 2]:
			print(1)
			print('{} {}'.format(1, 2))
		else:
			print(1)
			print('{} {}'.format(2, 1))
	elif a[0][1] != a[1][0] and a[n - 1][n - 2] != a[n - 2][n - 1]:
		if a[0][1] != '0':
			print(2)
			print('{} {}'.format(1, 2))
		else:
			print(2)
			print('{} {}'.format(2, 1))
		if a[n - 1][n - 2] == '0':
			print('{} {}'.format(n, n - 1))
		else:
			print('{} {}'.format(n - 1, n))


t = int(input())
while t > 0:
	n = int(input())
	mat = [input() for i in range(n)]
	ans = []
	if mat[0][1] == mat[1][0]:
		if mat[n - 1][n - 2] == mat[0][1]:
			ans.append([n - 1, n - 2])
		if mat[n - 2][n - 1] == mat[0][1]:
			ans.append([n - 2, n - 1])
	elif mat[n - 1][n - 2] == mat[n - 2][n - 1]:
		if mat[0][1] == mat[n - 1][n - 2]:
			ans.append([0, 1])
		if mat[1][0] == mat[n - 1][n - 2]:
			ans.append([1, 0])
	else:
		ans.append([1, 0])
		if mat[n - 1][n - 2] == mat[0][1]:
			ans.append([n - 1, n - 2])
		if mat[n - 2][n - 1] == mat[0][1]:
			ans.append([n - 2, n - 1])
	print(len(ans))
	for (x, y) in ans:
		print(x + 1, y + 1)
	t -= 1


from functools import reduce
import collections
import math
import sys

class Read:

	@staticmethod
	def string():
		return input()

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(delimiter=' '):
		return input().split(delimiter)

	@staticmethod
	def list_int(delimiter=' '):
		return list(map(int, input().split(delimiter)))

def main():
	t = Read.int()
	for _ in range(t):
		n = Read.int()
		a = list()
		for i in range(n):
			a.append(list(Read.string()))
		if a[0][1] == a[1][0] and a[1][0] == a[n - 1][n - 1 - 1] and (a[n - 1][n - 1 - 1] == a[n - 1 - 1][n - 1]):
			print('2', '1 2', '2 1', sep='\n')
		elif a[0][1] == a[1][0] and a[1][0] != a[n - 1][n - 1 - 1] and (a[n - 1][n - 1 - 1] == a[n - 1 - 1][n - 1]):
			print(0)
		else:
			kk = {'1': [], '0': []}
			if a[0][1] == '1':
				kk['1'].append('2 1')
			else:
				kk['0'].append('2 1')
			if a[1][0] == '1':
				kk['1'].append('1 2')
			else:
				kk['0'].append('1 2')
			if a[n - 1][n - 1 - 1] == '1':
				kk['1'].append(str(n - 1) + ' ' + str(n))
			else:
				kk['0'].append(str(n - 1) + ' ' + str(n))
			if a[n - 1 - 1][n - 1] == '1':
				kk['1'].append(str(n) + ' ' + str(n - 1))
			else:
				kk['0'].append(str(n) + ' ' + str(n - 1))
			if len(kk['1']) == len(kk['0']):
				print(2)
				print('2 1')
				if a[0][1] != a[n - 1][n - 1 - 1]:
					print(str(n - 1) + ' ' + str(n))
				else:
					print(str(n) + ' ' + str(n - 1))
			else:
				print(1)
				if len(kk['1']) < len(kk['0']):
					print(kk['1'][0])
				else:
					print(kk['0'][0])
main()


t = int(input())
for i in range(t):
	n = int(input())
	matrix = [input() for j in range(n)]
	val = matrix[0][1] + matrix[1][0] + matrix[n - 1][n - 2] + matrix[n - 2][n - 1]
	answer = {'0000': [(1, 2), (2, 1)], '0001': [(n, n - 1)], '0010': [(n - 1, n)], '0011': [], '0100': [(1, 2)], '0101': [(1, 2), (n - 1, n)], '0110': [(2, 1), (n - 1, n)], '0111': [(2, 1)], '1000': [(2, 1)], '1001': [(2, 1), (n - 1, n)], '1010': [(2, 1), (n, n - 1)], '1011': [(1, 2)], '1100': [], '1101': [(n - 1, n)], '1110': [(n, n - 1)], '1111': [(1, 2), (2, 1)]}
	answer_t = answer[val]
	print(len(answer_t))
	for (r, c) in answer_t:
		print('{} {}'.format(r, c))


def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		matrix = [input() for i in range(n)]
		(c1, c2, c3, c4) = (int(matrix[0][1]), int(matrix[1][0]), int(matrix[n - 1][n - 2]), int(matrix[n - 2][n - 1]))
		answer = []
		if c1 == c2:
			if c3 == c1:
				answer.append((n, n - 1))
			if c4 == c1:
				answer.append((n - 1, n))
		elif c3 == c4:
			if c1 == c3:
				answer.append((1, 2))
			if c2 == c3:
				answer.append((2, 1))
		else:
			if c1 != 0:
				answer.append((1, 2))
			if c2 != 0:
				answer.append((2, 1))
			if c3 != 1:
				answer.append((n, n - 1))
			if c4 != 1:
				answer.append((n - 1, n))
		print(len(answer))
		for j in answer:
			print(*j)
main()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def prod(a, mod=10 ** 9 + 7):
	ans = 1
	for each in a:
		ans = ans * each % mod
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if True else 1):
	n = int(input())
	a = []
	for i in range(n):
		a += [[int(k, 32) for k in input()]]
	zero_one = []
	one_zero = []
	if a[0][1] != 0:
		zero_one += [[1, 2]]
	else:
		one_zero += [[1, 2]]
	if a[1][0] != 0:
		zero_one += [[2, 1]]
	else:
		one_zero += [[2, 1]]
	if a[-1][-2] != 1:
		zero_one += [[n, n - 1]]
	else:
		one_zero += [[n, n - 1]]
	if a[-2][-1] != 1:
		zero_one += [[n - 1, n]]
	else:
		one_zero += [[n - 1, n]]
	if len(zero_one) > len(one_zero):
		zero_one = one_zero
	print(len(zero_one))
	for k in zero_one:
		print(*k)


import sys
input = sys.stdin.readline
for f in range(int(input())):
	n = int(input())
	grid = []
	for i in range(n):
		line = input()
		line = line[0:n]
		grid.append(line)
	if grid[0][1] == grid[1][0]:
		c = 0
		cs = []
		if grid[-1][-2] == grid[0][1]:
			c += 1
			cs.append([n, n - 1])
		if grid[-2][-1] == grid[0][1]:
			c += 1
			cs.append([n - 1, n])
		print(c)
		for x in cs:
			print(*x)
	elif grid[-1][-2] == grid[-2][-1]:
		print(1)
		if grid[0][1] == grid[-1][-2]:
			print(1, 2)
		else:
			print(2, 1)
	else:
		print(2)
		print(2, 1)
		if grid[-2][-1] == grid[0][1]:
			print(n - 1, n)
		else:
			print(n, n - 1)