#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, t1;
  cin >> t;
  t1 = t;
  vector<vector<int> > v;
  while (t--) {
    vector<int> v1;
    int n;
    cin >> n;
    int p, q, r, s;
    string c;
    for (int i = 0; i < n; i++) {
      cin >> c;
      if (i == 0)
        p = (int)c[1] - 48;
      else if (i == 1)
        q = (int)c[0] - 48;
      if (i == n - 2)
        r = (int)c[n - 1] - 48;
      else if (i == n - 1)
        s = (int)c[n - 2] - 48;
    }
    cout << p << q << r << s << endl;
    if (p == q && r == s) {
      if (p != r) {
        v1.push_back(0);
      } else {
        v1.push_back(2);
        v1.push_back(1);
        v1.push_back(2);
        v1.push_back(2);
        v1.push_back(1);
      }
    } else if (p != q && r != s) {
      v1.push_back(2);
      if (p == r) {
        v1.push_back(1);
        v1.push_back(2);
        v1.push_back(n);
        v1.push_back(n - 1);
      } else {
        v1.push_back(1);
        v1.push_back(2);
        v1.push_back(n - 1);
        v1.push_back(n);
      }
    } else if (p != q) {
      v1.push_back(1);
      if (p == r) {
        v1.push_back(1);
        v1.push_back(2);
      } else {
        v1.push_back(2);
        v1.push_back(1);
      }
    } else if (r != s) {
      v1.push_back(1);
      if (p == r) {
        v1.push_back(n - 1);
        v1.push_back(n);
      } else {
        v1.push_back(n);
        v1.push_back(n - 1);
      }
    }
    v.push_back(v1);
  }
  for (int i = 0; i < t1; i++) {
    if (v[i][0] == 0)
      cout << 0 << endl;
    else if (v[i][0] == 1) {
      cout << 1 << endl;
      cout << v[i][1] << ' ' << v[i][2] << endl;
    } else if (v[i][0] == 2) {
      cout << 2 << endl;
      cout << v[i][1] << ' ' << v[i][2] << endl;
      cout << v[i][3] << ' ' << v[i][4] << endl;
    }
  }
  return 0;
}
