from collections import defaultdict as dd
import sys
input=sys.stdin.readline
t=int(input())
while t:
    n=int(input())
    ll=[]
    for i in range(n):
        s=input().split()[0]
        ll.append(s)
    vis=[[False]*n for i in range(n)]
    vis[0][0]=True
    vis[0][1]=True
    vis[1][0]=True
    for i in range(2,n):
        if(ll[0][i]==ll[0][i-1] and vis[0][i-1]):
            vis[0][i]=True
        if(ll[i][0]==ll[i-1][0] and vis[i-1][0]):
            vis[i][0]=True
    
    for i in range(1,n):
        for j in range(1,n):
            if(ll[i][j]==ll[i][j-1] and vis[i][j-1]):
                vis[i][j]=True
            if(ll[i][j]==ll[i-1][j] and vis[i-1][j]):
                vis[i][j]=True
    
    b=vis[n-2][n-2]
    a=vis[n-1][n-3]
    c=vis[n-3][n-1]
    ans=[]
    aa=ll[n-1][n-3]
    bb=ll[n-2][n-2]
    cc=ll[n-3][n-1]
    if(a and b and c):
        if(aa==bb==cc):
            ans.append((1,2))
            ans.append((2,1))
        elif(aa==bb):
            ans.append((2,1))
            if(cc==ll[n-3][n-1]):
                ans.append((n-2,n))
        elif(cc==bb):
            ans.append((1,2))
            if(aa==ll[n-1][n-3]):
                ans.append((n,n-2))
    elif(a and b):
        if(aa==bb):
            if(ll[n-1][n-2]==aa):
                ans.append((n,n-1))
        else:
            if(aa==ll[n-1][n-2]):
                ans.append((n,n-2))
            else:
                ans.append((n-1,n-1))
    elif(b and c):
        if(cc==bb):
            if(ll[n-2][n-1]==bb):
                ans.append((n-1,n))
        else:
            if(bb==ll[n-2][n-1]):
                ans.append((n-1,n-1))
            else:
                ans.append((n-2,n))
    elif(a and c):
        if(ll[n-1][n-2]==aa):
            ans.append((n,n-2))
        if(ll[n-2][n-1]==cc):
            ans.append((n-1,n))
    elif(a):
        if(ll[n-1][n-2]==aa):
            ans.append((n,n-2))
    elif(c):
        if(ll[n-2][n-1]==cc):
            ans.append((n-1,n))
    elif(b):
        if(ll[n-1][n-2]==bb and ll[n-2][n-1]==bb):
            ans.append((n-1,n-1))
        elif(ll[n-1][n-2]==bb):
            ans.append((n,n-1))
        elif(ll[n-2][n-1]==bb):
            ans.append((n-1,n))
    print(len(ans))
    for i in ans:
        print(*i)
    t-=1
          
            
                
        