t=int(input())
for _ in range(t):
    n=int(input())
    mat = []
    for i in range(n):
        s=str(input())
        mat.append(s)
    vis0={}
    vis1={}
    q = []
    ##zero
    if mat[0][1]=='0':
        q.append((0,1))
    if mat[1][0]=='0':
        q.append((1,0))
    pq=[[-1,0],[1,0],[0,1],[0,-1]]
    while len(q)>0:
        x=q.pop(0)
        vis0[x]=1
        for i in pq:
            a,b=x[0]+i[0],x[1]+i[1]
            if 0<=a<n and 0<=b<n:
                if mat[a][b]=='0' and (a,b) not in vis0:
                    q.append((a,b))
    q=[]
    if mat[0][1]=='1':
        q.append((0,1))
    if mat[1][0]=='1':
        q.append((1,0))
    while len(q)>0:
        x=q.pop(0)
        vis1[x]=1
        for i in pq:
            a,b=x[0]+i[0],x[1]+i[1]
            if 0<=a<n and 0<=b<n:
                if mat[a][b]=='0' and (a,b) not in vis1:
                    q.append((a,b))
    x=(n-1,n-2)
    y=(n-2,n-1)
    if  (x not in vis0 and y not in vis0) and (x not in vis1 and y not in vis1):
        print(0)
    elif (x in vis0 or y in vis0) and (x not in vis1 and y not in vis1):
        ans = []
        if mat[n-2][n-1]=='0':
            ans.append((n-2+1,n-1+1))
        if mat[n-1][n-2]=='0':
            ans.append((n-1+1,n-2+1))
        print(len(ans))
        for i in ans:
            print(i[0],i[1])
    elif (x not in vis0 and y not in vis0) and (x in vis1 or y in vis1):
        ans = []
        if mat[n-2][n-1]=='1':
            ans.append((n-2+1,n-1+1))
        if mat[n-1][n-2]=='1':
            ans.append((n-1+1,n-2+1))
        print(len(ans))
        for i in ans:
            print(i[0],i[1])
    else:
        if mat[n-2][n-1]=='0' and mat[n-1][n-2]=='1':
            if mat[n-2][n-2]=='0' and mat[n-3][n-1]=='0':
                print(2)
                print(n-1,n)
                print(n,n-1)
            elif mat[n-2][n-2]=='0' and mat[n-3][n-1]=='1':
                print(2)
                print(n,n-2)
                print(n-1,n-1)
            else:
                print(2)
                print(n-1,n-1)
                print(n-2,n)
        else:
            if mat[n-1][n-3]=='0' and mat[n-2][n-2]=='0':
                print(2)
                print(n,n-1)
                print(n-2,n)
            elif mat[n-2][n-2]=='1' and mat[n-3][n-1]=='1':
                print(2)
                print(n-1,n)
                print(n,n-2)
            else:
                print(2)
                print(n-1,n-1)
                print(n-2,n)
            
            