from collections import defaultdict,deque
def check(s,d,g):
    visited=defaultdict(int)
    q=deque()
    q.append((s))
    visited[s]=1
    while q:
        n=q.popleft()
        if n==d:
            return 1
        for v in g[n]:
            if visited[v]==0:
                q.append(v)
                visited[v]=1
    return 0
    
def main():
    for _ in range(int(input())):
        n=int(input())
        gzero=defaultdict(list)
        a=[]
        for i in range(n):
            a.append(input())
        # for zeroes
        for i in range(n):
            for j in range(n):
                if a[i][j]=="S" or a[i][j]=='0':
                    if j+1<n and a[i][j+1]=='0':
                        gzero[(i,j)].append((i,j+1))
                    if i+1<n and a[i+1][j]=='0':
                        gzero[(i,j)].append((i+1,j))
        
        if a[n-2][n-1]=='0':
            gzero[(n-2,n-1)].append((n-1,n-1))
        if a[n-1][n-2]=='0':
            gzero[(n-1,n-2)].append((n-1,n-1))
        
        # for ones
        gones=defaultdict(list)
        for i in range(n):
            for j in range(n):
                if a[i][j]=='S' or a[i][j]=='1':
                    if j+1<n and a[i][j+1]=='1':
                        gones[(i,j)].append((i,j+1))
                    if i+1<n and a[i+1][j]=='1':
                        gones[(i,j)].append((i+1,j))
        if a[n-2][n-1]=='1':
            gones[(n-2,n-1)].append((n-1,n-1))
        if a[n-1][n-2]=='1':
            gones[(n-1,n-2)].append((n-1,n-1))
        
        if (not check((0,0),(n-1,n-1),gzero)) and (not check((0,0),(n-1,n-1),gones)):
            print(0)
            continue
        if (not check((0,0),(n-1,n-1),gzero)) and (check ((0,0),(n-1,n-1),gones)):
            if a[n-1][n-2]=='1' and a[n-2][n-1]=='1':
                print(2)
                print("%d %d"%(n-1,n-2))
                print("%d %d"%(n-2,n-1))
                continue
            if a[n-1][n-2]=='1':
                print(1)
                print("%d %d"%(n-1,n-2))
                continue
            if a[n-2][n-1]=='1':
                print(1)
                print("%d %d"%(n-2,n-1))
                continue
        if (check((0,0),(n-1,n-1),gzero)) and (not check ((0,0),(n-1,n-1),gones)):
            if a[n-1][n-2]=='0' and a[n-2][n-1]=='0':
                print(2)
                print("%d %d"%(n-1,n-2))
                print("%d %d"%(n-2,n-1))
                continue
            if a[n-1][n-2]=='0':
                print(1)
                print("%d %d"%(n-1,n-2))
                continue
            if a[n-2][n-1]=='0':
                print(1)
                print("%d %d"%(n-2,n-1))
                continue
        if (check((0,0),(n-1,n-1),gzero)) and (check ((0,0),(n-1,n-1),gones)):
            print(2)
            print("%d %d"%(n-1,n-2))
            print("%d %d"%(n-2,n-1))
            continue
main()