#include <bits/stdc++.h>
using namespace std;
long long dx[4] = {-1, 0, 0, 1};
long long dy[4] = {0, -1, 1, 0};
bool bfs(string s[], long long n, queue<pair<long long, long long> > q, char c,
         long long x, long long y) {
  q.push(make_pair(x, y));
  while (!q.empty()) {
    x = q.front().first;
    y = q.front().second;
    q.pop();
    s[x][y] = 'S';
    for (long long i = 0; i < (long long)(4); i++) {
      if (x + dx[i] >= 0 && x + dx[i] < n && y + dy[i] >= 0 && y + dy[i] < n) {
        if (s[x + dx[i]][y + dy[i]] == 'F') {
          return true;
        } else if (s[x + dx[i]][y + dy[i]] == c) {
          q.push(make_pair(x + dx[i], y + dy[i]));
        }
      }
    }
  }
  return false;
}
int main() {
  long long t;
  cin >> t;
  for (long long repeat = 0; repeat < (long long)(t); repeat++) {
    long long n;
    cin >> n;
    string s[n];
    for (long long i = 0; i < (long long)(n); i++) {
      cin >> s[i];
    }
    vector<pair<long long, long long> > ans;
    if (s[0][1] == '0' && s[1][0] == '0') {
      if (s[n - 2][n - 1] == '0') {
        ans.push_back(make_pair(n - 2, n - 1));
      }
      if (s[n - 1][n - 2] == '0') {
        ans.push_back(make_pair(n - 1, n - 2));
      }
    } else if (s[0][1] == '1' && s[1][0] == '1') {
      if (s[n - 2][n - 1] == '1') {
        ans.push_back(make_pair(n - 2, n - 1));
      }
      if (s[n - 1][n - 2] == '1') {
        ans.push_back(make_pair(n - 1, n - 2));
      }
    } else if (s[0][1] == '0' && s[1][0] == '1') {
      if (s[n - 2][n - 1] == '0' && s[n - 1][n - 2] == '0') {
        ans.push_back(make_pair(0, 1));
      } else if (s[n - 2][n - 1] == '0' && s[n - 1][n - 2] == '1') {
        if (s[n - 2][n - 2] == '0') {
          ans.push_back(make_pair(n - 2, n - 1));
          if (s[n - 1][n - 3] == '1') {
            ans.push_back(make_pair(n - 1, n - 3));
          }
        } else {
          ans.push_back(make_pair(n - 1, n - 2));
          if (s[n - 3][n - 1] == '0') {
            ans.push_back(make_pair(n - 3, n - 1));
          }
        }
      } else if (s[n - 2][n - 1] == '1' && s[n - 1][n - 2] == '0') {
        queue<pair<long long, long long> > q0, q1;
        string sCopy[n];
        for (long long i = 0; i < (long long)(n); i++) {
          sCopy[i] = s[i];
        }
        if (bfs(sCopy, n, q0, '0', 0, 1)) {
          ans.push_back(make_pair(n - 1, n - 2));
          if (s[n - 1][n - 3] == '0') {
            ans.push_back(make_pair(n - 1, n - 3));
          }
        } else {
          ans.push_back(make_pair(n - 2, n - 1));
          if (s[n - 3][n - 1] == '1') {
            ans.push_back(make_pair(n - 3, n - 1));
          }
        }
      } else {
        ans.push_back(make_pair(1, 0));
      }
    } else if (s[0][1] == '1' && s[1][0] == '0') {
      if (s[n - 2][n - 1] == '1' && s[n - 1][n - 2] == '1') {
        ans.push_back(make_pair(0, 1));
      } else if (s[n - 2][n - 1] == '1' && s[n - 1][n - 2] == '0') {
        if (s[n - 2][n - 2] == '1') {
          ans.push_back(make_pair(n - 2, n - 1));
          if (s[n - 1][n - 3] == '1') {
            ans.push_back(make_pair(n - 1, n - 3));
          }
        } else {
          ans.push_back(make_pair(n - 1, n - 2));
          if (s[n - 3][n - 1] == '0') {
            ans.push_back(make_pair(n - 3, n - 1));
          }
        }
      } else if (s[n - 2][n - 1] == '0' && s[n - 1][n - 2] == '1') {
        queue<pair<long long, long long> > q0, q1;
        string sCopy[n];
        for (long long i = 0; i < (long long)(n); i++) {
          sCopy[i] = s[i];
        }
        if (bfs(sCopy, n, q0, '1', 0, 1)) {
          ans.push_back(make_pair(n - 1, n - 2));
          if (s[n - 1][n - 3] == '1') {
            ans.push_back(make_pair(n - 1, n - 3));
          }
        } else {
          ans.push_back(make_pair(n - 2, n - 1));
          if (s[n - 3][n - 1] == '0') {
            ans.push_back(make_pair(n - 3, n - 1));
          }
        }
      } else {
        ans.push_back(make_pair(1, 0));
      }
    }
    cout << ans.size() << endl;
    for (long long i = 0; i < (long long)(ans.size()); i++) {
      cout << ++(ans[i].first) << " " << ++(ans[i].second) << endl;
    }
  }
  return 0;
}
