#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 5, Mod = 1e9 + 7;
void flip(vector<string> &v, long long i, long long j) {
  if (v[i][j] == '1')
    v[i][j] = '0';
  else
    v[i][j] = '1';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    vector<string> v(n);
    for (auto &x : v) cin >> x;
    long long tot = 0;
    vector<vector<long long> > r;
    for (long long i = 0; i < n - 1; i++) {
      for (long long j = 0; j < m - 1; j++) {
        if (v[i][j] == '1' and v[i + 1][j] == '1') {
          r.push_back({i, j, i + 1, j, i + 1, j + 1});
          flip(v, i, j);
          flip(v, i + 1, j);
          flip(v, i + 1, j + 1);
        } else if (v[i][j] == '1') {
          r.push_back({i, j, i, j + 1, i + 1, j + 1});
          flip(v, i, j);
          flip(v, i, j + 1);
          flip(v, i + 1, j + 1);
        } else if (v[i + 1][j] == '1') {
          r.push_back({i, j + 1, i + 1, j, i + 1, j + 1});
          flip(v, i, j + 1);
          flip(v, i + 1, j);
          flip(v, i + 1, j + 1);
        }
      }
      if (i == n - 2) break;
      if (v[i][m - 1] == '1') {
        r.push_back({i, m - 1, i + 1, m - 2, i + 1, m - 1});
        flip(v, i, m - 1);
        flip(v, i + 1, m - 2);
        flip(v, i + 1, m - 1);
      }
    }
    if (v[n - 2][m - 1] == '1' and v[n - 1][m - 1] == '1') {
      r.push_back({n - 2, m - 2, n - 1, m - 2, n - 1, m - 1});
      r.push_back({n - 2, m - 2, n - 1, m - 2, n - 2, m - 1});
    } else if (v[n - 1][m - 1] == '1') {
      r.push_back({n - 2, m - 2, n - 1, m - 2, n - 1, m - 1});
      r.push_back({n - 2, m - 2, n - 2, m - 1, n - 1, m - 1});
      r.push_back({n - 1, m - 2, n - 1, m - 1, n - 2, m - 1});
    } else if (v[n - 2][m - 1] == '1') {
      r.push_back({n - 2, m - 1, n - 2, m - 2, n - 1, m - 2});
      r.push_back({n - 2, m - 2, n - 2, m - 1, n - 1, m - 1});
      r.push_back({n - 1, m - 2, n - 1, m - 1, n - 2, m - 1});
    }
    cout << r.size() << '\n';
    for (auto x : r) {
      for (auto y : x) cout << y + 1 << " ";
      cout << '\n';
    }
  }
  return 0;
}
