import sys, collections

def bfs(num):
    check = [[False] * n for _ in range(n)]
    res = []
    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:
                    if not check[nx][ny]:
                        check[nx][ny] = True
    for i in range(n):
        for j in range(n):
            if i == 0 and j == 0:
                continue
            if i == n - 1 and j == n - 1:
                continue
            if arr[i][j] != num and not check[i][j]:
                res.append((i,j))
    return res

tc = int(sys.stdin.readline())
for _ in range(tc):
    n = int(sys.stdin.readline())
    dx = [0,1,0,-1]
    dy = [1,0,-1,0]
    arr = [list(sys.stdin.readline().rstrip()) for _ in range(n)]
    q = collections.deque()
    for i in range(n):
        for j in range(n):
            if arr[i][j] == '0':
                q.append((i,j))
    one = bfs('0')
    for i in range(n):
        for j in range(n):
            if arr[i][j] == '1':
                q.append((i,j))
    zero = bfs('1')
    if one and zero:
        print(2)
        print(one[0][0], one[0][1])
        print(zero[0][0], zero[0][1])
    elif not one and zero:
        print(1)
        print(zero[0][0], zero[0][1])
    elif one and not zero:
        print(1)
        print(one[0][0], one[0][1])
    else:
        print(0)