#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
void addAns(vector<vector<P>> &ans, vector<vector<int>> &cnt, vector<P> x) {
  ans.push_back(x);
  for (auto it : x) {
    cnt[it.first][it.second] ^= 1;
  }
}
void solve() {
  int n, m;
  cin >> n >> m;
  vector<string> a(n);
  vector<vector<int>> cnt(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    for (int j = 0; j < m; j++) {
      cnt[i][j] = a[i][j] - '0';
    }
  }
  vector<vector<P>> ans;
  for (int x = n - 1; x >= 2; x--) {
    for (int y = m - 2; y >= 0; y--) {
      vector<P> cur;
      for (int i = 0; i < 2; i++) {
        if (cnt[x][y + i] == 1) cur.push_back({x, y + i});
      }
      if (cur.empty()) continue;
      for (int i = 0; cur.size() < 3; i++) {
        cur.push_back({x - 1, y + i});
      }
      addAns(ans, cnt, cur);
    }
  }
  for (int y = m - 1; y >= 2; y--) {
    vector<P> cur;
    for (int i = 0; i < 2; i++) {
      if (cnt[i][y] == 1) cur.push_back({i, y});
    }
    if (cur.empty()) continue;
    for (int i = 0; (int)cur.size() < 3; i++) {
      cur.push_back({i, y - 1});
    }
    addAns(ans, cnt, cur);
  }
  vector<vector<int>> b(2, vector<int>(2));
  for (int x = 0; x < 2; x++) {
    for (int y = 0; y < 2; y++) {
      if (cnt[x][y] == 0) continue;
      for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
          b[i][j] ^= 1;
        }
      }
      b[x][y] ^= 1;
    }
  }
  for (int x = 0; x < 2; x++) {
    for (int y = 0; y < 2; y++) {
      if (b[x][y] == 0) continue;
      vector<P> cur;
      for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
          if (i != x || j != y) cur.push_back({i, j});
        }
      }
      addAns(ans, cnt, cur);
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) {
    for (int j = 0; j < 3; j++) {
      cout << ans[i][j].first + 1 << " " << ans[i][j].second + 1 << " ";
    }
    cout << endl;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    solve();
  }
  return 0;
}
