#include <bits/stdc++.h>
using namespace std;
int n;
vector<string> graph;
set<pair<int, int> > coord;
vector<vector<bool> > mark;
void DFS(pair<int, int> vertex, pair<int, int> parent) {
  mark[vertex.first][vertex.second] = 1;
  int dx[] = {0, 0, -1, 1};
  int dy[] = {-1, 1, 0, 0};
  for (int i = 0; i < 4; i++) {
    int new_x = dx[i] + vertex.first, new_y = dy[i] + vertex.second;
    if (new_x >= 0 and new_x < n and new_y >= 0 and new_y < n) {
      if ((graph[new_x][new_y] == '1' and
           graph[vertex.first][vertex.second] == '0') or
          (graph[new_x][new_y] == '0' and
           graph[vertex.first][vertex.second] == '1'))
        continue;
      if (mark[new_x][new_y] == 1) continue;
      if (new_x != parent.first or new_y != parent.second) {
        if (new_x == n - 1 and new_y == n - 1) {
          if (coord.find({vertex.first, vertex.second}) == coord.end()) {
            coord.insert({vertex.first, vertex.second});
            if (graph[vertex.first][vertex.second] == '1')
              graph[vertex.first][vertex.second] = '0';
            else
              graph[vertex.first][vertex.second] = '1';
          } else {
            if (graph[parent.first][parent.second] == '1')
              graph[parent.first][parent.second] = '0';
            else
              graph[parent.first][parent.second] = '1';
            coord.insert({parent.first, parent.second});
          }
        } else
          DFS({new_x, new_y}, vertex);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    graph.clear();
    graph.resize(n);
    mark.clear();
    mark.resize(n, vector<bool>(n, false));
    for (auto &i : graph) cin >> i;
    mark[0][0] = 1;
    DFS({0, 1}, {0, 0});
    if (coord.size() < 2) {
      mark.clear();
      mark.resize(n, vector<bool>(n, false));
      mark[0][0] = 1;
      DFS({1, 0}, {0, 0});
      if (coord.size() < 2) {
        mark.clear();
        mark.resize(n, vector<bool>(n, false));
        mark[0][0] = 1;
        DFS({0, 1}, {0, 0});
      }
      if (coord.size() < 2) {
        mark.clear();
        mark.resize(n, vector<bool>(n, false));
        mark[0][0] = 1;
        DFS({1, 0}, {0, 0});
      }
    }
    cout << coord.size() << endl;
    for (auto i : coord) cout << i.first + 1 << " " << i.second + 1 << endl;
    coord.clear();
  }
  return 0;
}
