import sys, collections

def bfs(num):
    q = collections.deque()
    q.append((0,0))
    check[0][0] = True
    while q:
        x, y = q.popleft()
        for i in range(4):
            nx, ny = x + dx[i], y + dy[i]
            if 0 <= nx < n and 0 <= ny < n:
                if arr[nx][ny] == num or arr[nx][ny] == 'F':
                    if not check[nx][ny]:
                        check[nx][ny] = True
                        q.append((nx,ny))

tc = int(sys.stdin.readline())
for _ in range(tc):
    n = int(sys.stdin.readline())
    dx = [0,1,0,-1]
    dy = [1,0,-1,0]
    one = False
    zero = False
    check = [[False] * n for _ in range(n)]
    arr = [list(sys.stdin.readline().rstrip()) for _ in range(n)]
    bfs('1')
    if check[n - 1][n - 1]:
        one = True
    check = [[False] * n for _ in range(n)]
    bfs('0')
    if check[n - 1][n - 1]:
        zero = True
    change = []
    if one and not zero:
        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 not one and zero:
        if arr[n - 2][n - 1] == '0':
            change.append((n - 1, n))
        if arr[n - 1][n - 2] == '0':
            change.append((n, n - 1))
    elif one and zero:
        if arr[n - 1][n - 2] == '0':
            change.append((n, n - 1))
            if arr[0][1] == '1':
                change.append((1,2))
            elif arr[1][0] == '1':
                change.append((2,1))
        elif arr[n - 2][n - 1] == '0':
            change.append((n - 1, n))
            if arr[0][1] == '1':
                change.append((1,2))
            elif arr[1][0] == '1':
                change.append((2,1))
    if change:
        print(len(change))
        for i in change:
            print(i[0], i[1])
    else:
        print(0)



