
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Queue;

public class virtual {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        int T = Integer.parseInt(br.readLine());
        for (int t = 0; t < T; t++) {
           int N = Integer.parseInt(br.readLine());
           int[][] grid = new int[N][N];
           for(int i = 0; i<N; i++){
               String l = br.readLine();
               for(int j = 0; j<N; j++){
                   grid[i][j] = l.charAt(j) - '0';
               }
           }
           boolean good = true;
           boolean c = false;
           boolean d = false;
           List<int[]> a = new ArrayList();
           if(ff(grid, N-2, N-1)){
               a.add(new int[]{N-2, N-1});
               grid[N-2][N-1] ^= 1;
               if(ff(grid, N-2, N-1)){
                   good = false;
               }
               c = true;
           }
           if(ff(grid, N-1, N-2)){
               a.add(new int[]{N-1, N-2});
               grid[N-1][N-2] ^= 1;
               if(ff(grid, N-1, N-2)){
                   good = false;
               }
               d = true;
           }
           
           if(!good){
               a = new ArrayList();
               if(c) grid[N-2][N-1] ^= 1;
               if(d) grid[N-1][N-2] ^= 1;
               if(ff(grid, 0, 1)) a.add(new int[]{0,1});
               if(ff(grid, 1, 0)) a.add(new int[]{1,0});
           }
           pw.println(a.size());
           for(int[] i : a){
               pw.println((i[0] + 1) + " " +(i[1]+1));
           }
        }
        
        pw.close();
        br.close();
    }
    
    static int[] xDir = new int[]{0, 0, 1, -1};
    static int[] yDir = new int[]{1, -1, 0, 0};
    static boolean ff(int[][] grid, int y, int x){
        Queue<int[]> dq = new ArrayDeque();
        dq.add(new int[]{y, x});
        boolean[][] vis = new boolean[grid.length][grid[0].length];
        while(!dq.isEmpty()){
            int[] c = dq.poll();

            if(vis[c[0]][c[1]]){
                continue;
            }
            vis[c[0]][c[1]] = true;
            for(int i = 0; i<4; i++){
                int dY = c[0] + yDir[i];
                int dX = c[1] + xDir[i];
                if(dY >= grid.length || dY < 0 || dX >= grid[0].length || dX < 0) continue;
                if(dY + dX == 0) return true;
                if(grid[dY][dX] == grid[c[0]][c[1]]){
                    dq.add(new int[]{dY, dX});
                }
            }
        }
        return false;
    }
}
/*
4
3
S11
011
00F
3
S11
101
11F
3
S00
110
00F
3
S11
001
00F
*/