#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while (!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) long long int idx,
               __attribute__((unused)) long long int LINE_NUM) {
  cout << '\n';
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, long long int idx, long long int LINE_NUM,
               Head H, Tail... T) {
  if (idx > 0)
    cout << ", ";
  else
    cout << "Line(" << LINE_NUM << ") ";
  stringstream ss;
  ss << H;
  cout << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}
const long long int mod = 1000000007;
const long long int inf = 1e18;
const long long int N = 1e5 + 5;
void HyperBeast() {
  long long int n;
  cin >> n;
  string s[n];
  for (long long int i = 0; i < n; i++) {
    cin >> s[i];
  }
  bool vis0[n][n];
  bool vis1[n][n];
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < n; j++) {
      vis0[i][j] = false;
      vis1[i][j] = false;
    }
  }
  vis0[0][0] = true;
  vis1[0][0] = true;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < n; j++) {
      if (i == 0 and j == 0)
        continue;
      else if (i == 0) {
        if (s[i][j] == '0')
          vis0[i][j] = vis0[i][j - 1];
        else
          vis1[i][j] = vis1[i][j - 1];
      } else if (j == 0) {
        if (s[i][j] == '0')
          vis0[i][j] = vis0[i - 1][j];
        else
          vis1[i][j] = vis1[i - 1][j];
      } else {
        if (s[i][j] == '0')
          vis0[i][j] = (vis0[i - 1][j] || vis0[i][j - 1]);
        else
          vis1[i][j] = (vis1[i - 1][j] || vis1[i][j - 1]);
      }
    }
  }
  if (vis0[n - 1][n - 2] and vis0[n - 2][n - 1]) {
    if (vis0[0][1] and vis0[1][0]) {
      cout << 2 << '\n';
      cout << "2 1\n 1 2\n";
    } else if (vis0[0][1] and vis1[1][0]) {
      cout << 1 << '\n';
      cout << "1 2\n";
    } else if (vis1[0][1] and vis0[1][0]) {
      cout << 1 << '\n';
      cout << "2 1\n";
    }
  } else if (vis0[n - 1][n - 2]) {
    if (vis1[n - 2][n - 1]) {
      cout << 2 << '\n';
      cout << "2 1\n 1 2\n";
    } else {
      cout << 1 << '\n';
      cout << n << ' ' << n - 1 << '\n';
    }
  } else if (vis0[n - 2][n - 1]) {
    if (vis1[n - 1][n - 2]) {
      cout << 2 << '\n';
      cout << "2 1\n 1 2\n";
    } else {
      cout << 1 << '\n';
      cout << n - 1 << ' ' << n << '\n';
    }
  } else {
    if (vis1[n - 1][n - 2] and vis1[n - 2][n - 1]) {
      if (vis1[0][1] and vis1[1][0]) {
        cout << 2 << '\n';
        cout << "2 1\n 1 2\n";
      } else if (vis1[0][1] and vis0[1][0]) {
        cout << 1 << '\n';
        cout << "1 2\n";
      } else if (vis0[0][1] and vis1[1][0]) {
        cout << 1 << '\n';
        cout << "2 1\n";
      }
    } else if (vis1[n - 1][n - 2]) {
      if (vis0[n - 2][n - 1]) {
        cout << 2 << '\n';
        cout << "2 1\n 1 2\n";
      } else {
        cout << 1 << '\n';
        cout << n << ' ' << n - 1 << '\n';
      }
    } else if (vis1[n - 2][n - 1]) {
      if (vis0[n - 1][n - 2]) {
        cout << 2 << '\n';
        cout << "2 1\n 1 2\n";
      } else {
        cout << 1 << '\n';
        cout << n - 1 << ' ' << n << '\n';
      }
    }
  }
  cout << 0 << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int T = 1;
  cin >> T;
  for (long long int ti = 1; ti <= T; ti++) {
    HyperBeast();
  }
}
