
from __future__ import division
import sys
input = sys.stdin.readline
import math
from math import sqrt, floor, ceil
from collections import Counter


############ ---- Input Functions ---- ############
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))
def insr2():
    s = input()
    return(s.split(" "))

def prime_factorization(n):

    if n == 1:
        return [1]

    ans=[]
    i = 2
    cap = sqrt(n)
    while i <= cap:
        if n % i == 0:
            ans.append(i)
            n = n//i
            cap=sqrt(n)
        else:
            i += 1
    if n > 1:
        ans.append(n)
    return ans

def binomial(n, k):
    if n == 1 or n == k:
        return 1

    if k > n:
        return 0       
    else:
        a = math.factorial(n)
        b = math.factorial(k)
        c = math.factorial(n-k)
        div = a // (b * c)
        return div  

for _ in range(inp()):
    n = inp()

    c = 0
    ans=[]

    for i in range(n):
        nums = insr()

        k = len(nums)

        if i == 0:
            a1 = nums[1]
        if i == 1:
            a2 = nums[0]
        
        if i == n-2:
            b1 = nums[-1]
        if i == n-1:
            b2 = nums[-2]
        
    if a1 == b1:
        c+=1
        ans.append([k-1, k])
    if a2 == b2:
        c+=1
        ans.append([k, k-1])

    print c
    for a in ans:
        print ' '.join([str(b) for b in a])
