t = int(input())

for _ in range(t):
    n = int(input())

    arr = input()

    el12 = int(arr[1])

    arr = input()

    el21 = int(arr[0])

    if n == 3:
        el34 = int(arr[n-1])
        arr = input()
        el43 = int(arr[n-2])

    else:
        for _ in range(2,n-2): arr = input()

        arr = input()
        el34 = int(arr[n-1])

        arr = input()
        el43 = int(arr[n-2])
    


    need = (el12^el21) + (el34 ^ el43)

    if need == 0:
        if el12 == el34:
            print(2)
            print(1, 2)
            print(2,1)
    else: print(0)

    

    if need == 2:
        print(need)
        if el12 != 1: print(1, 2)

        if el21 != 1: print(2,1)

        if el34 !=1 : print(n-1, n)

        if el43 !=1: print(n, n-1)

    if need == 1:
        print(need)
        if el12 == el21:
            if el34 == el21: print(n-1, n)
            else: print(n, n-1)
        
        else:
            if el12 == el34: print(1, 2)
            else: print(2, 1)
