#include <bits/stdc++.h>
using namespace std;
struct op {
  int x1, y1, x2, y2, x3, y3;
};
int n, m;
vector<vector<int> > a;
vector<op> ans;
void go(int x1, int y1, int x2, int y2, int x3, int y3) {
  ans.push_back({x1, y1, x2, y2, x3, y3});
  a[x1][y1] ^= 1;
  a[x2][y2] ^= 1;
  a[x3][y3] ^= 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    a.clear();
    ans.clear();
    cin >> n >> m;
    a.resize(n, vector<int>(m));
    for (auto &i : a) {
      for (auto &j : i) {
        char c;
        cin >> c;
        j = c - '0';
      }
    }
    for (int i = 0; i + 1 < n; i++) {
      for (int j = 0; j + 1 < m; j++) {
        if (a[i][j]) {
          go(i, j, i + 1, j, i + 1, j + 1);
        }
      }
      if (a[i][m - 1]) {
        go(i, m - 1, i + 1, m - 1, i + 1, m - 2);
      }
    }
    for (int j = 0; j + 1 < m; j++) {
      if (a[n - 1][j] == 0) continue;
      if (a[n - 2][j]) {
        go(n - 2, j, n - 1, j, n - 1, j + 1);
      } else if (a[n - 1][j + 1]) {
        go(n - 1, j, n - 2, j, n - 2, j + 1);
        go(n - 1, j + 1, n - 2, j, n - 2, j + 1);
      } else {
        go(n - 1, j, n - 1, j + 1, n - 2, j + 1);
      }
    }
    if (a[n - 1][m - 1] && a[n - 2][m - 1]) {
      go(n - 1, m - 1, n - 1, m - 2, n - 2, m - 2);
      go(n - 2, m - 1, n - 1, m - 2, n - 2, m - 2);
    } else if (a[n - 1][m - 1]) {
      go(n - 1, m - 1, n - 1, m - 2, n - 2, m - 2);
      go(n - 2, m - 2, n - 1, m - 1, n - 2, m - 1);
      go(n - 1, m - 2, n - 1, m - 1, n - 2, m - 1);
    }
    cout << ans.size() << "\n";
    for (auto &i : ans) {
      cout << i.x1 + 1 << " " << i.y1 + 1 << " " << i.x2 + 1 << " " << i.y2 + 1
           << " " << i.x3 + 1 << " " << i.y3 + 1 << "\n";
    }
  }
}
