#include <bits/stdc++.h>
using namespace std;
bool check(int x, int y, vector<string>& vect) {
  char c = vect[x][y];
  queue<pair<int, int>> q;
  q.push({x, y});
  set<pair<int, int>> visited;
  visited.insert({x, y});
  while (!q.empty()) {
    int X = q.front().first;
    int Y = q.front().second;
    q.pop();
    if (X == 0 && Y == 0 || (X == 0 && Y == 1) || (X == 1 && Y == 0))
      return true;
    int x_dir[4] = {0, 1, 0, -1};
    int y_dir[4] = {1, 0, -1, 0};
    for (int i = 0; i < 4; i++) {
      int currX = X + x_dir[i];
      int currY = Y + y_dir[i];
      if ((currX >= 0) && (currY >= 0) && (currX < vect.size()) &&
          (currY < vect[0].size()) &&
          (visited.find({currX, currY}) == visited.end()) &&
          (vect[currX][currY] == c)) {
        q.push({currX, currY});
        visited.insert({currX, currY});
      }
    }
  }
  return false;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    vector<string> vect;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      string s;
      cin >> s;
      vect.push_back(s);
    }
    vector<pair<int, int>> ans;
    if (check(n - 2, n - 1, vect)) {
      ans.push_back({n - 1, n});
    }
    if (check(n - 1, n - 2, vect)) {
      ans.push_back({n, n - 1});
    }
    if (ans.size() == 0) {
      cout << 0 << endl;
    } else {
      cout << ans.size() << endl;
      for (auto c : ans) {
        cout << c.first << " " << c.second << endl;
      }
    }
  }
}
