#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
#import io,os; input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline #for pypy
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]

for _ in range(inp()):
    n = inp()
    x = [input().strip() for i in range(n)]
    q = [(0,0)]
    vis = set([(0,0)])
    dx,dy = [0,0,-1,1],[1,-1,0,0]
    ans = []
    while q:
        #print(q)
        cx,cy = q.pop(0)
        if (cx,cy) == (0,0):
            q.append((0,1))
            q.append((1,0))
            vis.add((0,1))
            vis.add((1,0))
            continue
        if (cx,cy) == (n-2,n-1):
            ans.append((n-1,n))
        elif (cx,cy) == (n-1,n-2):
            ans.append((n,n-1))
        for i in range(4):
            nx,ny = cx+dx[i],cy+dy[i]
            if 0<=nx<n and 0<=ny<n and (nx,ny) not in vis and x[cx][cy] == x[nx][ny]:
                q.append((nx,ny))
                vis.add((nx,ny))
    print(len(ans))
    [print(*i) for i in ans]
