import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter; // System.out is a PrintWriter
// import java.util.Arrays;
import java.util.ArrayDeque;
import java.util.ArrayList;
// import java.util.ArrayList;
// import java.util.Collections;    //  for ArrayList sorting mainly
// import java.util.HashMap;
// import java.util.hashset;
// import java.util.Random;
import java.util.StringTokenizer;

public class B {
    public static void main(String[] args) throws IOException {
        FastScanner scn = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int tc = scn.nextInt();
        while (tc-- > 0) {
            int N = scn.nextInt();
            char[][] grid = new char[N][];
            for (int i = 0; i < N; i++) {
                grid[i] = scn.next().toCharArray();
            }
            ArrayList<String> ans = new ArrayList<>();
            // for 0;
            boolean[][] vis = new boolean[N][N];
            if (BFS(grid, '1', N, vis)) {
                if (vis[N - 2][N - 2] && vis[N - 3][N - 1] && vis[N - 1][N - 3]) {
                    if (vis[N - 1][N - 2]) {
                        grid[N - 1][N - 2] = '1';
                        ans.add(N + " " + (N - 1));
                    }
                    if (vis[N - 2][N - 1]) {
                        grid[N - 2][N - 1] = '1';
                        ans.add((N - 1) + " " + N);
                    }
                } else {
                    if (vis[N - 2][N - 2]) {
                        grid[N - 2][N - 2] = '1';
                        ans.add((N - 1) + " " + (N - 1));
                    }
                    if (vis[N - 3][N - 1]) {
                        grid[N - 3][N - 1] = '1';
                        ans.add((N - 2) + " " + N);
                    }
                    if (vis[N - 1][N - 3]) {
                        grid[N - 1][N - 3] = '1';
                        ans.add(N + " " + (N - 2));
                    }
                }
            }
            // for 1
            vis = new boolean[N][N];
            if (BFS(grid, '0', N, vis)) {
                if (vis[N - 2][N - 2] && vis[N - 3][N - 1] && vis[N - 1][N - 3]) {
                    if (vis[N - 1][N - 2]) {
                        ans.add(N + " " + (N - 1));
                    }
                    if (vis[N - 2][N - 1]) {
                        ans.add((N - 1) + " " + N);
                    }
                } else {
                    if (vis[N - 2][N - 2]) {
                        ans.add((N - 1) + " " + (N - 1));
                    }
                    if (vis[N - 3][N - 1]) {
                        ans.add((N - 2) + " " + N);
                    }
                    if (vis[N - 1][N - 3]) {
                        ans.add(N + " " + (N - 2));
                    }
                }
            }
            out.println(ans.size());
            if (ans.size() <= 2)
            for (String str : ans) {
                out.println(str);
            }
        }
        out.close();
    }

    private static boolean BFS(char[][] grid, char val, int N, boolean[][] vis) {
        ArrayDeque<int[]> que = new ArrayDeque<>();
        que.addLast(new int[] { 0, 0 });
        while (que.size() != 0) {
            int size = que.size();
            while (size-- > 0) {
                int[] vtx = que.removeFirst();
                if (vtx[0] == N - 1 && vtx[1] == N - 1) {
                    return true;
                }
                vis[vtx[0]][vtx[1]] = true;
                if (vtx[0] != N - 1 && grid[vtx[0] + 1][vtx[1]] != val) {
                    que.addLast(new int[] { vtx[0] + 1, vtx[1] });
                }
                if (vtx[1] != N - 1 && grid[vtx[0]][vtx[1] + 1] != val) {
                    que.addLast(new int[] { vtx[0], vtx[1] + 1 });
                }
            }
        }
        return false;
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner() {
            this.br = new BufferedReader(new InputStreamReader(System.in));
            this.st = new StringTokenizer("");
        }

        String next() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException err) {
                    err.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            if (st.hasMoreTokens()) {
                return st.nextToken("").trim();
            }
            try {
                return br.readLine().trim();
            } catch (IOException err) {
                err.printStackTrace();
            }
            return "";
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

    }
}
