#include <bits/stdc++.h>
using namespace std;
const int maxn = 200;
char s[maxn][maxn];
int a[maxn][maxn];
int t, n, c0, c1, h;
int x1[30013], x2[30013], x3[30013];
int y[30013], y2[30013], y3[30013];
int main() {
  scanf("%d", &t);
  while (t--) {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) {
      scanf("%s", s[i] + 1);
      for (int j = 1; j <= m; j++) a[i][j] = s[i][j] - '0';
    }
    int ans = 0;
    if (n > 2) {
      for (int i = 1; i < n; i++) {
        for (int j = 1; j < m; j++) {
          if (a[i][j]) {
            ans++;
            if (a[i][j + 1]) {
              x1[ans] = i, y[ans] = j, a[i][j] ^= 1;
              x2[ans] = i, y2[ans] = j + 1, a[i][j + 1] ^= 1;
              x3[ans] = i + 1, y3[ans] = j, a[i + 1][j] ^= 1;
            } else {
              x1[ans] = i, y[ans] = j, a[i][j] ^= 1;
              x2[ans] = i + 1, y2[ans] = j + 1, a[i + 1][j + 1] ^= 1;
              x3[ans] = i + 1, y3[ans] = j, a[i + 1][j] ^= 1;
            }
          } else if (a[i][j + 1]) {
            ans++;
            x1[ans] = i, y[ans] = j + 1, a[i][j + 1] ^= 1;
            x2[ans] = i + 1, y2[ans] = j + 1, a[i + 1][j + 1] ^= 1;
            x3[ans] = i + 1, y3[ans] = j, a[i + 1][j] ^= 1;
          }
        }
      }
    }
    for (int j = 1; j < m; j++) {
      if (a[n - 1][j]) {
        ans++;
        if (a[n][j]) {
          x1[ans] = n, y[ans] = j, a[n][j] ^= 1;
          x2[ans] = n - 1, y2[ans] = j, a[n - 1][j] ^= 1;
          x3[ans] = n, y3[ans] = j + 1, a[n][j + 1] ^= 1;
        } else {
          x1[ans] = n, y[ans] = j + 1, a[n][j + 1] ^= 1;
          x2[ans] = n - 1, y2[ans] = j, a[n - 1][j] ^= 1;
          x3[ans] = n - 1, y3[ans] = j + 1, a[n - 1][j + 1] ^= 1;
        }
      } else if (a[n][j]) {
        ans++;
        x1[ans] = n, y[ans] = j, a[n][j] ^= 1;
        x2[ans] = n - 1, y2[ans] = j + 1, a[n - 1][j + 1] ^= 1;
        x3[ans] = n, y3[ans] = j + 1, a[n][j + 1] ^= 1;
      }
    }
    if (a[n][m] && a[n - 1][m]) {
      ans++;
      x1[ans] = n - 1, y[ans] = m - 1;
      x2[ans] = n, y2[ans] = m - 1;
      x3[ans] = n, y3[ans] = m;
      ans++;
      x1[ans] = n - 1, y[ans] = m - 1;
      x2[ans] = n, y2[ans] = m - 1;
      x3[ans] = n - 1, y3[ans] = m;
    } else if (a[n][m] && !a[n - 1][m]) {
      ans++;
      x1[ans] = n - 1, y[ans] = m - 1;
      x2[ans] = n - 1, y2[ans] = m;
      x3[ans] = n, y3[ans] = m;
      ans++;
      x1[ans] = n, y[ans] = m - 1;
      x2[ans] = n, y2[ans] = m;
      x3[ans] = n - 1, y3[ans] = m;
      ans++;
      x1[ans] = n, y[ans] = m - 1;
      x2[ans] = n, y2[ans] = m;
      x3[ans] = n - 1, y3[ans] = m - 1;
    } else if (!a[n][m] && a[n - 1][m]) {
      ans++;
      x1[ans] = n - 1, y[ans] = m;
      x2[ans] = n, y2[ans] = m - 1;
      x3[ans] = n, y3[ans] = m;
      ans++;
      x1[ans] = n - 1, y[ans] = m - 1;
      x2[ans] = n - 1, y2[ans] = m;
      x3[ans] = n, y3[ans] = m;
      ans++;
      x1[ans] = n - 1, y[ans] = m - 1;
      x2[ans] = n - 1, y2[ans] = m;
      x3[ans] = n, y3[ans] = m - 1;
    }
    printf("%d\n", ans);
    for (int i = 1; i <= ans; i++) {
      printf("%d %d %d %d %d %d\n", x1[i], y[i], x2[i], y2[i], x3[i], y3[i]);
    }
  }
}
