#include <bits/stdc++.h>
using namespace std;
long long t = 1, n, m, a[109][109], b, cc;
struct st {
  long long a, b;
} ans[90009];
string s;
int main() {
  cin >> t;
  while (t--) {
    cc = 0;
    cin >> n >> m;
    for (long long i = 1; i <= n; i += 1) {
      cin >> s;
      for (long long j = 0; j < m; j += 1) {
        a[i][j + 1] = s[j] - '0';
      }
    }
    for (long long i = 1; i < n; i += 1) {
      for (long long j = 2; j <= m; j += 1) {
        if (a[i][j]) {
          long long cnt = 2;
          if (a[i][j - 1]) ans[cc++] = {i, j - 1}, a[i][j - 1] = 0, cnt -= 1;
          if (a[i + 1][j - 1])
            ans[cc++] = {i + 1, j - 1}, a[i + 1][j - 1] = 0, cnt -= 1;
          if (cnt == 1) ans[cc++] = {i + 1, j}, a[i + 1][j] ^= 1;
          if (cnt < 2) ans[cc++] = {i, j}, a[i][j] = 0;
        } else {
          long long cnt = 2;
          if (a[i + 1][j - 1])
            ans[cc++] = {i + 1, j - 1}, a[i + 1][j - 1] = 0, cnt -= 1;
          if (a[i][j - 1]) ans[cc++] = {i, j - 1}, a[i][j - 1] = 0, cnt -= 1;
          if (cnt == 1)
            ans[cc++] = {i + 1, j}, a[i + 1][j] ^= 1, ans[cc++] = {i, j},
            a[i][j] = 1;
          if (cnt == 0) {
            if (a[i + 1][j])
              ans[cc++] = {i + 1, j}, a[i + 1][j] = 0;
            else
              ans[cc++] = {i, j}, a[i][j] = 1;
          }
        }
      }
      if (a[i][m]) {
        ans[cc++] = {i, m}, ans[cc++] = {i + 1, m - 1}, ans[cc++] = {i, m - 1};
        ans[cc++] = {i + 1, m}, ans[cc++] = {i + 1, m - 1},
        ans[cc++] = {i, m - 1};
        a[i][m] = 0;
        a[i + 1][m] ^= 1;
      }
    }
    for (long long j = 1; j <= m; j += 1)
      if (a[n][j]) {
        ans[cc++] = {n, j}, ans[cc++] = {n - 1, j}, ans[cc++] = {n, j - 1};
        ans[cc++] = {n - 1, j - 1}, ans[cc++] = {n - 1, j}, ans[cc++] = {n, j};
        ans[cc++] = {n - 1, j - 1}, ans[cc++] = {n, j - 1}, ans[cc++] = {n, j};
      }
    cout << cc / 3 << endl;
    for (long long i = 0; i < cc; i += 1) {
      cout << ans[i].a << ' ' << ans[i].b << ' ';
      if (i % 3 == 2) cout << endl;
    }
    cout << endl;
  }
  return 0;
}
