from collections import deque, defaultdict
for _ in range(int(input())):
    n = int(input())
    mat = []
    for i in range(n):
        a = list(input().strip())
        mat.append(a)
    dx = [1,-1,0,0]
    dy = [0,0,-1,1]
    def bfs(sign):
        q = deque()
        q.append([0,0])
        vis = {(0,0):1}
        while q :
            x,y = q.popleft()
            if x==n-1 and y==n-1:
                return True
            for i in range(4):
                xx = x+dx[i]
                yy = y+dy[i]
                if 0<=xx<n and 0<=yy<n and (xx,yy) not in vis and mat[xx][yy] in [sign,"F"]:
                    q.append([xx,yy])
                    vis[(xx,yy)] = 1
        return False
    # print(mat)
    one = bfs("1")
    zero = bfs("0")
    # print(one,zero)
    if not one and not zero:
        print(0)
        continue
    if one and zero:
        res = [[1,2],[n,n-1]]
        print(len(res))
        for i in res:
            print(*i)
        continue
    ones = []
    zeros = []
    if mat[0][1]!=mat[1][0]:
        ones += [[1,2],[2,1]]
    if mat[-1][-2]!=mat[-2][-1]:
        zeros += [[n-1,n],[n,n-1]]
    res = []
    if one:
        if ones:
            for i,j in ones:
                if mat[i-1][j-1]=="1":
                    res.append([i,j])
        else:
            for i,j in zeros:
                if mat[i-1][j-1]=="1":
                    res.append([i,j])
        print(len(res))
        for i in res:
            print(*i)
    else:
        if ones:
            for i,j in ones:
                if mat[i-1][j-1]=="0":
                    res.append([i,j])
        else:
            for i,j in zeros:
                if mat[i-1][j-1]=="0":
                    res.append([i,j])
        print(len(res))
        for i in res:
            print(*i)

