// Main Code at the Bottom
import java.util.*;
import java.io.*; 
public class Main{
	//Fast IO class
    static class FastReader {
        BufferedReader br; 
        StringTokenizer st; 
        public FastReader() {
        	boolean env=System.getProperty("ONLINE_JUDGE") != null;
        	if(!env) {
        		try {
					br=new BufferedReader(new FileReader("src\\input.txt"));
				} catch (FileNotFoundException e) {
					e.printStackTrace();
				}
        	}
        	else br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) {
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
        int nextInt() {
            return Integer.parseInt(next()); 
        } 
        long nextLong() {
            return Long.parseLong(next()); 
        } 
        double nextDouble() {
            return Double.parseDouble(next()); 
        } 
        String nextLine() {
            String str = ""; 
            try {
                str = br.readLine(); 
            } 
            catch (IOException e) {
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }     
    static long MOD=(long)1e9+7;
    //debug
    static void debug(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
    // Pair
    static class pair{
    	long x,y;
    	pair(long a,long b){
    		this.x=a;
    		this.y=b;
    	}
    	public boolean equals(Object obj) {
    		if(obj == null || obj.getClass()!= this.getClass()) return false;
            pair p = (pair) obj;
            return (this.x==p.x && this.y==p.y);
        }
    	public int hashCode() {
            return Objects.hash(x,y);
        }
    }
    static FastReader sc=new FastReader();
    static PrintWriter out=new PrintWriter(System.out);  
    //Global variables and functions
    static int moves[][]= {{0,1},{0,-1},{1,0},{-1,0}};
    static boolean check(char s[][],int x,int y,int n) {
    	int visited[][]=new int[n][n];
    	Queue<int []> q=new LinkedList<>();
    	q.add(new int[] {x,y});
    	char c=s[x][y];
    	while(!q.isEmpty()) {
    		int p[]=q.poll();
    		int i=p[0],j=p[1];
    		if(visited[i][j]==1) continue;
    		if(i==n-1 && j==n-1) return true;
    		visited[i][j]=1;
    		if(s[i][j]!=c) continue;
    		for(int m[]: moves) {
    			int k=i+m[0],l=j+m[1];
    			if(k<0 || k>=n || l<0 || l>=n) continue;
    			q.add(new int[] {k,l});
    		}
    	}
    	return false;
    }
    //Main function(The main code starts from here)
    public static void main (String[] args) throws java.lang.Exception {
    	int test=1;
    	test=sc.nextInt();
    	while(test-->0) {
    		int n=sc.nextInt();
    		char s[][]=new char[n][n];
    		for(int i=0;i<n;i++) s[i]=sc.nextLine().toCharArray();
    		boolean v1=check(s,0,1,n),v2=check(s,1,0,n);
    		if(v1 && v2) {
    			if(s[1][1]=='0') s[1][1]='1';
    			else s[1][1]='0';
    			if(check(s,0,1,n) || check(s,1,0,n)) {
    				out.println(2);
    				out.println("1 2");
    				out.println("2 1");
    			}
    			else {
    				out.println(1);
    				out.println("2 2");
    			}
    		}
    		else if(v1) {
    			if(s[0][1]=='0') s[0][1]='1';
    			else s[0][1]='0';
    			if(check(s,0,1,n)) {
    				out.println(2);
    				out.println("1 2");
    				if(s[0][2]==s[0][1]) out.println("1 3");
    				else out.println("2 2");
    			}
    			else {
    				out.println(1);
    				out.println("1 2");
    			}
    		}
    		else if(v2) {
    			if(s[1][0]=='0') s[1][0]='1';
    			else s[1][0]='0';
    			if(check(s,1,0,n)) {
    				out.println(2);
    				out.println("2 1");
    				if(s[2][0]==s[1][0]) out.println("3 1");
    				else out.println("2 2");
    			}
    			else {
    				out.println(1);
    				out.println("2 1");
    			}
    		}
    		else out.println(0);
    	}	
        out.flush();
        out.close();
    }
}