#include <bits/stdc++.h>
using namespace std;
char grid[300][300];
long long vis[300][300];
long long n, m;
long long di[] = {0, 0, -1, 1};
long long dj[] = {-1, 1, 0, 0};
bool isPos(long long i, long long j) {
  return (i >= 0 and j >= 0 and i < n and j < n and !vis[i][j]);
}
void dfs(long long i, long long j) {
  vis[i][j] = true;
  for (long long k = 0; k < 4; k++) {
    long long ni = i + di[k], nj = j + dj[k];
    if (isPos(ni, nj) and grid[ni][nj] == grid[i][j]) dfs(ni, nj);
  }
}
void solve() {
  memset(vis, 0, sizeof(vis));
  cin >> n;
  m = n;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) cin >> grid[i][j];
  }
  dfs(0, 1);
  dfs(1, 0);
  long long move = 2;
  vector<pair<long long, long long>> ans;
  auto find = [&](long long i, long long j) {
    if (grid[i][j] == grid[0][1]) {
      ans.push_back({0, 1});
      move--;
    } else if (grid[i][j] == grid[1][0]) {
      ans.push_back({1, 0});
      move--;
    }
  };
  auto chk = [&](long long i, long long j) {
    if (grid[i - 1][j] != grid[i][j] and vis[i - 1][j])
      find(i - 1, j);
    else if (grid[i][j - 1] != grid[i][j] and vis[i][j - 1])
      find(i, j - 1);
  };
  if (vis[n - 2][m - 1]) {
    ans.push_back({n - 2, m - 1});
    move--;
    chk(n - 2, m - 1);
  }
  if (move and vis[n - 1][m - 2]) find(n - 1, m - 2);
  cout << (long long)ans.size() << endl;
  for (auto it : ans) cout << it.first + 1 << " " << it.second + 1 << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cin.tie(nullptr);
  long long t_c = 1;
  cin >> t_c;
  while (t_c--) solve();
}
