#include <iostream>
#include <cmath>
#include <utility>
#include <vector>

using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
#define mp make_pair
#define x first
#define y second

int main () {
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		char grid[203][203];
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				cin>>grid[i][j];
			}
		}
		int s1=int(grid[1][2])-48;
		int s2=int(grid[2][1])-48;
		int f1=int(grid[n][n-1])-48;
		int f2=int(grid[n-1][n])-48;
		vector<pii> sol;
		if(s1==s2){
			int x=(s1+1)%2;
			if(f1!=x){
				sol.push_back(mp(n,n-1));
			}
			if(f2!=x){
				sol.push_back(mp(n-1,n));
			}
			cout<<sol.size()<<endl;
			for(int i=0;i<sol.size();i++){
				cout<<sol[i].x<<" "<<sol[i].y<<endl;
			}
		}
		else if(f1==f2){
			int x=(s1+1)%2;
			if(s1!=x){
				sol.push_back(mp(1,2));
			}
			if(s2!=x){
				sol.push_back(mp(2,1));
			}
			cout<<sol.size()<<endl;
			for(int i=0;i<sol.size();i++){
				cout<<sol[i].x<<" "<<sol[i].y<<endl;
			}
		}
		else{
			int x=(s1+1)%2;
			sol.push_back(mp(2,1));
			if(f1!=x){
				sol.push_back(mp(n,n-1));
			}
			if(f2!=x){
				sol.push_back(mp(n-1,n));
			}
			cout<<sol.size()<<endl;
			for(int i=0;i<sol.size();i++){
				cout<<sol[i].x<<" "<<sol[i].y<<endl;
			}
		}

	}

return 0;
}


#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second

using namespace std;
const int INF = 0x3f3f3f3f;//?????
typedef long long ll;
typedef long double ld;
typedef pair<ll, int>  pll;
typedef pair<int, int> pii;
const int N = 1000000;
char a[205][205];int b[105],prime[N],st[N];ll sum[N];
int cnt=0;
ll qpow(ll x,ll y,ll mod)
{
	int ans=1;
	while(y)
	{
		if(y&1) ans=ans*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return ans%mod;
}
void ola()
{
	for(int i=2;i<=1000000;i++)
	{
		if(st[i]==0)
		{
			prime[cnt++]=i;
		}
		for(int j=0;j<cnt&&i*prime[j]<=1000000;j++)
		{
			st[i*prime[j]]=1;
			if(i%prime[j]==0) break;
		 }
	}
}
int main()
{
	IOS;
	int t; cin >> t;
	while(t--)
	{

		int n; cin >> n;
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
			{
				cin >> a[i][j];
			}
		}
		int t1=a[1][2]-'0',t2=a[2][1]-'0',t3=a[n][n-1]-'0',t4=a[n-1][n]-'0';
		if(t1==t2&&t3==t4&&t1!=t3) cout << "0" << endl;
		else if(t1==t2==t3==t4)
		{
			cout << 2 << endl;
			cout << 2 << " " << 1 << endl;
			cout << 1 << " " << 2 << endl;
		}
		else if(t1!=t2&&t3==t4&&t1==t3)
		{
			cout << 1 << endl;
			cout << 1 << " " << 2 << endl;
		}
		else if(t1!=t2&&t3==t4&&t2==t3)
		{
			cout << "1" << endl;
			cout << 2 << " " << 1 << endl;
		}
		else if(t3!=t4&&t1==t2&&t1==t3)
		{
			cout << 1 << endl;
			cout << n << " " << n-1 << endl;
		}
		else if(t3!=t4&&t1==t2&&t1==t4)
		{
			cout << 1 << endl;
			cout << n-1 << " " << n << endl;
		}
		else if(t1==t3&&t2==t4&&t1!=t2)
		{
			cout << 2 << endl;
			cout << 2 << " " << 1 << endl;
			cout << n << " " << n-1 << endl;
		}
		else if(t1==t4&&t2==t3&&t1!=t2)
		{
			cout << 2 << endl;
			cout << 2 << " " << 1 << endl;
			cout << n-1 << " " << n << endl;
		}
	}
	return 0;
}


#include<iostream>
#include<cstring>
#define nl if(t){puts("");}
using namespace std;

const int maxn=200+5,dx[]={-1,0,0,1},dy[]={0,-1,1,0};
int t,n,Map[maxn][maxn];
bool d0,d1,vis[maxn][maxn];

void dfs0(int x,int y){
	vis[x][y]=1;
	for(int a=0;a<4;a++){
		int xx=x+dx[a],yy=y+dy[a];
		if(0<=xx && xx<n && 0<=yy && yy<n && !vis[xx][yy]){
			if(Map[xx][yy]=='F'-'0') d0=0;
			else if(Map[xx][yy]==0) dfs0(xx,yy);
		}
	}
}

void dfs1(int x,int y){
	vis[x][y]=1;
	for(int a=0;a<4;a++){
		int xx=x+dx[a],yy=y+dy[a];
		if(0<=xx && xx<n && 0<=yy && yy<n && !vis[xx][yy]){
			if(Map[xx][yy]=='F'-'0') d1=0;
			else if(Map[xx][yy]==1) dfs1(xx,yy);
		}
	}
}

void DO(){
	memset(vis,0,sizeof(vis));
	d0=d1=1;
	dfs0(0,0);
	memset(vis,0,sizeof(vis));
	dfs1(0,0);
}

int main(){
	cin>>t;
	while(t--){
		cin>>n;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				char x;
				cin>>x;
				Map[i][j]=x-'0';
			}
		}
		DO();
		if(d0 && d1){ printf("0"); nl; continue; }
		Map[n-2][n-1]=!Map[n-2][n-1];
		DO();
		if(d0 && d1){ printf("1\n%d %d",n-1,n); nl; continue; }
		Map[n-1][n-2]=!Map[n-1][n-2];
		DO();
		if(d0 && d1){ printf("2\n%d %d\n%d %d",n-1,n,n,n-1); nl; continue; }
		Map[n-2][n-1]=!Map[n-2][n-1];
		DO();
		if(d0 && d1){ printf("1\n%d %d",n,n-1); nl; }
	}
	return 0;
}


