t=int(input())
for _ in range(t):
    n=int(input())
    l=[]
    for i in range(n):
        l.append(input())
    a=len(set(l[0]))
    b_list=[]
    for e in l:
        b_list.append(e[-1])
    b=len(set(b_list))
    c=len(set(l[-1]))
    d_list=[]
    for e in l:
        d_list.append(e[0])
    d=len(set(d_list))
    if a==3 and b==3 and c==3 and d==3:
        print(0)
#         if l[-2][-2]==l[-2][-1] and l[-2][-2]==l[-1][-2]:
#             print(0)
    else:
        ans=[]
        cnt=0
        if l[-2][-2]==l[-2][-1]:
            cnt+=1
            ans.append(list((n-1,n)))
        if l[-2][-2]==l[-1][-2]:
            cnt+=1
            ans.append(list((n,n-1)))
        print(cnt)
        for each in ans:
            print(*each)
                