#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)])
    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))
        if (cx,cy) == (n-2,n-1):
            ans.append((n-1,n))
        if (cx,cy) == (n-1,n-2):
            ans.append((n,n-1)) 
        if cx+1<n and (cx+1,cy) not in vis and x[cx][cy] == x[cx+1][cy]:
            q.append((cx+1,cy))
            vis.add((cx+1,cy))
        if cy+1<n and (cx,cy+1) not in vis and x[cx][cy] == x[cx][cy+1]:
            q.append((cx,cy+1))
            vis.add((cx,cy+1))
    print(len(ans))
    [print(*i) for i in ans]