/*
ID: Trump
TASK:
LANG: C++
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include <iostream>
#include <fstream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double lb;
//#define MARK
const ll losn=1e6+5;
const ll maxn=1e5+5;
const ll minn=1e3+5;
const ll tiny=1e2+5;
const ll inf=1e9;
const ll binf=1e18;
const ll mod=1e9+7;
const ll hmod=4698571;
void ck(){cout<<1<<endl;}

char c[205][205];
int main(){
//#ifdef MARK
//    freopen("input.in", "r", stdin);
//    freopen("ouput.out", "w", stdout);
//    freopen("input.in", "r", stdin);
//    freopen("ouput.out", "w", stdout);
//#endif
	ll t;
	cin>>t;
	while(t--){
		ll n;
		cin>>n;
		for(ll i=1;i<=n;i++){
			for(ll j=1;j<=n;j++){
				cin>>c[i][j];
			}
		}
		ll arr[5];
		arr[1]=c[1][2]-'0';
		arr[2]=c[2][1]-'0';
		arr[3]=c[n][n-1]-'0';
		arr[4]=c[n-1][n]-'0';
		ll as[2][5]={
		{0,0,1,1},
		{1,1,0,0}};
		ll s[4][2]={
		{1,2},
		{2,1},
		{n,n-1},
		{n-1,n}};
		for(ll j=0;j<2;j++){
			ll k=0;
			for(ll i=0;i<4;i++){
				if(arr[i+1]!=as[j][i]){
					k++;
				}
			}
			if(k<=2){
				cout<<k<<endl;
				for(ll i=0;i<4;i++){
					if(arr[i+1]!=as[j][i]){
						cout<<s[i][0]<<" "<<s[i][1]<<endl;
					}
				}
				break;
			}
		}
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define ll long long
#define fo(i,x,y) for(register int i=x;i<=y;++i)
#define go(i,x,y) for(register int i=x;i>=y;--i)
using namespace std;

inline int read(){
    int x=0,fh=1;
    char ch=getchar();
    while(!isdigit(ch)){
        if(ch=='-') fh=-1;
        ch=getchar();
    }
    while(isdigit(ch)){
        x=(x<<1)+(x<<3)+ch-'0';
        ch=getchar();
    }
    return x*fh;
}

const int maxn=205;
string a[maxn],s;

void work(){
    int n=read(),ans=0;
    fo(i,0,n-1) cin>>a[i];
    s.resize(4);
    s[0]=a[0][1];
    s[1]=a[1][0];
    s[2]=a[n-1][n-2];
    s[3]=a[n-2][n-1];
    if(s=="0011"||s=="1100"){
        puts("0");
        return;
    }
    if(s=="0000"||s=="1111"){
        puts("2");
        puts("1 2");
        puts("2 1");
        return;
    }
    if(s[0]!=s[1]){
        if(s[2]==s[3]){
            puts("1");
            if(s[0]==s[2]) puts("1 2");
            else puts("2 1");
        }else{
            puts("2");
            if(s[0]=='1') puts("1 2");
            else puts("2 1");
            if(s[2]=='0') printf("%d %d\n",n,n-1);
            else printf("%d %d\n",n-1,n);
        }
    }else{
        puts("1");
        if(s[2]==s[0]) printf("%d %d\n",n,n-1);
        else printf("%d %d\n",n-1,n);
    }
}
int main(){
    int T=read();
    while(T--){
        work();
    }
    return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<iostream>
#define R register
using namespace std;
inline int read() {
	R int x=0,f=0,ch=getchar();
	while('0'>ch||ch>'9')f^=ch=='-',ch=getchar();
	while('0'<=ch&&ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=getchar();
	return f?-x:x;
}
int t,n;
struct node{
	string s;
}a[210];
int main(){
	t=read();
	while(t--){
		n=read();
		int ans=0;
		for(int i=1;i<=n;i++)
			cin>>a[i].s;
		if(a[1].s[1]==a[2].s[0]){
			if(a[n].s[n-2]==a[1].s[1])
				++ans;
			if(a[n-1].s[n-1]==a[1].s[1])
				++ans;
			printf("%d\n",ans);
			if(a[n].s[n-2]==a[1].s[1])
				printf("%d %d\n",n,n-1);
			if(a[n-1].s[n-1]==a[1].s[1])
				printf("%d %d\n",n-1,n);
		}
		else{
			if(a[n].s[n-2]==a[n-1].s[n-1]){
				puts("1");
				if(a[n].s[n-2]==a[1].s[1])
					puts("1 2");
				else
					puts("2 1");
				continue;
			}
			puts("2");
			if(a[n].s[n-2]==a[1].s[1])
				printf("%d %d\n2 1\n",n,n-1);
			else
				printf("%d %d\n1 2\n",n,n-1);
		}
	}
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<iostream>
#define R register
using namespace std;
inline int read() {
	R int x=0,f=0,ch=getchar();
	while('0'>ch||ch>'9')f^=ch=='-',ch=getchar();
	while('0'<=ch&&ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=getchar();
	return f?-x:x;
}
int t,n;
struct node{
	string s;
}a[210];
int main(){
	t=read();
	while(t--){
		n=read();
		int ans=0;
		for(int i=1;i<=n;i++)
			cin>>a[i].s;
		if(a[1].s[1]==a[2].s[0]){
			if(a[n].s[n-2]==a[1].s[1])
				++ans;
			if(a[n-1].s[n-1]==a[1].s[1])
				++ans;
			printf("%d\n",ans);
			if(a[n].s[n-2]==a[1].s[1])
				printf("%d %d\n",n,n-1);
			if(a[n-1].s[n-1]==a[1].s[1])
				printf("%d %d\n",n-1,n);
		}
		else{
			if(a[n].s[n-2]==a[n-1].s[n-1]){
				puts("1");
				if(a[n].s[n-2]==a[1].s[1])
					puts("2 1");
				else
					puts("1 2");
				continue;
			}
			puts("2");
			if(a[n].s[n-2]==a[1].s[1])
				printf("%d %d\n1 1\n",n,n-1);
			else
				printf("%d %d\n1 1\n",n-1,n);
		}
	}
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<iostream>
#define R register
using namespace std;
inline int read() {
	R int x=0,f=0,ch=getchar();
	while('0'>ch||ch>'9')f^=ch=='-',ch=getchar();
	while('0'<=ch&&ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=getchar();
	return f?-x:x;
}
int t,n;
struct node{
	string s;
}a[210];
int main(){
	t=read();
	while(t--){
		n=read();
		int ans=0;
		for(int i=1;i<=n;i++)
			cin>>a[i].s;
		if(a[1].s[1]==a[2].s[0]){
			if(a[n].s[n-2]==a[1].s[1])
				++ans;
			if(a[n-1].s[n-1]==a[1].s[1])
				++ans;
			printf("%d\n",ans);
			if(a[n].s[n-2]==a[1].s[1])
				printf("%d %d\n",n,n-1);
			if(a[n-1].s[n-1]==a[1].s[1])
				printf("%d %d\n",n-1,n);
		}
		else{
			if(a[n].s[n-2]==a[n-1].s[n-1]){
				puts("1");
				if(a[n].s[n-2]==a[1].s[1])
					puts("1 2");
				else
					puts("2 1");
				continue;
			}
			puts("2");
			if(a[n].s[n-2]==a[1].s[1])
				printf("%d %d\n1 2\n",n,n-1);
			else
				printf("%d %d\n1 2\n",n-1,n);
		}
	}
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<iostream>
#define R register
using namespace std;
inline int read() {
	R int x=0,f=0,ch=getchar();
	while('0'>ch||ch>'9')f^=ch=='-',ch=getchar();
	while('0'<=ch&&ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=getchar();
	return f?-x:x;
}
int t,n;
struct node{
	string s;
}a[210];
int main(){
	t=read();
	while(t--){
		n=read();
		int ans=0;
		for(int i=1;i<=n;i++)
			cin>>a[i].s;
		if(a[1].s[1]==a[2].s[0]){
			if(a[n].s[n-2]==a[1].s[1])
				++ans;
			if(a[n-1].s[n-1]==a[1].s[1])
				++ans;
			printf("%d\n",ans);
			if(a[n].s[n-2]==a[1].s[1])
				printf("%d %d\n",n,n-1);
			if(a[n-1].s[n-1]==a[1].s[1])
				printf("%d %d\n",n-1,n);
		}
		else{
			if(a[n].s[n-2]==a[n-1].s[n-1]){
				puts("1");
				if(a[n].s[n-2]==a[1].s[1])
					puts("1 2");
				else
					puts("2 1");
				continue;
			}
			puts("2");
			if(a[n].s[n-2]==a[1].s[1])
				printf("%d %d\n1 1\n",n,n-1);
			else
				printf("%d %d\n1 1\n",n-1,n);
		}
	}
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<iostream>
#define R register
using namespace std;
inline int read() {
	R int x=0,f=0,ch=getchar();
	while('0'>ch||ch>'9')f^=ch=='-',ch=getchar();
	while('0'<=ch&&ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=getchar();
	return f?-x:x;
}
int t,n;
struct node{
	string s;
}a[210];
int main(){
	t=read();
	while(t--){
		n=read();
		int ans=0;
		for(int i=1;i<=n;i++)
			cin>>a[i].s;
		if(a[1].s[1]==a[2].s[0]){
			if(a[n].s[n-2]==a[1].s[1])
				++ans;
			if(a[n-1].s[n-1]==a[1].s[1])
				++ans;
			printf("%d\n",ans);
			if(a[n].s[n-2]==a[1].s[1])
				printf("%d %d\n",n,n-1);
			if(a[n-1].s[n-1]==a[1].s[1])
				printf("%d %d\n",n-1,n);
		}
		else{
			puts("2");
			if(a[n].s[n-2]==a[1].s[1])
				printf("%d %d\n1 1\n",n,n-1);
			else
				printf("%d %d\n1 1\n",n-1,n);
		}
	}
	return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define base 31
#define MOD 1e9+7
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FORs(i, a, b) for(int i = a; i >= b; i--)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define __FOR(i, a, b, k) for(int i = a; i <= b; i+= k)
#define __REP(i, a, b, k) for(int i = a; i < b; i+= k)
#define pb push_back
#define _io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define Read_ freopen("input.inp", "r", stdin)
#define Write_ freopen("output.out", "w", stdout);
using namespace std;
typedef pair <int, int> ii;
typedef vector <ii> vii;
#define fi first
#define se second
#define mp make_pair
#define N  500
int t,n,res=0;
char a[N][N];
int v[N],v2[N];
int main(){
    _io;

    cin>>t;
    while(t--){
        cin>>n;
        FOR(i,1,n){
            FOR(j,1,n){
                char x;
                cin>>x;
                a[i][j]=x;
            }
        }
        if (a[1][2]==a[2][1]){
            if ((a[n][n-1]==a[n-1][n])&&(a[n][n-1]!=a[1][2])){
                cout<<0<<"\n";
            }
            if ((a[n][n-1]==a[n-1][n])&&(a[n][n-1]==a[1][2])){
                cout<<2<<"\n";
                cout<<1<<" "<<2<<"\n";
                cout<<2<<" "<<1<<"\n";
            }
            if (a[n][n-1]!=a[n-1][n]){
                if (a[n][n-1]==a[1][2]){
                    cout<<1<<"\n";
                    cout<<n<<" "<<n-1<<"\n";
                }
                else {
                    cout<<1<<"\n";
                    cout<<n-1<<" "<<n<<"\n";
                }
            }
        }
        else {
            if (a[n][n-1]==a[n-1][n]){
                if (a[1][2]==a[n][n-1]){
                    cout<<1<<"\n";
                    cout<<1<<" "<<2<<"\n";
                }
                else {
                    cout<<1<<"\n";
                    cout<<2<<" "<<1<<"\n";
                }
            }
            if (a[n][n-1]!=a[n-1][n]){
                cout<<2<<"\n";
                if (a[1][2]=='1'){
                    cout<<1<<" "<<2<<"\n";
                }
                else cout<<2<<" "<<1<<"\n";
                if (a[n][n-1]=='0'){
                    cout<<n<<" "<<n-1<<"\n";
                }
                else cout<<n-1<<" "<<n<<"\n";
            }
        }

    }
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define base 31
#define MOD 1e9+7
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FORs(i, a, b) for(int i = a; i >= b; i--)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define __FOR(i, a, b, k) for(int i = a; i <= b; i+= k)
#define __REP(i, a, b, k) for(int i = a; i < b; i+= k)
#define pb push_back
#define _io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define Read_ freopen("input.inp", "r", stdin)
#define Write_ freopen("output.out", "w", stdout);
using namespace std;
typedef pair <int, int> ii;
typedef vector <ii> vii;
#define fi first
#define se second
#define mp make_pair
#define N  500
int t,n,res=0;
char a[N][N];
int v[N],v2[N];
int main(){
    _io;

    cin>>t;
    while(t--){
        cin>>n;
        FOR(i,1,n){
            FOR(j,1,n){
                char x;
                cin>>x;
                a[i][j]=x;
            }
        }
        if (a[1][2]==a[2][1]){
            if ((a[n][n-1]==a[n-1][n])&&(a[n][n-1]!=a[1][2])){
                cout<<0<<"\n"; return 0;
            }
            if ((a[n][n-1]==a[n-1][n])&&(a[n][n-1]==a[1][2])){
                cout<<2<<"\n";
                cout<<n<<" "<<n-1<<"\n";
                cout<<n-1<<" "<<n<<"\n";
            }
            if (a[n][n-1]!=a[n-1][n]){
                if (a[n][n-1]==a[1][2]){
                    cout<<1<<"\n";
                    cout<<n<<" "<<n-1<<"\n";
                }
                else {
                    cout<<1<<"\n";
                    cout<<n-1<<" "<<n<<"\n";
                }
            }
        }
        else {
            if (a[n][n-1]==a[n-1][n]){
                if (a[1][2]==a[n][n-1]){
                    cout<<1<<"\n";
                    cout<<1<<" "<<2<<"\n";
                }
                else {
                    cout<<1<<"\n";
                    cout<<2<<" "<<1<<"\n";
                }
            }
            if (a[n][n-1]!=a[n-1][n]){
                cout<<2<<"\n";
                if (a[1][2]=='1'){
                    cout<<1<<" "<<2<<"\n";
                }
                else cout<<2<<" "<<1<<"\n";
                if (a[n][n-1]=='0'){
                    cout<<n<<" "<<n-1<<"\n";
                }
                else cout<<n-1<<" "<<n<<"\n";
            }
        }

    }
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define base 31
#define MOD 1e9+7
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FORs(i, a, b) for(int i = a; i >= b; i--)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define __FOR(i, a, b, k) for(int i = a; i <= b; i+= k)
#define __REP(i, a, b, k) for(int i = a; i < b; i+= k)
#define pb push_back
#define _io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define Read_ freopen("input.inp", "r", stdin)
#define Write_ freopen("output.out", "w", stdout);
using namespace std;
typedef pair <int, int> ii;
typedef vector <ii> vii;
#define fi first
#define se second
#define mp make_pair
#define N  500
int t,n,res=0;
char a[N][N];
int v[N],v2[N];
int main(){
    _io;
    //Read_; Write_;
    cin>>t;
    while(t--){
        cin>>n;
        FOR(i,1,n){
            FOR(j,1,n){
                char x;
                cin>>x;
                a[i][j]=x;
            }
        }
        if (a[1][2]==a[2][1]){
            if ((a[n][n-1]==a[n-1][n])&&(a[n][n-1]!=a[1][2])){
                cout<<0<<"\n"; return 0;
            }
            if ((a[n][n-1]==a[n-1][n])&&(a[n][n-1]==a[1][2])){
                cout<<2<<"\n";
                cout<<1<<" "<<2<<"\n";
                cout<<2<<" "<<1<<"\n";
            }
            if (a[n][n-1]!=a[n-1][n]){
                if (a[n][n-1]==a[1][2]){
                    cout<<1<<"\n";
                    cout<<n<<" "<<n-1<<"\n";
                }
                else {
                    cout<<1<<"\n";
                    cout<<n-1<<" "<<n<<"\n";
                }
            }
        }
        else {
            if (a[n][n-1]==a[n-1][n]){
                if (a[1][2]==a[n][n-1]){
                    cout<<1<<"\n";
                    cout<<1<<" "<<2<<"\n";
                }
                else {
                    cout<<1<<"\n";
                    cout<<2<<" "<<1<<"\n";
                }
            }
            if (a[n][n-1]!=a[n-1][n]){
                cout<<2<<"\n";
                if (a[1][2]=='1'){
                    cout<<1<<" "<<2<<"\n";
                }
                else cout<<2<<" "<<1<<"\n";
                if (a[n][n-1]=='0'){
                    cout<<n<<" "<<n-1<<"\n";
                }
                else cout<<n-1<<" "<<n<<"\n";
            }
        }

    }
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define base 31
#define MOD 1e9+7
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FORs(i, a, b) for(int i = a; i >= b; i--)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define __FOR(i, a, b, k) for(int i = a; i <= b; i+= k)
#define __REP(i, a, b, k) for(int i = a; i < b; i+= k)
#define pb push_back
#define _io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define Read_ freopen("input.inp", "r", stdin)
#define Write_ freopen("output.out", "w", stdout);
using namespace std;
typedef pair <int, int> ii;
typedef vector <ii> vii;
#define fi first
#define se second
#define mp make_pair
#define N  500
int t,n,res=0;
char a[N][N];
int v[N],v2[N];
int main(){
    _io;

    cin>>t;
    while(t--){
        cin>>n;
        FOR(i,1,n){
            FOR(j,1,n){
                char x;
                cin>>x;
                a[i][j]=x;
            }
        }
        if ((a[1][2]==a[2][1]) && (a[n][n-1]==a[n-1][n]) && (a[1][2]!=a[n][n-1])){
            cout<<0<<"\n";
            return 0;
        }
        if (a[1][2]==a[2][1]){
            if ((a[n][n-1]==a[n-1][n])&&(a[n][n-1]!=a[1][2])){
                cout<<0<<"\n"; return 0;
            }
            if ((a[n][n-1]==a[n-1][n])&&(a[n][n-1]==a[1][2])){
                cout<<2<<"\n";
                cout<<n<<" "<<n-1<<"\n";
                cout<<n-1<<" "<<n<<"\n";
            }
            if (a[n][n-1]!=a[n-1][n]){
                if (a[n][n-1]==a[1][2]){
                    cout<<1<<"\n";
                    cout<<n<<" "<<n-1<<"\n";
                }
                else {
                    cout<<1<<"\n";
                    cout<<n-1<<" "<<n<<"\n";
                }
            }
        }
        else {
            if (a[n][n-1]==a[n-1][n]){
                if (a[1][2]==a[n][n-1]){
                    cout<<1<<"\n";
                    cout<<1<<" "<<2<<"\n";
                }
                else {
                    cout<<1<<"\n";
                    cout<<2<<" "<<1<<"\n";
                }
            }
            if (a[n][n-1]!=a[n-1][n]){
                cout<<2<<"\n";
                if (a[1][2]=='1'){
                    cout<<1<<" "<<2<<"\n";
                }
                else cout<<2<<" "<<1<<"\n";
                if (a[n][n-1]=='0'){
                    cout<<n<<" "<<n-1<<"\n";
                }
                else cout<<n-1<<" "<<n<<"\n";
            }
        }

    }
    return 0;
}


typedef long long ll;
typedef unsigned long long ull;
#define base 31
#define MOD 1e9+7
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FORs(i, a, b) for(int i = a; i >= b; i--)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define __FOR(i, a, b, k) for(int i = a; i <= b; i+= k)
#define __REP(i, a, b, k) for(int i = a; i < b; i+= k)
#define pb push_back
#define _io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define Read_ freopen("input.inp", "r", stdin)
#define Write_ freopen("output.out", "w", stdout);
using namespace std;
typedef pair <int, int> ii;
typedef vector <ii> vii;
#define fi first
#define se second
#define mp make_pair
#define N  500
int t,n,res=0;
char a[N][N];
int v[N],v2[N];
int main(){
    _io;
   // Read_; Write_;
    cin>>t;
    while(t--){
        cin>>n;
        FOR(i,1,n){
            FOR(j,1,n){
                char x;
                cin>>x;
                a[i][j]=x;
            }
        }
        if (a[1][2]==a[2][1]){
            if ((a[n][n-1]==a[n-1][n])&&(a[n][n-1]!=a[1][2])){
                cout<<0<<"\n"; return 0;
            }
            if ((a[n][n-1]==a[n-1][n])&&(a[n][n-1]==a[1][2])){
                cout<<2<<"\n";
                cout<<1<<" "<<2<<"\n";
                cout<<2<<" "<<1<<"\n";
            }
            if (a[n][n-1]!=a[n-1][n]){
                if (a[n][n-1]==a[1][2]){
                    cout<<1<<"\n";
                    cout<<n<<" "<<n-1<<"\n";
                }
                else {
                    cout<<1<<"\n";
                    cout<<n-1<<" "<<n<<"\n";
                }
            }
        }
        else {
            if (a[n][n-1]==a[n-1][n]){
                if (a[1][2]==a[n][n-1]){
                    cout<<1<<"\n";
                    cout<<1<<" "<<2<<"\n";
                }
                else {
                    cout<<1<<"\n";
                    cout<<2<<" "<<1<<"\n";
                }
            }
            if (a[n][n-1]!=a[n-1][n]){
                cout<<2<<"\n";
                if (a[1][2]=='1'){
                    cout<<1<<" "<<2<<"\n";
                }
                else cout<<2<<" "<<1<<"\n";
                if (a[n][n-1]=='0'){
                    cout<<n<<" "<<n-1<<"\n";
                }
                else cout<<n-1<<" "<<n<<"\n";
            }
        }

    }
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define base 31
#define MOD 1e9+7
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FORs(i, a, b) for(int i = a; i >= b; i--)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define __FOR(i, a, b, k) for(int i = a; i <= b; i+= k)
#define __REP(i, a, b, k) for(int i = a; i < b; i+= k)
#define pb push_back
#define _io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define Read_ freopen("input.inp", "r", stdin)
#define Write_ freopen("output.out", "w", stdout);
using namespace std;
typedef pair <int, int> ii;
typedef vector <ii> vii;
#define fi first
#define se second
#define mp make_pair
#define N  500
int t,n,res=0;
char a[N][N];
int v[N],v2[N];
int main(){
    _io;

    cin>>t;
    while(t--){
        cin>>n;
        FOR(i,1,n){
            FOR(j,1,n){
                char x;
                cin>>x;
                a[i][j]=x;
            }
        }
        FOR(i,n-2,n){
            FOR(j,n-2,n){
                if (i==n-2 || j==n-2){
                    if (a[i][j]!='1'){
                        ++res;
                        v[res]=i; v2[res]=j;
                    }
                }
                else {
                    if (a[i][j]!='0'){
                        ++res;
                        v[res]=i; v2[res]=j;
                    }
                }
            }
        }
        /*
        FOR(i,1,n){
            FOR(j,1,n){
                cout<<a[i][j];
            }
            cout<<"\n";
        }*/
        cout<<res<<"\n";
        FOR(i,1,res) cout<<v[i]<<" "<<v2[i]<<"\n";
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
    int t;
    cin >> t;
    while(t--) {
        long long n;
        cin >> n;
        vector<string> strvec;
        for(int i = 0; i < n; ++i) {
            string str;
            cin >> str;
            strvec.push_back(str);
        }
        char sr = strvec[0][1];
        char sd = strvec[1][0];
        char fu = strvec[n - 2][n - 1];
        char fl = strvec[n - 1][n - 2];

        int cnt = 0;
        long long c1r = -1;
        long long c1c = -1;
        long long c2r = -1;
        long long c2c = -1;
        if (sr == sd) {

            if (fu == sr) {
                ++cnt;
                c1r = n - 2;
                c1c = n - 1;

            }
            if (fl == sd) {
                ++cnt;
                c2r = n - 1;
                c2c = n - 2;

            }

        } else {
            if (fu == fl) {

                if (sd == fu) {
                    cnt = 1;
                    c1r = 1;
                    c1c = 0;
                } else {
                    cnt = 1;
                    c1r = 0;
                    c1c = 1;
                }
            } else {
                if (sd == fu) {
                    cnt = 2;
                    c1r = 0;
                    c1c = 1;
                    c2r = n - 2;
                    c2c = n - 1;
                }  else {
                    cnt = 2;
                    c1r = 0;
                    c1c = 1;
                    c2r = n - 1;
                    c2c = n - 2;
                }
            }
        }

        cout << cnt << endl;
        if (c1r != -1) {
            cout << (c1r + 1) <<" " <<c1c + 1<<endl;
        }
        if (c2r != -1) {
            cout << c2r  + 1<< " " << (c2c) + 1 << endl;
        }
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
    int t;
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        vector<string> strvec;
        for(int i = 0; i < n; ++i) {
            string str;
            cin >> str;
            strvec.push_back(str);
        }
        char sr = strvec[0][1];
        char sd = strvec[1][0];
        char fu = strvec[n - 2][n - 1];
        char fl = strvec[n - 1][n - 2];

        int cnt = 0;
        char c1r = 'n';
        char c1c = 'n';
        char c2r = 'n';
        char c2c = 'n';
        if (sr == sd) {

            if (fu == sr) {
                ++cnt;
                c1r = n - 2;
                c1c = n - 1;

            }
            if (fl == sd) {
                ++cnt;
                c2r = n - 1;
                c2c = n - 2;

            }

        } else {
            if (fu == fl) {

                if (sd == fu) {
                    cnt = 1;
                    c1r = 1;
                    c1c = 0;
                } else {
                    cnt = 1;
                    c1r = 0;
                    c1c = 1;
                }
            } else {
                if (sd == fu) {
                    cnt = 2;
                    c1r = 0;
                    c1c = 1;
                    c2r = n -1;
                    c2c = n - 2;
                }  else {
                    cnt = 2;
                    c1r = 1;
                    c1c = 0;
                    c2r = n - 1;
                    c2c = n - 2;
                }
            }
        }

        cout << cnt << endl;
        if (c1r != 'n') {
            cout << (static_cast<unsigned>(c1r) + 1) <<" " <<(static_cast<unsigned>(c1c) + 1)<<endl;
        }
        if (c2r != 'n') {
            cout << (static_cast<unsigned>(c2r)  + 1)<< " " << (static_cast<unsigned>(c2c) + 1) << endl;
        }
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
    int t;
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        vector<string> strvec;
        for(int i = 0; i < n; ++i) {
            string str;
            cin >> str;
            strvec.push_back(str);
        }
        char sr = strvec[0][1];
        char sd = strvec[1][0];
        char fu = strvec[n - 2][n - 1];
        char fl = strvec[n - 1][n - 2];

        int cnt = 0;
        char c1r = 'n';
        char c1c = 'n';
        char c2r = 'n';
        char c2c = 'n';
        if (sr == sd) {

            if (fu == sr) {
                ++cnt;
                c1r = n - 2;
                c1c = n - 1;

            }
            if (fl == sd) {
                ++cnt;
                c2r = n - 1;
                c2c = n - 2;

            }

        } else {
            if (fu == fl) {

                if (sd == fu) {
                    cnt = 1;
                    c1r = 1;
                    c1c = 0;
                } else {
                    cnt = 2;
                    c1r = 0;
                    c1c = 1;
                    c2r = 1;
                    c2c = 0;
                }
            } else {
                if (sd == fu) {
                    cnt = 2;
                    c1r = 1;
                    c1c = 0;
                    c2r = n -1;
                    c2c = n - 2;
                }  else {
                    cnt = 2;
                    c1r = 1;
                    c1c = 0;
                    c2r = n - 2;
                    c2c = n - 1;
                }
            }
        }

        cout << cnt << endl;
        if (c1r != 'n') {
            cout << (static_cast<unsigned>(c1r) + 1) <<" " <<(static_cast<unsigned>(c1c) + 1)<<endl;
        }
        if (c2r != 'n') {
            cout << (static_cast<unsigned>(c2r)  + 1)<< " " << (static_cast<unsigned>(c2c) + 1) << endl;
        }
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
    int t;
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        vector<string> strvec;
        for(int i = 0; i < n; ++i) {
            string str;
            cin >> str;
            strvec.push_back(str);
        }
        char sr = strvec[0][1];
        char sd = strvec[1][0];
        char fu = strvec[n - 2][n - 1];
        char fl = strvec[n - 1][n - 2];

        int cnt = 0;
        char c1r = 'n';
        char c1c = 'n';
        char c2r = 'n';
        char c2c = 'n';
        if (sr == sd) {

            if (fu == sr) {
                ++cnt;
                c1r = n - 2;
                c1c = n - 1;

            }
            if (fl == sd) {
                ++cnt;
                c2r = n - 1;
                c2c = n - 2;

            }

        } else {
            if (fu == fl) {

                if (sd == fu) {
                    cnt = 1;
                    c1r = 1;
                    c1c = 0;
                } else {
                    cnt = 1;
                    c1r = 0;
                    c1c = 1;
                }
            } else {
                if (sd == fu) {
                    cnt = 2;
                    c1r = 0;
                    c1c = 1;
                    c2r = n -1;
                    c2c = n - 2;
                }  else {
                    cnt = 2;
                    c1r = 1;
                    c1c = 0;
                    c2r = n - 2;
                    c2c = n - 1;
                }
            }
        }

        cout << cnt << endl;
        if (c1r != 'n') {
            cout << (static_cast<unsigned>(c1r) + 1) <<" " <<(static_cast<unsigned>(c1c) + 1)<<endl;
        }
        if (c2r != 'n') {
            cout << (static_cast<unsigned>(c2r)  + 1)<< " " << (static_cast<unsigned>(c2c) + 1) << endl;
        }
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
    int t;
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        vector<string> strvec;
        for(int i = 0; i < n; ++i) {
            string str;
            cin >> str;
            strvec.push_back(str);
        }
        char sr = strvec[0][1];
        char sd = strvec[1][0];
        char fu = strvec[n - 2][n - 1];
        char fl = strvec[n - 1][n - 2];

        int cnt = 0;
        char c1r = 'n';
        char c1c = 'n';
        char c2r = 'n';
        char c2c = 'n';
        if (sr == sd) {

            if (fu == sr) {
                ++cnt;
                c1r = n - 2;
                c1c = n - 1;

            }
            if (fl == sd) {
                ++cnt;
                c2r = n - 1;
                c2c = n - 2;

            }

        } else {
            if (fu == fl) {

                if (sd == fu) {
                    cnt = 1;
                    c1r = 1;
                    c1c = 0;
                } else {
                    cnt = 1;
                    c1r = 0;
                    c1c = 1;
                }
            } else {
                if (sd == fu) {
                    cnt = 2;
                    c1r = 0;
                    c1c = 1;
                    c2r = n -1;
                    c2c = n - 2;
                }  else {
                    cnt = 2;
                    c1r = 0;
                    c1c = 1;
                    c2r = n - 2;
                    c2c = n - 1;
                }
            }
        }

        cout << cnt << endl;
        if (c1r != 'n') {
            cout << (static_cast<unsigned>(c1r) + 1) <<" " <<(static_cast<unsigned>(c1c) + 1)<<endl;
        }
        if (c2r != 'n') {
            cout << (static_cast<unsigned>(c2r)  + 1)<< " " << (static_cast<unsigned>(c2c) + 1) << endl;
        }
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
    int t;
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        vector<string> strvec;
        for(int i = 0; i < n; ++i) {
            string str;
            cin >> str;
            strvec.push_back(str);
        }
        char sr = strvec[0][1];
        char sd = strvec[1][0];
        char fu = strvec[n - 2][n - 1];
        char fl = strvec[n - 1][n - 2];

        int cnt = 0;
        char c1r = 'n';
        char c1c = 'n';
        char c2r = 'n';
        char c2c = 'n';
        if (sr == sd) {

            if (fu == sr) {
                ++cnt;
                c1r = n - 2;
                c1c = n - 1;

            }
            if (fl == sd) {
                ++cnt;
                c2r = n - 1;
                c2c = n - 2;

            }

        } else {
            if (fu == fl) {
                ++cnt;
                if (sd == fu) {

                    c1r = 1;
                    c1c = 0;
                } else {
                    c1r = 0;
                    c2c = 1;
                }
            } else {
                if (sd == fu) {
                    cnt = 2;
                    c1r = 1;
                    c1c = 0;
                    c2r = n -1;
                    c2c = n - 2;
                }  else {
                    cnt = 2;
                    c1r = 1;
                    c1c = 0;
                    c2r = n - 2;
                    c2c = n - 1;
                }
            }
        }

        cout << cnt << endl;
        if (c1r != 'n') {
            cout << (static_cast<unsigned>(c1r) + 1) <<" " <<(static_cast<unsigned>(c1c) + 1)<<endl;
        }
        if (c2r != 'n') {
            cout << (static_cast<unsigned>(c2r)  + 1)<< " " << (static_cast<unsigned>(c2c) + 1) << endl;
        }
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
    int t;
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        vector<string> strvec;
        for(int i = 0; i < n; ++i) {
            string str;
            cin >> str;
            strvec.push_back(str);
        }
        char sr = strvec[0][1];
        char sd = strvec[1][0];
        char fu = strvec[n - 2][n - 1];
        char fl = strvec[n - 1][n - 2];

        int cnt = 0;
        char c1r = 'n';
        char c1c = 'n';
        char c2r = 'n';
        char c2c = 'n';
        if (sr == sd) {

            if (fu == sr) {
                ++cnt;
                c1r = n - 2;
                c1c = n - 1;

            }
            if (fl == sd) {
                ++cnt;
                c2r = n - 1;
                c2c = n - 2;

            }

        } else {
            if (fu == fl) {

                if (sd == fu) {
                    cnt = 1;
                    c1r = 1;
                    c1c = 0;
                } else {
                    cnt = 1;
                    c1r = 0;
                    c1c = 1;
                }
            } else {
                if (sd == fu) {
                    cnt = 2;
                    c1r = 0;
                    c1c = 1;
                    c2r = n - 2;
                    c2c = n - 1;
                }  else {
                    cnt = 2;
                    c1r = 0;
                    c1c = 1;
                    c2r = n - 1;
                    c2c = n - 2;
                }
            }
        }

        cout << cnt << endl;
        if (c1r != 'n') {
            cout << (static_cast<unsigned>(c1r) + 1) <<" " <<(static_cast<unsigned>(c1c) + 1)<<endl;
        }
        if (c2r != 'n') {
            cout << (static_cast<unsigned>(c2r)  + 1)<< " " << (static_cast<unsigned>(c2c) + 1) << endl;
        }
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
    int t;
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        vector<string> strvec;
        for(int i = 0; i < n; ++i) {
            string str;
            cin >> str;
            strvec.push_back(str);
        }
        char sr = strvec[0][1];
        char sd = strvec[1][0];
        char fu = strvec[n - 2][n - 1];
        char fl = strvec[n - 1][n - 2];

        int cnt = 0;
        char c1r = 'n';
        char c1c = 'n';
        char c2r = 'n';
        char c2c = 'n';
        if (sr == sd) {

            if (fu == sr) {
                ++cnt;
                c1r = n - 2;
                c1c = n - 1;

            }
            if (fl == sd) {
                ++cnt;
                c2r = n - 1;
                c2c = n - 2;

            }

        } else {
            if (fu == fl) {
                ++cnt;
                if (sd == fu) {

                    c1r = 1;
                    c1c = 0;
                } else {
                    c1r = 0;
                    c1c = 1;
                }
            } else {
                if (sd == fu) {
                    cnt = 2;
                    c1r = 1;
                    c1c = 0;
                    c2r = n -1;
                    c2c = n - 2;
                }  else {
                    cnt = 2;
                    c1r = 1;
                    c1c = 0;
                    c2r = n - 2;
                    c2c = n - 1;
                }
            }
        }

        cout << cnt << endl;
        if (c1r != 'n') {
            cout << (static_cast<unsigned>(c1r) + 1) <<" " <<(static_cast<unsigned>(c1c) + 1)<<endl;
        }
        if (c2r != 'n') {
            cout << (static_cast<unsigned>(c2r)  + 1)<< " " << (static_cast<unsigned>(c2c) + 1) << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

using ll= long long;
#define double long double
#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _set(x) __builtin_popcount(x)
#define _setl(x) __builtin_popcountll(x)
#define PI  3.14159265358979323846264338327950L
#define mod 1000000007LL

void debug(){
	cerr<<"]\n";
}
template<class H,class ... T> void debug(H h,T... t){
	cerr<<h;
	if(sizeof... (t)){
		cerr<<", ";
	}
	debug(t...);
}
#ifdef DEBUG
	#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", debug(__VA_ARGS__)
	#define dpv(...) cerr<< "["#__VA_ARGS__ " : ";for(int i: (__VA_ARGS__)){cerr<<i<<" ";}cerr<<"]\n"
#else
	#define dbg(...) 0
	#define dpv(...) 0
#endif

void solve(){
	int n;
	cin>>n;
	vector<string> g(n);
	for(int i=0;i<n;i++){
		cin>>g[i];
	}
	int cnt =0;
	cnt = (g[1][0]==g[0][1]);
	cnt += (g[n-2][n-1]==g[n-1][n-2]);
	if(cnt==2 && g[1][0] ==g[n-2][n-1]){
		cout<<"2\n1 2\n2 1\n";
		return;
	}else if(cnt==2){
		cout<<"0\n";
		return;
	}
	cout<<cnt<<"\n";
	if(g[n-2][n-1] != g[n-1][n-2]){
		if(g[n-2][n-1] != '1'){
			cout<<n-1<<" "<<n<<'\n';
		}else {
			cout<<n<<" "<<n-1<<"\n";
		}
	}
	if(g[1][0] != g[0][1]){
		if(g[1][0] == '1'){
			cout<<2<<' '<<1<<"\n";
		}else{
			cout<<1<<" "<<2<<"\n";
		}
	}
}

int32_t main(){
	IOS
	// freopen("input.txt","r",stdin);
	int _;
	cin>>_;
	// _=1;
	for(int i=1;i<=_;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}

/*
   check for overflows int long long
   correct mize of array
*/


#include <bits/stdc++.h>
using namespace std;

using ll= long long;
#define double long double
#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _set(x) __builtin_popcount(x)
#define _setl(x) __builtin_popcountll(x)
#define PI  3.14159265358979323846264338327950L
#define mod 1000000007LL

void debug(){
	cerr<<"]\n";
}
template<class H,class ... T> void debug(H h,T... t){
	cerr<<h;
	if(sizeof... (t)){
		cerr<<", ";
	}
	debug(t...);
}
#ifdef DEBUG
	#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", debug(__VA_ARGS__)
	#define dpv(...) cerr<< "["#__VA_ARGS__ " : ";for(int i: (__VA_ARGS__)){cerr<<i<<" ";}cerr<<"]\n"
#else
	#define dbg(...) 0
	#define dpv(...) 0
#endif

void solve(){
	int n;
	cin>>n;
	vector<string> g(n);
	for(int i=0;i<n;i++){
		cin>>g[i];
	}
	int cnt =0;
	cnt = (g[1][0]==g[0][1]);
	cnt += (g[n-2][n-1]==g[n-1][n-2]);
	if(cnt==2 && g[1][0] ==g[n-2][n-1]){
		cout<<"2\n1 2\n2 1\n";
		return;
	}else if(cnt==2){
		cout<<"0\n";
		return;
	}
	cnt = (g[1][0]!=g[0][1]);
	cnt += (g[n-2][n-1]!=g[n-1][n-2]);
	cout<<cnt<<'\n';
	if(g[0][1]==g[1][0] && g[0][1]=='1'){
		if(g[n-2][n-1] != '0'){
			cout<<n-1<<' '<<n<<"\n";
		}else{
			cout<<n<<" "<<n-1<<"\n";
		}
	}
	if(g[n-2][n-1] != g[n-1][n-2]){
		if(g[n-2][n-1] != '1'){
			cout<<n-1<<" "<<n<<'\n';
		}else {
			cout<<n<<" "<<n-1<<"\n";
		}
	}
	if(g[1][0] != g[0][1]){
		if(g[1][0] == '1'){
			cout<<2<<' '<<1<<"\n";
		}else{
			cout<<1<<" "<<2<<"\n";
		}
	}
}

int32_t main(){
	IOS
	// freopen("input.txt","r",stdin);
	int _;
	cin>>_;
	// _=1;
	for(int i=1;i<=_;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}

/*
   check for overflows int long long
   correct mize of array
*/


#include <bits/stdc++.h>
using namespace std;

using ll= long long;
#define double long double
#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _set(x) __builtin_popcount(x)
#define _setl(x) __builtin_popcountll(x)
#define PI  3.14159265358979323846264338327950L
#define mod 1000000007LL

void debug(){
	cerr<<"]\n";
}
template<class H,class ... T> void debug(H h,T... t){
	cerr<<h;
	if(sizeof... (t)){
		cerr<<", ";
	}
	debug(t...);
}
#ifdef DEBUG
	#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", debug(__VA_ARGS__)
	#define dpv(...) cerr<< "["#__VA_ARGS__ " : ";for(int i: (__VA_ARGS__)){cerr<<i<<" ";}cerr<<"]\n"
#else
	#define dbg(...) 0
	#define dpv(...) 0
#endif

void solve(){
	int n;
	cin>>n;
	vector<string> g(n);
	for(int i=0;i<n;i++){
		cin>>g[i];
	}
	int cnt =0;
	cnt = (g[1][0]==g[0][1]);
	cnt += (g[n-2][n-1]==g[n-1][n-2]);
	if(cnt==2 && g[1][0] ==g[n-2][n-1]){
		cout<<"2\n1 2\n2 1\n";
		return;
	}else if(cnt==2){
		cout<<"0\n";
		return;
	}
	cnt = (g[1][0]!=g[0][1]);
	cnt += (g[n-2][n-1]!=g[n-1][n-2]);
	cout<<cnt<<'\n';
	if(g[n-2][n-1] != g[n-1][n-2]){
		if(g[n-2][n-1] != '1'){
			cout<<n-1<<" "<<n<<'\n';
		}else {
			cout<<n<<" "<<n-1<<"\n";
		}
	}
	if(g[1][0] != g[0][1]){
		if(g[1][0] == '1'){
			cout<<2<<' '<<1<<"\n";
		}else{
			cout<<1<<" "<<2<<"\n";
		}
	}
}

int32_t main(){
	IOS
	// freopen("input.txt","r",stdin);
	int _;
	cin>>_;
	// _=1;
	for(int i=1;i<=_;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}

/*
   check for overflows int long long
   correct mize of array
*/


#include <bits/stdc++.h>
using namespace std;

using ll= long long;
#define double long double
#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _set(x) __builtin_popcount(x)
#define _setl(x) __builtin_popcountll(x)
#define PI  3.14159265358979323846264338327950L
#define mod 1000000007LL

void debug(){
	cerr<<"]\n";
}
template<class H,class ... T> void debug(H h,T... t){
	cerr<<h;
	if(sizeof... (t)){
		cerr<<", ";
	}
	debug(t...);
}
#ifdef DEBUG
	#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", debug(__VA_ARGS__)
	#define dpv(...) cerr<< "["#__VA_ARGS__ " : ";for(int i: (__VA_ARGS__)){cerr<<i<<" ";}cerr<<"]\n"
#else
	#define dbg(...) 0
	#define dpv(...) 0
#endif

void solve(){
	int n;
	cin>>n;
	vector<string> g(n);
	for(int i=0;i<n;i++){
		cin>>g[i];
	}
	int cnt =0;
	cnt = (g[1][0]==g[0][1]);
	cnt += (g[n-2][n-1]==g[n-1][n-2]);
	if(cnt==2 && g[1][0] ==g[n-2][n-1]){
		cout<<"2\n1 2\n2 1\n";
		return;
	}else{
		cout<<"0\n";
		return;
	}
	cout<<cnt<<"\n";
	if(g[n-2][n-1] != g[n-1][n-2]){
		if(g[n-2][n-1] != '1'){
			cout<<n-1<<" "<<n<<'\n';
		}else {
			cout<<n<<" "<<n-1<<"\n";
		}
	}
	if(g[1][0] != g[0][1]){
		if(g[1][0] == '1'){
			cout<<2<<' '<<1<<"\n";
		}else{
			cout<<1<<" "<<2<<"\n";
		}
	}
}

int32_t main(){
	IOS
	// freopen("input.txt","r",stdin);
	int _;
	cin>>_;
	// _=1;
	for(int i=1;i<=_;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}

/*
   check for overflows int long long
   correct mize of array
*/


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define cor(x) cout << (x) << "\n"; return 0;
#define cps CLOCKS_PER_SEC
#define tests(t) int t; cin >> t; while(t--)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define eb emplace_back
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define fi first
#define se second
#define bitcount(x) __builtin_popcount(x)
#define bit(x) (1LL << x)
#define PI acos(-1.0)
#define EPS 1e-9

using namespace std;

using namespace __gnu_pbds;
template<class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
///All indexing is 0-based
///methods: find_by_order(k); & order_of_key(k);
///To make it an ordered_multiset, use pairs of (value, time_of_insertion)
///to distinguish values which are similar
#define mod 1000000007
#define maxn 205

typedef long long ll;
typedef double ld;
typedef pair<ll, ll> par;

int N,nf,nc,way3,way4,way13,way14,way23,way24;
queue<par> Q;
int movf[4]={0,0,1,-1};
int movc[4]={1,-1,0,0};
char A[maxn][maxn];
vector<par> v;
int mark[maxn][maxn];

void bfs(int f,int c)
{
    way3=way4=0;
    Q.push(par(f,c));
    for(int i=1;i<=N;i++)
        fill(mark[i],mark[i]+N+1,0);
    while(!Q.empty()){
        f = Q.front().fi;
        c = Q.front().se;
        Q.pop();
        for(int i=0;i<4;i++){
            nf = f + movf[i],nc = c+movc[i];
            if(nf>N || nf<1 || nc>N || nc<1)
                continue;
            if(mark[nf][nc])
                continue;

            if(A[nf][nc]==A[f][c]){
                if(nf == N && nc == N-1){
                    way3=1;
                    continue;
                }
                if(nf == N-1 && nc == N){
                    way4=1;
                    continue;
                }

                Q.push(par(nf,nc));
                mark[nf][nc]=1;
            }
        }
    }

}

int main()
{
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm
   // ios_base::sync_with_stdio(0);
   // cin.tie(0);

    tests(will){
        cin >> N;
        for(int i=1;i<=N;i++)
            cin >> (A[i]+1);
        bfs(2,1);
        way13 = way3;
        way14 = way4;
        bfs(1,2);
        way23 = way3;
        way24 = way4;

        if(way13+way14+way23+way24 == 0){
            cout << "0\n" ;
            continue;
        }
        if(way23){
            cout << "1\n" << N << " " << N-1 << "\n";
            continue;
        }
        if(way14){
            cout << "1\n" << N-1 << " " << N << "\n";
            continue;
        }
        int sol=0;
        if(way24){
            sol++;
            v.pb(par(N-1,N));
        }
        if(way13){
            sol++;
            v.pb(par(N,N-1));
        }

        cout << sol << "\n";
        for(auto p:v)
            cout << p.fi << " " << p.se << "\n";
        v.clear();
        way13=way14=way23=way24=0;

    }

}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define cor(x) cout << (x) << "\n"; return 0;
#define cps CLOCKS_PER_SEC
#define tests(t) int t; cin >> t; while(t--)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define eb emplace_back
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define fi first
#define se second
#define bitcount(x) __builtin_popcount(x)
#define bit(x) (1LL << x)
#define PI acos(-1.0)
#define EPS 1e-9

using namespace std;

using namespace __gnu_pbds;
template<class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
///All indexing is 0-based
///methods: find_by_order(k); & order_of_key(k);
///To make it an ordered_multiset, use pairs of (value, time_of_insertion)
///to distinguish values which are similar
#define mod 1000000007
#define maxn 205

typedef long long ll;
typedef double ld;
typedef pair<ll, ll> par;

int N,cero;
char A[maxn][maxn];
vector<par> v;

void fun(char a){
    if(A[1][2]==a)
        v.pb(par(1,2));
    if(A[2][1]==a)
        v.pb(par(2,1));
    if(A[N][N-1]==a)
        v.pb(par(N,N-1));
    if(A[N-1][N]==a)
        v.pb(par(N-1,N));
}

int main()
{
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm
   // ios_base::sync_with_stdio(0);
   // cin.tie(0);

    tests(will){
        cin >> N;
        for(int i=1;i<=N;i++)
            cin >> (A[i]+1);
        if(A[1][2]=='0')
                cero++;
        if(A[2][1]=='0')
                cero++;
        if(A[N][N-1]=='0')
                cero++;
        if(A[N-1][N]=='0')
                cero++;
        if(cero>=2)
            fun('1');
        else
            fun('0');
        cout << v.sz << "\n";
        for(auto a:v){
            cout << a.fi << " " << a.se << "\n";
        }
        v.clear();
        cero=0;

    }

}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define cor(x) cout << (x) << "\n"; return 0;
#define cps CLOCKS_PER_SEC
#define tests(t) int t; cin >> t; while(t--)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define eb emplace_back
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define fi first
#define se second
#define bitcount(x) __builtin_popcount(x)
#define bit(x) (1LL << x)
#define PI acos(-1.0)
#define EPS 1e-9

using namespace std;

using namespace __gnu_pbds;
template<class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
///All indexing is 0-based
///methods: find_by_order(k); & order_of_key(k);
///To make it an ordered_multiset, use pairs of (value, time_of_insertion)
///to distinguish values which are similar
#define mod 1000000007
#define maxn 205

typedef long long ll;
typedef double ld;
typedef pair<ll, ll> par;

int N,nf,nc,way3,way4,way13,way14,way23,way24;
queue<par> Q;
int movf[4]={0,0,1,-1};
int movc[4]={1,-1,0,0};
char A[maxn][maxn];
vector<par> v;
int mark[maxn][maxn];

void bfs(int f,int c)
{
    way3=way4=0;
    Q.push(par(f,c));
    for(int i=1;i<=N;i++)
        fill(mark[i],mark[i]+N+1,0);
    while(!Q.empty()){
        f = Q.front().fi;
        c = Q.front().se;
        Q.pop();
        for(int i=0;i<4;i++){
            nf = f + movf[i],nc = c+movc[i];
            if(nf>N || nf<1 || nc>N || nc<1)
                continue;
            if(mark[nf][nc])
                continue;

            if(A[nf][nc]==A[f][c]){
                Q.push(par(nf,nc));
                mark[nf][nc]=1;
                if(nf == N && nc == N-1)
                    way3=1;

                if(nf == N-1 && nc == N)
                    way4=1;

            }
        }
    }

}

int main()
{
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm
   // ios_base::sync_with_stdio(0);
   // cin.tie(0);

    tests(will){
        cin >> N;
        for(int i=1;i<=N;i++)
            cin >> (A[i]+1);
        bfs(2,1);
        way13 = way3;
        way14 = way4;
        bfs(1,2);
        way23 = way3;
        way24 = way4;

        if(way13+way14+way23+way24 == 0){
            cout << "0\n" ;
            continue;
        }
        if(way23 || way14){
            cout << "2\n" << N << " " << N-1 << "\n";
            cout << N-1 << " " << N << "\n";
            continue;
        }
        int sol=0;
        if(way24){
            sol++;
            v.pb(par(N-1,N));
        }
        if(way13){
            sol++;
            v.pb(par(N,N-1));
        }

        cout << sol << "\n";
        for(auto p:v)
            cout << p.fi << " " << p.se << "\n";
        v.clear();
        way13=way14=way23=way24=0;

    }

}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define cor(x) cout << (x) << "\n"; return 0;
#define cps CLOCKS_PER_SEC
#define tests(t) int t; cin >> t; while(t--)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define eb emplace_back
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define fi first
#define se second
#define bitcount(x) __builtin_popcount(x)
#define bit(x) (1LL << x)
#define PI acos(-1.0)
#define EPS 1e-9

using namespace std;

using namespace __gnu_pbds;
template<class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
///All indexing is 0-based
///methods: find_by_order(k); & order_of_key(k);
///To make it an ordered_multiset, use pairs of (value, time_of_insertion)
///to distinguish values which are similar
#define mod 1000000007
#define maxn 205

typedef long long ll;
typedef double ld;
typedef pair<ll, ll> par;

int N,cero1,cero2;
char A[maxn][maxn];
vector<par> v;

void fun1(char a){
    if(A[1][2]==a)
        v.pb(par(1,2));
    if(A[2][1]==a)
        v.pb(par(2,1));
}
void fun2(char a){
    if(A[N][N-1]==a)
        v.pb(par(N,N-1));
    if(A[N-1][N]==a)
        v.pb(par(N-1,N));
}

int main()
{
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm
   // ios_base::sync_with_stdio(0);
   // cin.tie(0);

    tests(will){
        cin >> N;
        for(int i=1;i<=N;i++)
            cin >> (A[i]+1);
        if(A[1][2]=='0')
                cero1++;
        if(A[2][1]=='0')
                cero1++;
        if(A[N][N-1]=='0')
                cero2++;
        if(A[N-1][N]=='0')
                cero2++;
        if(cero1 + 2-cero2>2)
            fun1('1'), fun2('0');
        else
            fun1('0'), fun2('1');
        cout << v.sz << "\n";
        for(auto a:v){
            cout << a.fi << " " << a.se << "\n";
        }
        v.clear();
        cero1=cero2=0;

    }

}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define cor(x) cout << (x) << "\n"; return 0;
#define cps CLOCKS_PER_SEC
#define tests(t) int t; cin >> t; while(t--)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define eb emplace_back
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define fi first
#define se second
#define bitcount(x) __builtin_popcount(x)
#define bit(x) (1LL << x)
#define PI acos(-1.0)
#define EPS 1e-9

using namespace std;

using namespace __gnu_pbds;
template<class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
///All indexing is 0-based
///methods: find_by_order(k); & order_of_key(k);
///To make it an ordered_multiset, use pairs of (value, time_of_insertion)
///to distinguish values which are similar
#define mod 1000000007
#define maxn 205

typedef long long ll;
typedef double ld;
typedef pair<ll, ll> par;

int N,nf,nc,way3,way4,way13,way14,way23,way24;
queue<par> Q;
int movf[4]={0,0,1,-1};
int movc[4]={1,-1,0,0};
char A[maxn][maxn];
vector<par> v;
int mark[maxn][maxn];

void bfs(int f,int c)
{
    way3=way4=0;
    Q.push(par(f,c));
    for(int i=1;i<=N;i++)
        fill(mark[i],mark[i]+N+1,0);
    while(!Q.empty()){
        f = Q.front().fi;
        c = Q.front().se;
        Q.pop();
        for(int i=0;i<4;i++){
            nf = f + movf[i],nc = c+movc[i];
            if(nf>N || nf<1 || nc>N || nc<1)
                continue;
            if(mark[nf][nc])
                continue;

            if(A[nf][nc]==A[f][c]){
                Q.push(par(nf,nc));
                mark[nf][nc]=1;
                if(nf == N && nc == N-1)
                    way3=1;

                if(nf == N-1 && nc == N)
                    way4=1;

            }
        }
    }

}

int main()
{
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm
   // ios_base::sync_with_stdio(0);
   // cin.tie(0);

    tests(will){
        cin >> N;
        for(int i=1;i<=N;i++)
            cin >> (A[i]+1);
        bfs(2,1);
        way13 = way3;
        way14 = way4;
        bfs(1,2);
        way23 = way3;
        way24 = way4;

        if(way13+way14+way23+way24 == 0){
            cout << "0\n" ;
            continue;
        }
        if(way23){
          v.pb(par(N,N-1));
          if(A[1][2]==A[N-1][N])
            v.pb(par(N-1,N));
        }
        else
        if(way14){
            v.pb(par(N-1,N));
          if(A[2][1]==A[N][N-1])
            v.pb(par(N,N-1));
        }
        else{
        if(way24)
            v.pb(par(N-1,N));
        if(way13)
            v.pb(par(N,N-1));
        }

        cout << v.sz << "\n";
        for(auto p:v)
            cout << p.fi << " " << p.se << "\n";
        v.clear();
        way13=way14=way23=way24=0;

    }

}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <utility>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <cassert>
#define ll long long int
using namespace std;

const int M = 1e9 + 7;
long long mod(long long x) {
	return ((x % M + M) % M);
}
long long add(long long a, long long b) {
	return mod(mod(a) + mod(b));
}
long long mul(long long a, long long b) {
	return mod(mod(a) * mod(b));
}

ll bin(ll a, ll b)
{
	if (b == 0)
		return 1;
	ll  res = bin(a, b / 2);
	if (b % 2)
		return res * res * a;
	else
		return res * res;
}

ll exponentMod(ll A, ll B, ll C)
{
	if (A == 0)
		return 0;
	if (B == 0)
		return 1;

	ll y;
	if (B % 2 == 0) {
		y = exponentMod(A, B / 2, C);
		y = (y * y) % C;
	}

	else {
		y = A % C;
		y = (y * exponentMod(A, B - 1, C) % C) % C;
	}

	return (ll)((y + C) % C);
}

ll isprime(ll x)
{
	ll i, res = 1;
	for (i = 2; i <= sqrt(x); i++)
	{
		if (x % i == 0)
		{
			res = i;
			break;
		}
	}
	return res;
}

ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
		return gcd(b, a % b);
}

ll extended_gcd(ll a, ll b, ll& x, ll& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	ll x1, y1;
	ll d = extended_gcd(b, a % b, x1, y1);
	x = y1;
	y = x1 - y1 * (a / b);
	return d;
}

ll binarySearch(ll arr[], ll l, ll r, ll x)
{
	if (r >= l) {
		ll mid = l + (r - l) / 2;

		if (arr[mid] == x)
			return mid;

		if (arr[mid] > x)
			return binarySearch(arr, l, mid - 1, x);

		return binarySearch(arr, mid + 1, r, x);
	}
	return -1;
}

void solve()
{
	ll n;
	cin >> n;
	char a[300][300], i, j, count = 0;
	for (i = 1; i <= n; i++)
	{
		for (j = 1; j <= n; j++)
		{
			cin >> a[i][j];
		}
	}
	int count1 = 0, count2 = 0, count3 = 0, count4 = 0;
	if (a[1][2] == '0')
		count1++;
	else
		count2++;
	if (a[2][1] == '0')
		count1++;
	else
		count2++;
	if (a[n][n - 1] == '0')
		count3++;
	else
		count4++;
	if (a[n - 1][n] == '0')
		count3++;
	else
		count4++;
	if (count1 == 0 || count2 == 0)
	{
		if (count1 == 0)
		{
			if (count3 == 2)
			{
				cout << "0" << "\n";
			}
			else if (count3 == 1)
			{
				cout << 1 << "\n";
				if (a[n][n - 1] == '1')
					cout << n << " " << n - 1 << "\n";
				else
					cout << n - 1 << " " << n << "\n";
			}
			else
			{
				cout << 2 << "\n";
				cout << n << " " << n - 1 << "\n" << n - 1 << " " << n << "\n";
			}
		}
		else if (count2 == 0)
		{
			if (count4 == 2)
			{
				cout << "0" << "\n";
			}
			else if (count4 == 1)
			{
				cout << 1 << "\n";
				if (a[n][n - 1] == '0')
					cout << n << " " << n - 1 << "\n";
				else
					cout << n - 1 << " " << n << "\n";
			}
			else
			{
				cout << 2 << "\n";
				cout << n << " " << n - 1 << "\n" << n - 1 << " " << n << "\n";
			}
		}
	}
	else
	{
		if (count3 == 1 && count4 == 1)
		{
			cout << 2 << "\n";
			cout << 1 << " " << 2 << "\n";
			if (a[n][n - 1] == a[1][2])
				cout << n - 1 << " " << n << "\n";
			else
				cout << n << " " << n - 1 << "\n";
		}
		else
		{
			if (count3 == 0)
			{
				cout << 1 << "\n";
				if (a[1][2] == '1')
					cout << 1 << " " << 2 << "\n";
				else
					cout << 2 << " " << 1 << "\n";
			}
			else if (count4 == 0)
			{
				cout << 1 << "\n";
				if (a[1][2] == '0')
					cout << 1 << " " << 2 << "\n";
				else
					cout << 2 << " " << 1 << "\n";
			}
		}
	}
}

void test_case()
{
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	test_case();
	//solve();
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <utility>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <cassert>
#define ll long long int
using namespace std;

const int M = 1e9 + 7;
long long mod(long long x) {
	return ((x % M + M) % M);
}
long long add(long long a, long long b) {
	return mod(mod(a) + mod(b));
}
long long mul(long long a, long long b) {
	return mod(mod(a) * mod(b));
}

ll bin(ll a, ll b)
{
	if (b == 0)
		return 1;
	ll  res = bin(a, b / 2);
	if (b % 2)
		return res * res * a;
	else
		return res * res;
}

ll exponentMod(ll A,ll B,ll C)
{
	if (A == 0)
		return 0;
	if (B == 0)
		return 1;

	ll y;
	if (B % 2 == 0) {
		y = exponentMod(A, B / 2, C);
		y = (y * y) % C;
	}

	else {
		y = A % C;
		y = (y * exponentMod(A, B - 1, C) % C) % C;
	}

	return (ll)((y + C) % C);
}

ll isprime(ll x)
{
	ll i, res = 1;
	for (i = 2; i <= sqrt(x); i++)
	{
		if (x % i == 0)
		{
			res = i;
			break;
		}
	}
	return res;
}

ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
		return gcd(b, a % b);
}

ll extended_gcd(ll a, ll b, ll& x, ll& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	ll x1, y1;
	ll d = extended_gcd(b, a % b, x1, y1);
	x = y1;
	y = x1 - y1 * (a / b);
	return d;
}

ll binarySearch(ll arr[],ll l,ll r,ll x)
{
	if (r >= l) {
		ll mid = l + (r - l) / 2;

		if (arr[mid] == x)
			return mid;

		if (arr[mid] > x)
			return binarySearch(arr, l, mid - 1, x);

		return binarySearch(arr, mid + 1, r, x);
	}
	return -1;
}

void solve()
{
	ll n;
	cin >> n;
	char a[200][200], i, j, count = 0;
	for (i = 1; i <= n; i++)
	{
		for (j = 1; j <= n; j++)
		{
			cin >> a[i][j];
		}
	}
	int count1 = 0, count2 = 0, count3 = 0, count4 = 0;
	if (a[1][2] == '0')
		count1++;
	else
		count2++;
	if (a[2][1] == '0')
		count1++;
	else
		count2++;
	if (a[n][n - 1] == '0')
		count3++;
	else
		count4++;
	if (a[n - 1][n] == '0')
		count3++;
	else
		count4++;
	if (count1 == 0 || count2 == 0)
	{
		if (count1 == 0)
		{
			if (count3 == 2)
			{
				cout << "0" << "\n";
			}
			else if (count3 == 1)
			{
				cout << 1 << "\n";
				if (a[n][n - 1] == '1')
					cout << n << " " << n - 1 << "\n";
				else
					cout << n - 1 << " " << n << "\n";
			}
			else
			{
				cout << 2 << "\n";
				cout << n << " " << n - 1 << "\n" << n - 1 << " " << n << "\n";
			}
		}
		else if (count2 == 0)
		{
			if (count4 == 2)
			{
				cout << "0" << "\n";
			}
			else if (count4 == 1)
			{
				cout << 1 << "\n";
				if (a[n][n - 1] == '0')
					cout << n << " " << n - 1 << "\n";
				else
					cout << n - 1 << " " << n << "\n";
			}
			else
			{
				cout << 2 << "\n";
				cout << n << " " << n - 1 << "\n" << n - 1 << " " << n << "\n";
			}
		}
	}
	else
	{
		if (count3 == 1 && count4 == 1)
		{
			cout << 2 << "\n";
			cout << 1 << " " << 2 << "\n";
			if (a[n][n - 1] == a[1][2])
				cout << n << " " << n - 1 << "\n";
			else
				cout << n - 1 << " " << n << "\n";
		}
		else
		{
			if (count3 == 0)
			{
				cout << 1 << "\n";
				if (a[1][2] == '1')
					cout << 1 << " " << 2 << "\n";
				else
					cout << 2 << " " << 1 << "\n";
			}
			else if(count4==0)
			{
				cout << 1 << "\n";
				if (a[1][2] == '0')
					cout << 1 << " " << 2 << "\n";
				else
					cout << 2 << " " << 1 << "\n";
			}
		}
	}
}

void test_case()
{
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	test_case();
	//solve();
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <utility>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <cassert>
#define ll long long int
using namespace std;

const int M = 1e9 + 7;
long long mod(long long x) {
	return ((x % M + M) % M);
}
long long add(long long a, long long b) {
	return mod(mod(a) + mod(b));
}
long long mul(long long a, long long b) {
	return mod(mod(a) * mod(b));
}

ll bin(ll a, ll b)
{
	if (b == 0)
		return 1;
	ll  res = bin(a, b / 2);
	if (b % 2)
		return res * res * a;
	else
		return res * res;
}

ll exponentMod(ll A, ll B, ll C)
{
	if (A == 0)
		return 0;
	if (B == 0)
		return 1;

	ll y;
	if (B % 2 == 0) {
		y = exponentMod(A, B / 2, C);
		y = (y * y) % C;
	}

	else {
		y = A % C;
		y = (y * exponentMod(A, B - 1, C) % C) % C;
	}

	return (ll)((y + C) % C);
}

ll isprime(ll x)
{
	ll i, res = 1;
	for (i = 2; i <= sqrt(x); i++)
	{
		if (x % i == 0)
		{
			res = i;
			break;
		}
	}
	return res;
}

ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
		return gcd(b, a % b);
}

ll extended_gcd(ll a, ll b, ll& x, ll& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	ll x1, y1;
	ll d = extended_gcd(b, a % b, x1, y1);
	x = y1;
	y = x1 - y1 * (a / b);
	return d;
}

ll binarySearch(ll arr[], ll l, ll r, ll x)
{
	if (r >= l) {
		ll mid = l + (r - l) / 2;

		if (arr[mid] == x)
			return mid;

		if (arr[mid] > x)
			return binarySearch(arr, l, mid - 1, x);

		return binarySearch(arr, mid + 1, r, x);
	}
	return -1;
}

void solve()
{
	ll n;
	cin >> n;
	char a[n+1][n+1], i, j, count = 0;
	for (i = 1; i <= n; i++)
	{
		for (j = 1; j <= n; j++)
		{
			cin >> a[i][j];
		}
	}
	int count1 = 0, count2 = 0, count3 = 0, count4 = 0;
	if (a[1][2] == '0')
		count1++;
	else
		count2++;
	if (a[2][1] == '0')
		count1++;
	else
		count2++;
	if (a[n][n - 1] == '0')
		count3++;
	else
		count4++;
	if (a[n - 1][n] == '0')
		count3++;
	else
		count4++;
	if (count1 == 0 || count2 == 0)
	{
		if (count1 == 0)
		{
			if (count3 == 2)
			{
				cout << "0" << "\n";
			}
			else if (count3 == 1)
			{
				cout << 1 << "\n";
				if (a[n][n - 1] == '1')
					cout << n << " " << n - 1 << "\n";
				else
					cout << n - 1 << " " << n << "\n";
			}
			else
			{
				cout << 2 << "\n";
				cout << n << " " << n - 1 << "\n" << n - 1 << " " << n << "\n";
			}
		}
		else if (count2 == 0)
		{
			if (count4 == 2)
			{
				cout << "0" << "\n";
			}
			else if (count4 == 1)
			{
				cout << 1 << "\n";
				if (a[n][n - 1] == '0')
					cout << n << " " << n - 1 << "\n";
				else
					cout << n - 1 << " " << n << "\n";
			}
			else
			{
				cout << 2 << "\n";
				cout << n << " " << n - 1 << "\n" << n - 1 << " " << n << "\n";
			}
		}
	}
	else
	{
		if (count3 == 1 && count4 == 1)
		{
			cout << 2 << "\n";
			cout << 1 << " " << 2 << "\n";
			if (a[n][n - 1] == a[1][2])
				cout << n - 1 << " " << n << "\n";
			else
				cout << n << " " << n - 1 << "\n";
		}
		else
		{
			if (count3 == 0)
			{
				cout << 1 << "\n";
				if (a[1][2] == '1')
					cout << 1 << " " << 2 << "\n";
				else
					cout << 2 << " " << 1 << "\n";
			}
			else if (count4 == 0)
			{
				cout << 1 << "\n";
				if (a[1][2] == '0')
					cout << 1 << " " << 2 << "\n";
				else
					cout << 2 << " " << 1 << "\n";
			}
		}
	}
}

void test_case()
{
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	test_case();
	//solve();
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <utility>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <cassert>
#define ll long long int
using namespace std;

const int M = 1e9 + 7;
long long mod(long long x) {
	return ((x % M + M) % M);
}
long long add(long long a, long long b) {
	return mod(mod(a) + mod(b));
}
long long mul(long long a, long long b) {
	return mod(mod(a) * mod(b));
}

ll bin(ll a, ll b)
{
	if (b == 0)
		return 1;
	ll  res = bin(a, b / 2);
	if (b % 2)
		return res * res * a;
	else
		return res * res;
}

ll exponentMod(ll A, ll B, ll C)
{
	if (A == 0)
		return 0;
	if (B == 0)
		return 1;

	ll y;
	if (B % 2 == 0) {
		y = exponentMod(A, B / 2, C);
		y = (y * y) % C;
	}

	else {
		y = A % C;
		y = (y * exponentMod(A, B - 1, C) % C) % C;
	}

	return (ll)((y + C) % C);
}

ll isprime(ll x)
{
	ll i, res = 1;
	for (i = 2; i <= sqrt(x); i++)
	{
		if (x % i == 0)
		{
			res = i;
			break;
		}
	}
	return res;
}

ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
		return gcd(b, a % b);
}

ll extended_gcd(ll a, ll b, ll& x, ll& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	ll x1, y1;
	ll d = extended_gcd(b, a % b, x1, y1);
	x = y1;
	y = x1 - y1 * (a / b);
	return d;
}

ll binarySearch(ll arr[], ll l, ll r, ll x)
{
	if (r >= l) {
		ll mid = l + (r - l) / 2;

		if (arr[mid] == x)
			return mid;

		if (arr[mid] > x)
			return binarySearch(arr, l, mid - 1, x);

		return binarySearch(arr, mid + 1, r, x);
	}
	return -1;
}

void solve()
{
	ll n;
	cin >> n;
	char a[200][200], i, j, count = 0;
	for (i = 1; i <= n; i++)
	{
		for (j = 1; j <= n; j++)
		{
			cin >> a[i][j];
		}
	}
	int count1 = 0, count2 = 0, count3 = 0, count4 = 0;
	if (a[1][2] == '0')
		count1++;
	else
		count2++;
	if (a[2][1] == '0')
		count1++;
	else
		count2++;
	if (a[n][n - 1] == '0')
		count3++;
	else
		count4++;
	if (a[n - 1][n] == '0')
		count3++;
	else
		count4++;
	if (count1 == 0 || count2 == 0)
	{
		if (count1 == 0)
		{
			if (count3 == 2)
			{
				cout << "0" << "\n";
			}
			else if (count3 == 1)
			{
				cout << 1 << "\n";
				if (a[n][n - 1] == '1')
					cout << n << " " << n - 1 << "\n";
				else
					cout << n - 1 << " " << n << "\n";
			}
			else
			{
				cout << 2 << "\n";
				cout << n << " " << n - 1 << "\n" << n - 1 << " " << n << "\n";
			}
		}
		else if (count2 == 0)
		{
			if (count4 == 2)
			{
				cout << "0" << "\n";
			}
			else if (count4 == 1)
			{
				cout << 1 << "\n";
				if (a[n][n - 1] == '0')
					cout << n << " " << n - 1 << "\n";
				else
					cout << n - 1 << " " << n << "\n";
			}
			else
			{
				cout << 2 << "\n";
				cout << n << " " << n - 1 << "\n" << n - 1 << " " << n << "\n";
			}
		}
	}
	else
	{
		if (count3 == 1 && count4 == 1)
		{
			cout << 2 << "\n";
			cout << 1 << " " << 2 << "\n";
			if (a[n][n - 1] == a[1][2])
				cout << n - 1 << " " << n << "\n";
			else
				cout << n << " " << n - 1 << "\n";
		}
		else
		{
			if (count3 == 0)
			{
				cout << 1 << "\n";
				if (a[1][2] == '1')
					cout << 1 << " " << 2 << "\n";
				else
					cout << 2 << " " << 1 << "\n";
			}
			else if (count4 == 0)
			{
				cout << 1 << "\n";
				if (a[1][2] == '0')
					cout << 1 << " " << 2 << "\n";
				else
					cout << 2 << " " << 1 << "\n";
			}
		}
	}
}

void test_case()
{
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	test_case();
	//solve();
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;

const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
char str[205];
int n, mp[205][205], flag, vis[205][205];

void dfs(int x, int y, int ops) {
    if (x == y && x == n) {
        flag = 1;
        return;
    }
    vis[x][y] = 1;
    for (int i = 0; i <= 3; ++i) {
        int tx = x + dx[i], ty = y + dy[i];
        if (tx < 1 || ty < 1 || tx > n || ty > n || vis[tx][ty] || (mp[tx][ty] != ops && mp[tx][ty] != -1)) continue;
        dfs(tx, ty, ops);
    }
    vis[x][y] = 0;
}

bool check(int num) {
    if (num == 2) {
        mp[n][n - 1] ^= 1;
    } else if (num == 1) {
        mp[n - 1][n] ^= 1;
    } else if (num == 3) {
        mp[n][n - 1] ^= 1;
        mp[n - 1][n] ^= 1;
    }
    flag = 0;
    int tmp = 0;
    for (int i = 0; i <= 1; ++i) {
        dfs(1, 1, i);
        if (flag) {
            tmp = 1;
            break;
        }
    }
    if (num == 2) {
        mp[n][n - 1] ^= 1;
    } else if (num == 1) {
        mp[n - 1][n] ^= 1;
    } else if (num == 3) {
        mp[n][n - 1] ^= 1;
        mp[n - 1][n] ^= 1;
    }
    if (!tmp) return 1;
    return 0;
}

int main() {
    int T;
    scanf ("%d", &T);
    while (T--) {
        memset(mp, 0, sizeof mp);
        scanf ("%d%d", &n);
        for (int i = 1; i <= n; ++i) {
            scanf ("%s", str);
            for (int j = 0; j < n; ++j) {
                if (str[j] == 'S' || str[j] == 'F') {
                    mp[i][j + 1] = -1;
                    continue;
                }
                mp[i][j + 1] = str[j] - '0';
            }
        }
        if (check(0)) {
            printf ("0\n");
            continue;
        } else if (check(1)) {
            printf ("1\n%d %d\n", n - 1, n);
            continue;
        } else if (check(2)) {
            printf ("1\n%d %d\n", n, n - 1);
            continue;
        } else if (check(3)) {
            printf ("2\n%d %d\n%d %d\n", n, n - 1, n - 1, n);
            continue;
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;

const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
char str[205];
int n, mp[205][205], flag, vis[205][205];

void dfs(int x, int y, int ops) {
	vis[x][y] = 1;
    if (x == y && x == n) {
        flag = 1;
        return;
    }
    for (int i = 0; i <= 3; ++i) {
        int tx = x + dx[i], ty = y + dy[i];
        if (tx < 1 || ty < 1 || tx > n || ty > n || vis[tx][ty] || (mp[tx][ty] != ops && mp[tx][ty] != -1)) continue;
        dfs(tx, ty, ops);
    }
}

inline bool check(int num) {
    if (num == 2) {
        mp[n][n - 1] ^= 1;
    } else if (num == 1) {
        mp[n - 1][n] ^= 1;
    } else if (num == 3) {
        mp[n][n - 1] ^= 1;
        mp[n - 1][n] ^= 1;
    }
    flag = 0;
    int tmp = 0;
    for (int i = 0; i <= 1; ++i) {
    	memset(vis, 0, sizeof vis);
        dfs(1, 1, i);
        if (flag) {
            tmp = 1;
            break;
        }
    }
    if (num == 2) {
        mp[n][n - 1] ^= 1;
    } else if (num == 1) {
        mp[n - 1][n] ^= 1;
    } else if (num == 3) {
        mp[n][n - 1] ^= 1;
        mp[n - 1][n] ^= 1;
    }
    if (!tmp) return 1;
    return 0;
}

int main() {
    int T;
    scanf ("%d", &T);
    while (T--) {
        memset(mp, 0, sizeof mp);
        scanf ("%d%d", &n);
        for (int i = 1; i <= n; ++i) {
            scanf ("%s", str);
            for (int j = 0; j < n; ++j) {
                if (str[j] == 'S' || str[j] == 'F') {
                    mp[i][j + 1] = -1;
                    continue;
                }
                mp[i][j + 1] = str[j] - '0';
            }
        }
        if (check(0)) {
            printf ("0\n");
            continue;
        } else if (check(1)) {
            printf ("1\n%d %d\n", n - 1, n);
            continue;
        } else if (check(2)) {
            printf ("1\n%d %d\n", n, n - 1);
            continue;
        } else if (check(3)) {
            printf ("2\n%d %d\n%d %d\n", n, n - 1, n - 1, n);
            continue;
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;

const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
char str[205];
int n, mp[205][205], flag, vis[205][205];

void dfs(int x, int y, int ops) {
    if (x == y && x == n) {
        flag = 1;
        return;
    }vis[x][y] = 1;
    for (int i = 0; i <= 3; ++i) {
        int tx = x + dx[i], ty = y + dy[i];
        if (tx < 1 || ty < 1 || tx > n || ty > n || vis[tx][ty] || (mp[tx][ty] != ops && mp[tx][ty] != -1)) continue;
        dfs(tx, ty, ops);
    }
}

inline bool check(int num) {
    if (num == 2) {
        mp[n][n - 1] ^= 1;
    } else if (num == 1) {
        mp[n - 1][n] ^= 1;
    } else if (num == 3) {
        mp[n][n - 1] ^= 1;
        mp[n - 1][n] ^= 1;
    }
    flag = 0;
    int tmp = 0;
    for (int i = 0; i <= 1; ++i) {
    	memset(vis, 0, sizeof vis);
        dfs(1, 1, i);
        if (flag) {
            tmp = 1;
            break;
        }
    }
    if (num == 2) {
        mp[n][n - 1] ^= 1;
    } else if (num == 1) {
        mp[n - 1][n] ^= 1;
    } else if (num == 3) {
        mp[n][n - 1] ^= 1;
        mp[n - 1][n] ^= 1;
    }
    if (!tmp) return 1;
    return 0;
}

int main() {
    int T;
    scanf ("%d", &T);
    while (T--) {
        memset(mp, 0, sizeof mp);
        scanf ("%d%d", &n);
        for (int i = 1; i <= n; ++i) {
            scanf ("%s", str);
            for (int j = 0; j < n; ++j) {
                if (str[j] == 'S' || str[j] == 'F') {
                    mp[i][j + 1] = -1;
                    continue;
                }
                mp[i][j + 1] = str[j] - '0';
            }
        }
        if (check(0)) {
            printf ("0\n");
            continue;
        } else if (check(1)) {
            printf ("1\n%d %d\n", n - 1, n);
            continue;
        } else if (check(2)) {
            printf ("1\n%d %d\n", n, n - 1);
            continue;
        } else if (check(3)) {
            printf ("2\n%d %d\n%d %d\n", n, n - 1, n - 1, n);
            continue;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#define ts cout<<"ok"<<endl
#define int long long
#define hh puts("")
#define pc putchar
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
using namespace std;
const int N=205;
int n,cnt;
char s[N][N];
struct node{
	int x,y;
}p[N];
inline int read(){
    int ret=0,ff=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-') ff=-1;ch=getchar();}
    while(isdigit(ch)){ret=ret*10+(ch^48);ch=getchar();}
    return ret*ff;
}
void write(int x){if(x<0){x=-x,pc('-');}if(x>9) write(x/10);pc(x%10+48);}
void writeln(int x){write(x),hh;}
void writesp(int x){write(x),pc(' ');}
signed main(){
	int T=read();
	while(T--){
		n=read();
		for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
		cnt=0;
		int a=s[1][2]-'0',b=s[2][1]-'0',c=s[n][n-1]-'0',d=s[n-1][n]-'0';
		if(a!=b&&c!=d){
			if(a==0) p[++cnt]=(node){2,1};
			else p[++cnt]=(node){1,2};
			if(c==1) p[++cnt]=(node){n-1,n};
			else p[++cnt]=(node){n,n-1};
		}
		else{
			if(a!=b){
				if(a==(c^1)) p[++cnt]=(node){2,1};
				else p[++cnt]=(node){1,2};
			}
			else if(c!=d){
				if(c==(a^1)) p[++cnt]=(node){n-1,n};
				else p[++cnt]=(node){n,n-1};
			}
			else{
				if(a==c){
					p[++cnt]=(node){1,2};
					p[++cnt]=(node){2,1};
				}
			}
		}
		writeln(cnt);
		for(int i=1;i<=cnt;i++) writesp(p[i].x),writeln(p[i].y);
	}
    return 0;
}


#include<bits/stdc++.h>
#define ts cout<<"ok"<<endl
#define int long long
#define hh puts("")
#define pc putchar
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
using namespace std;
const int N=205;
int n,cnt;
char s[N][N];
struct node{
	int x,y;
}p[N];
inline int read(){
    int ret=0,ff=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-') ff=-1;ch=getchar();}
    while(isdigit(ch)){ret=ret*10+(ch^48);ch=getchar();}
    return ret*ff;
}
void write(int x){if(x<0){x=-x,pc('-');}if(x>9) write(x/10);pc(x%10+48);}
void writeln(int x){write(x),hh;}
void writesp(int x){write(x),pc(' ');}
signed main(){
	int T=read();
	while(T--){
		n=read();
		for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
		cnt=0;
		int a=s[1][2]-'0',b=s[2][1]-'0',c=s[n][n-1]-'0',d=s[n-1][n]-'0';
		if(a!=b&&c!=d){
			if(a==0) p[++cnt]=(node){2,1};
			else p[++cnt]=(node){1,2};
			if(c==1) p[++cnt]=(node){n-1,n};
			else p[++cnt]=(node){n,n-1};
		}
		else{
			if(a!=b){
				if(a==(c^1)) p[++cnt]=(node){2,1};
				else p[++cnt]=(node){1,2};
			}
			if(c!=d){
				if(c==(a^1)) p[++cnt]=(node){n-1,n};
				else p[++cnt]=(node){n,n-1};
			}
		}
		writeln(cnt);
		for(int i=1;i<=cnt;i++) writesp(p[i].x),writeln(p[i].y);
	}
    return 0;
}


#include<bits/stdc++.h>
#define ts cout<<"ok"<<endl
#define int long long
#define hh puts("")
#define pc putchar
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
using namespace std;
const int N=205;
int n,cnt;
char s[N][N];
struct node{
	int x,y;
}p[N];
inline int read(){
    int ret=0,ff=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-') ff=-1;ch=getchar();}
    while(isdigit(ch)){ret=ret*10+(ch^48);ch=getchar();}
    return ret*ff;
}
void write(int x){if(x<0){x=-x,pc('-');}if(x>9) write(x/10);pc(x%10+48);}
void writeln(int x){write(x),hh;}
void writesp(int x){write(x),pc(' ');}
signed main(){
	int T=read();
	while(T--){
		n=read();
		for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
		cnt=0;
		int a=s[1][2]-'0',b=s[2][1]-'0',c=s[n][n-1]-'0',d=s[n-1][n]-'0';
		if(a!=b&&c!=d){
			if(a==0) p[++cnt]=(node){2,1};
			else p[++cnt]=(node){1,2};
			if(c==1) p[++cnt]=(node){n-1,n};
			else p[++cnt]=(node){n,n-1};
		}
		else{
			if(a!=b){
				if(a==(c^1)) p[++cnt]=(node){2,1};
				else p[++cnt]=(node){1,2};
			}
			else if(c!=d){
				if(c==(a^1)) p[++cnt]=(node){n-1,n};
				else p[++cnt]=(node){n,n-1};
			}
			else{
				p[++cnt]=(node){1,2};
				p[++cnt]=(node){2,1};
			}
		}
		writeln(cnt);
		for(int i=1;i<=cnt;i++) writesp(p[i].x),writeln(p[i].y);
	}
    return 0;
}


import math
t = int(input())
while t:
    n = int(input())
    a = []
    a.append(4)
    for i in range(2,4*n+1,2):
        flag=0
        for j in range(len(a)):
            x = math.gcd(a[j],i)
            if x==1 or a[j]%i==0 or i%a[j]==0:
                if flag==0:
                    num = a[j]
                flag+=1

        if flag==0:
            a.append(i)
        elif flag==1:
            a.remove(num)
            a.append(i)

    for i in range(n):
        print(a[i],end=" ")
    print(" ")
    t-=1


import math
t = int(input())
while t:
    n = int(input())
    a = [ ]
    a.append(4)
    for i in range(6,4*n+1):
        x = math.gcd(4,i)
        if x!=4 and x!=1 and x!=i:
            a.append(i)
    for i in range(n):
        print(a[i],end=" ")
    print(" ")
    t-=1


import math
t = int(input())
while t:
    n = int(input())
    a = [ ]
    for i in range(2,4*n+1):
        for j in range(i+1,4*n+1):
            x = math.gcd(i,j)
            if x!=1 and x!=i and x!=j:
                if i not in a:
                    if j not in a:
                        a.append(i)
                        a.append(j)
    for i in range(n):
        print(a[i],end=" ")
    print(" ")
    t-=1


import math
t = int(input())
while t:
    n = int(input())
    a = []
    for i in range(2,4*n+1):
        for j in range(i+1,4*n+1):
            x = math.gcd(i,j)
            if x!=1 and x!=i and x!=j:
                if len(a)>0:
                    if i not in a and j not in a:
                        y = math.gcd(a[-1],i)
                        z = math.gcd(a[-1],j)
                        if y!=1 and y!=i and y!=a[-1]:
                            a.append(i)
                            a.append(j)
                            break
                        if z!=1 and z!=j and z!=a[-1]:
                            a.append(j)
                            a.append(i)
                else:
                    a.append(i)
                    a.append(j)

    for i in range(n):
        print(a[i],end=" ")
    print(" ")
    t-=1


import math
t = int(input())
while t:
    n = int(input())
    a = [ ]
    a.append(4)
    flag=0
    x = 4
    for i in range(6,4*n+1):
        if flag==0:
            x+=2
            a.append(x)
            flag=1
            continue
        else:
            x+=4
            a.append(x)
            flag=0
            continue

    for i in range(n):
        print(a[i],end=" ")
    print(" ")
    t-=1


import math
t = int(input())
while t:
    n = int(input())
    a = []
    a.append(4)
    for i in range(2,4*n+1,2):
        flag=0
        for j in range(len(a)):
            x = math.gcd(a[j],i)
            if x==1 or x==a[j] or x==i:
                flag=1
                break

        if flag==0:
            a.append(i)

    for i in range(n):
        print(a[i],end=" ")
    print(" ")
    t-=1


t=int(input())
import math
for _ in range(t):
    n=int(input())
    i=4*n
    a = set()
    while(i>=1 and len(a)!=n):
        flag=1
        for j in a:
            if(math.gcd(j,i)==min(i,j)):
                flag=0
        if(flag==1):
            a.add(i)
        i-=2
    for i in a:
        print(i,end=' ')
    print()


t=int(input())
import math
for _ in range(t):
    n=int(input())
    i=4*n-1
    a = set()
    while(i>1 and len(a)!=n):
        flag=1
        for j in a:
            if(math.gcd(j,i)!=1):
                flag=0
        if(flag==1):
            a.add(i)
        i-=1
    for i in a:
        print(i,end=' ')
    print()


t=int(input())
import math
for _ in range(t):
    n=int(input())
    i=4*n
    a = set()
    a.add(1)
    while(i>=1 and len(a)!=n):
        flag=1
        for j in a:
            if(math.gcd(j,i)!=1):
                flag=0
        if(flag==1):
            a.add(i)
        i-=1
    for i in a:
        print(i,end=' ')
    print()


t=int(input())
import math
for _ in range(t):
    n=int(input())
    i=4*n
    a = set()
    while(i>=1 and len(a)!=n):
        flag=1
        for j in a:
            if(math.gcd(j,i)!=1):
                flag=0
        if(flag==1):
            a.add(i)
        i-=1
    for i in a:
        print(i,end=' ')
    print()


def Resheto(n):
    a = [0] * n
    for i in range(n):
        a[i] = i

    a[1] = 0

    m = 2
    while m < n:
        if a[m] != 0:
            j = m * 2
            while j < n:
                a[j] = 0
                j = j + m
        m += 1

    b = []
    for i in a:
        if a[i] != 0:
            b.append(a[i])

    del a
    return b
t = int(input())

for _ in range(t):
    k = int(input())
    ch = Resheto(200)
    r = []
    i = j = d = 0
    while i < len(ch) and d < k:
        r.append(2 * ch[i])
        i += 1
        d += 1
    i = 0
    while d < k:
        if ch[i] != ch[j]:
            if ch[i] * ch[j] * 2 <= 4 * k:
                r.append(ch[i] * ch[j] * 2)
                d += 1
            elif ch[i] * ch[j] * 2 > 4 * k:
                i += 1
                j = -1
        j += 1
    print(*r)


t = int(input())
for _ in range(t):
    n = int(input())
    for i in range(n):
        print(4*n - i * 2, end= " ")
    print()


import sys, os, io
I = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

for tc in range(1, 1 + int(I())):
    n = int(I())
    print(*list(range(4*n,1,-2))[:n])


import sys, os, io
I = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

p = []
for i in range(2,100000):
    for j in range(2, i):
        if i % j == 0:
            break
    else:
        p.append(i)
    if len(p) >= 100:
        break

for tc in range(1, 1 + int(I())):
    n = int(I())
    print(*[ p[i] * 2 for i in range(n)])


import sys, os, io
I = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

p = []
for i in range(2,100000):
    for j in range(2, i):
        if i % j == 0:
            break
    else:
        p.append(i)
    if len(p) >= 100:
        break

for tc in range(1, 1 + int(I())):
    n = int(I())
    l = []
    for i in range(4, 4*n+1, 2):
        for j in l:
            if i % j == 0:
                break
        else:
            l.append(i)
    print(*l)


import sys, os, io
I = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

p = []
for i in range(2,100000):
    for j in range(2, i):
        if i % j == 0:
            break
    else:
        p.append(i)
    if len(p) >= 100:
        break

for tc in range(1, 1 + int(I())):
    n = int(I())
    l = []
    i, j = 0, 0
    for _ in range(n):
        l.append(p[i]*p[j])
        if i == j:
            i, j = i+1, 0
        else:
            j += 1
    print(*l)


import sys, os, io
I = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

p = []
for i in range(2,100000):
    j = 2
    while j * j < i:
        j += 1
    if j * j > i:
        p.append(i)
    if len(p) >= 100:
        break

for tc in range(1, 1 + int(I())):
    n = int(I())
    print(*[ p[i] * 2 for i in range(n)])


for _ in range(int(input())):
    n = int(input())
    ans = []
    for i in range(n):
        ans.append(4+i*2)
    print(ans)


for _ in range(int(input())):
    n = int(input())
    ans = []
    for i in range(n):
        ans.append(10+i*2)
    print(ans)


for _ in range(int(input())):
    n = int(input())
    ans = 4*n
    for i in range(n):
        print(ans,end= ' ')
        ans-=2
    print()


t = int(input())
for _ in range(t):
    n = int(input())
    dp = [4,6]
    for i in range(1,n):
        dp.append(dp[i-1] * 2 +2)
    print(*dp[0:n])


t = int(input())
for _ in range(t):
    n = int(input())
    if (n == 1):
        print(4)
    else:
        dp = [4,6]
        for i in range(2,n):
            dp.append(dp[i-2] * 2 +2)
        print(*dp[0:n])


t = int(input())
for _ in range(t):
    n = int(input())
    if (n == 1):
        print(4)
    else:
        dp = [4,6]
        for i in range(2,n):
            if i % 2 == 0:
                dp.append(dp[i-1]+dp[i-2])
            else:
                dp.append(dp[i-1]+dp[i-3])

        print(*dp)


t = int(input())
for _ in range(t):
    n = int(input())
    if (n == 1):
        print(4)
    else:
        dp = [4,6]
        for i in range(1,n):
            dp.append(dp[i-1] * 2 +2)
        print(*dp[0:n])


t = int(input())
for _ in range(t):
    n = int(input())
    if (n == 1):
        print(4)
    else:
        dp = [4,6]
        for i in range(2,n):
            dp.append(dp[i-2] +dp[i-1])
        print(*dp[0:n])


t = int(input())
for _ in range(t):
    n = int(input())
    k = 2 * n
    for i in range(n):
        print(k,end= ' ')
        k+=2
    print()


from collections import deque

t = int(input())
for _ in range(t):
    a, b = map(int, input().split())
    s1 = input()
    cnt = 0
    s = deque()
    for i in range(len(s1)):
        s.append(s1[i])
    if (len(s) > 0):
        while s[-1] == '0':
            if (len(s)== 0):
                break
            s.pop()
    if (len(s) > 0):
        while s[0] == '0':
            if (len(s) == 0):
                break
            s.popleft()

    solve = [a]
    ans = 0
    for i in range(1, len(s)):
        if s[i - 1] == '1' and s[i] == '1':
            solve.append(solve[-1])
        if s[i - 1] == '1' and s[i] == '0':
            ans += solve[-1]
            solve.append(solve[-1] + b)
        if s[i - 1] == '0' and s[i] == '0':
            solve.append(solve[-1] + b)
        if s[i - 1] == '0' and s[i] == '1':
            solve.append(min(solve[-1], ans + a))
    print(solve[-1])


'''

                            Online Python Compiler.
                Code, Compile, Run and Debug python program online.
Write your code in this editor and press "Run" button to execute it.

'''

t=int(input())
for i in range(t):
    n=int(input())
    for i in range(n):
        print(2*(i+1),end=" ")
    print()


t=int(input())
for i in range(t):
    n=int(input())
    j=0
    for i in range(n):
        print((n*4)-j,end=" ")
        j+=2
    print()


test = int(input())
while test>0:
    test-=1
    n = int(input())
    arr = []
    a = 2
    while n>0:
        ch = 0
        for i in range(2,a):
            if a%i == 0:
                ch = 1
                break
        if ch == 0:
            arr.append(a)
            n-=1
        a+=1
    for i in range(len(arr)):
        print(2*arr[i],end = " ")
    print()


test = int(input())
while test>0:
    test-=1
    n = int(input())
    arr = []
    a = 2
    while n>0:
        ch = 0
        for i in range(2,a):
            if a%i == 0:
                ch = 1
                break
        if ch == 0:
            arr.append(a)
            n-=1
        a+=1
    for i in range(len(arr)):
        print(2*arr[i],end = " ")


test = int(input())
while test>0:
    test-=1
    n = int(input())
    arr = []
    a = 2
    for i in range(n+1,2*n+1):
        arr.append(i)
    for i in range(len(arr)):
        print(2*arr[i],end = " ")
    print()


"""
#If FastIO not needed, used this and don't forget to strip
#import sys, math
#input = sys.stdin.readline
"""

import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right

from types import GeneratorType
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        import os
        self.os = os
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            self.os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

from collections import defaultdict as dd, deque as dq
import math, string

def getInts():
    return [int(s) for s in input().split()]

def getInt():
    return int(input())

def getStrs():
    return [s for s in input().split()]

def getStr():
    return input()

def listStr():
    return list(input())

MOD = 10**9+7

"""

"""

def solve():
    N = getInt()
    ans = []
    for j in range(N):
        if N % 2 == 1 and j > 1:
            k = 2
        else:
            k = 0
        ans.append(4+2*j+k)
    print(*ans)
    return

for _ in range(getInt()):
    solve()