#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
#define int long long int
#define float long double
#define fr first
#define sc second
#define pb push_back
#define in insert
#define sz size
#define U 998244353
#define lwr lower_bound
#define upr upper_bound
#define all(a) (a).begin(),(a).end()
#define ordered_set     tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//vector<int> adj[500005];
string s[300];
bool vis[1000][1000];
void dfs(int i,int j,char val,int n)
{
	vis[i][j]=true;
	if(i>0&&vis[i-1][j]==false&&s[i-1][j]==val)
	{
		dfs(i-1,j,val,n);
	}
	if(i<n-1&&vis[i+1][j]==false&&s[i+1][j]==val)
	{
		dfs(i+1,j,val,n);
	}
	if(j>0&&vis[i][j-1]==false&&s[i][j-1]==val)
	{
		dfs(i,j-1,val,n);
	}
	if(j<n-1&&vis[i][j+1]==false&&s[i][j+1]==val)
	{
		dfs(i,j+1,val,n);
	}


}
signed main()
{
    ios_base::sync_with_stdio(false);
    int tc;
    cin>>tc;
    while(tc--)
    {
    	int n;
    	cin>>n;
    	//string s[n];
    	for(int i=0;i<n;i++)
    	{
    		cin>>s[i];
    	}
    	int con=0;
    	dfs(0,1,s[0][1],n);
    	vector<pair<int,int>> ans;
    	if(vis[1][0]==true)
    	{
    		if(vis[n-1][n-2]&&vis[n-2][n-1])
    		{
    			ans.pb({1,2});
    			ans.pb({2,1});
    		}
    		else if(vis[n-1][n-2]||vis[n-2][n-1])
    		{
    			if(vis[n-1][n-2])
    			{
    				ans.pb({n,n-1});
    			}
    			else
    			{
    				ans.pb({n-1,n});
    			}
    		}
    	}
    	else
    	{
    		if(vis[n-1][n-2]&&vis[n-2][n-1])
    		{
    			ans.pb({1,2});
    		}
    		else if(vis[n-1][n-2]||vis[n-2][n-1])
    		{
    			ans.pb({1,2});
    			dfs(1,0,s[1][0],n);
    			if(vis[n-1][n-2]&&vis[n-2][n-1])
    			{
    				ans.pb({2,1});
    			}
    		}
    		else
    		{
    			dfs(1,0,s[1][0],n);
    			if(vis[n-1][n-2]||vis[n-2][n-1])
    			{
    				ans.pb({2,1});
    			}
    		}
    	}
    	cout<<ans.sz()<<endl;
    	for(int i=0;i<ans.sz();i++)
    	{
    		cout<<ans[i].fr<<" "<<ans[i].sc<<endl;
    	}
    	for(int i=0;i<n;i++)
    	{
    		for(int j=0;j<n;j++)
    		{
    			vis[i][j]=false;
    		}
    	}
    	

    }
}

