#include <bits/stdc++.h>
using namespace std;
const int mxn = 100;
int n, m;
int a[mxn][mxn];
vector<array<pair<int, int>, 3> > v;
void answer() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      char c;
      cin >> c;
      a[i][j] = c & 1;
    }
  v.clear();
  for (int i = 0; i < n - 1; i++)
    for (int j = 0; j < m - 1; j++)
      if (i + j != n + m - 4) {
        int k = 0;
        v.push_back(array<pair<int, int>, 3>());
        for (int x = 0; x < 2; x++)
          for (int y = 0; y < 2; y++) {
            if ((!(x + y) || (!y && i + x == n - 1) ||
                 (!x && j + y == m - 1)) &&
                a[i + x][j + y]) {
              v.back()[k++] = {i + x + 1, j + y + 1};
              a[i + x][j + y] ^= 1;
            }
          }
        if (!k) {
          v.pop_back();
        } else {
          for (int x = 0; x < 2; x++)
            for (int y = 0; y < 2; y++) {
              if (k < 3 && x + y && (y || i + x < n - 1) &&
                  (x || j + y < m - 1)) {
                v.back()[k++] = {i + x + 1, j + y + 1};
                a[i + x][j + y] ^= 1;
              }
            }
        }
      }
  while (1) {
    int k = 0;
    for (int i = 0; i < 2; i++)
      for (int j = 0; j < 2; j++) {
        k += a[n - i - 1][m - j - 1];
      }
    if (!k) break;
    v.push_back(array<pair<int, int>, 3>());
    for (int i = 0, x = 0, y = 0; i < 2; i++)
      for (int j = 0; j < 2; j++) {
        if ((x < 3 - (k < 3) * 2 && a[n - i - 1][m - j - 1]) ||
            (y < (k < 3) * 2 && !a[n - i - 1][m - j - 1])) {
          v.back()[x + y] = {n - i, m - j};
          ((a[n - i - 1][m - j - 1] ^= 1) ? y : x)++;
        }
      }
  }
  cout << v.size() << '\n';
  for (array<pair<int, int>, 3> i : v)
    for (int j = 0; j < 3; j++) {
      cout << i[j].first << " " << i[j].second << (j == 2 ? '\n' : ' ');
    }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) answer();
  return 0;
}
