#include <bits/stdc++.h>
using namespace std;
const long long N = 120;
inline long long read() {
  long long s = 0, w = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
  return s * w;
}
long long T, n, m, tot, ans[3 * N * N * N][2], f[N][N];
char x[N];
long long upd1(long long x, long long y) {
  if (f[x][y + 1] == 1 && f[x + 1][y + 1] == 1)
    ans[++tot][0] = x, ans[tot][1] = y + 1, ans[++tot][0] = x, ans[tot][1] = y,
    ans[++tot][0] = x + 1, ans[tot][1] = y + 1, f[x][y] = 1 - f[x][y],
    f[x][y + 1] = 0, f[x + 1][y + 1] = 0;
  if (f[x][y + 1] == 1 && f[x + 1][y + 1] == 0)
    ans[++tot][0] = x, ans[tot][1] = y + 1, ans[++tot][0] = x, ans[tot][1] = y,
    ans[++tot][0] = x + 1, ans[tot][1] = y, f[x][y] = 1 - f[x][y],
    f[x + 1][y] = 1 - f[x + 1][y], f[x][y + 1] = 0;
  if (f[x][y + 1] == 0 && f[x + 1][y + 1] == 1)
    ans[++tot][0] = x + 1, ans[tot][1] = y + 1, ans[++tot][0] = x,
    ans[tot][1] = y, ans[++tot][0] = x + 1, ans[tot][1] = y,
    f[x][y] = 1 - f[x][y], f[x + 1][y] = 1 - f[x + 1][y], f[x + 1][y + 1] = 0;
}
long long upd2(long long x, long long y) {
  if (f[x + 1][y] == 1 && f[x + 1][y + 1] == 1)
    ans[++tot][0] = x + 1, ans[tot][1] = y, ans[++tot][0] = x + 1,
    ans[tot][1] = y + 1, ans[++tot][0] = x, ans[tot][1] = y,
    f[x][y] = 1 - f[x][y], f[x + 1][y] = 0, f[x + 1][y + 1] = 0;
  if (f[x + 1][y] == 1 && f[x + 1][y + 1] == 0)
    ans[++tot][0] = x + 1, ans[tot][1] = y, ans[++tot][0] = x, ans[tot][1] = y,
    ans[++tot][0] = x, ans[tot][1] = y + 1, f[x][y] = 1 - f[x][y],
    f[x][y + 1] = 1 - f[x][y + 1], f[x + 1][y] = 0;
  if (f[x + 1][y] == 0 && f[x + 1][y + 1] == 1)
    ans[++tot][0] = x + 1, ans[tot][1] = y + 1, ans[++tot][0] = x,
    ans[tot][1] = y, ans[++tot][0] = x, ans[tot][1] = y + 1,
    f[x][y] = 1 - f[x][y], f[x][y + 1] = 1 - f[x][y + 1], f[x + 1][y + 1] = 0;
}
void solve(long long x, long long y) {
  if (f[x][y] == 1 && f[x + 1][y] == 1 && f[x][y + 1] == 1 &&
      f[x + 1][y + 1] == 0)
    ans[++tot][0] = x, ans[tot][1] = y, ans[++tot][0] = x + 1, ans[tot][1] = y,
    ans[++tot][0] = x, ans[tot][1] = y + 1, f[x][y] = 0, f[x + 1][y] = 0,
    f[x][y + 1] = 0, f[x + 1][y + 1] = 0;
  if (f[x][y] == 1 && f[x + 1][y] == 1 && f[x][y + 1] == 0 &&
      f[x + 1][y + 1] == 1)
    ans[++tot][0] = x, ans[tot][1] = y, ans[++tot][0] = x + 1, ans[tot][1] = y,
    ans[++tot][0] = x + 1, ans[tot][1] = y + 1, f[x][y] = 0, f[x + 1][y] = 0,
    f[x][y + 1] = 0, f[x + 1][y + 1] = 0;
  if (f[x][y] == 1 && f[x + 1][y] == 0 && f[x][y + 1] == 1 &&
      f[x + 1][y + 1] == 1)
    ans[++tot][0] = x, ans[tot][1] = y, ans[++tot][0] = x, ans[tot][1] = y + 1,
    ans[++tot][0] = x + 1, ans[tot][1] = y + 1, f[x][y] = 0, f[x + 1][y] = 0,
    f[x][y + 1] = 0, f[x + 1][y + 1] = 0;
  if (f[x][y] == 0 && f[x + 1][y] == 1 && f[x][y + 1] == 1 &&
      f[x + 1][y + 1] == 1)
    ans[++tot][0] = x + 1, ans[tot][1] = y, ans[++tot][0] = x,
    ans[tot][1] = y + 1, ans[++tot][0] = x + 1, ans[tot][1] = y + 1,
    f[x][y] = 0, f[x + 1][y] = 0, f[x][y + 1] = 0, f[x + 1][y + 1] = 0;
  if (f[x][y] == 1 && f[x + 1][y] == 1 && f[x][y + 1] == 0 &&
      f[x + 1][y + 1] == 0)
    ans[++tot][0] = x, ans[tot][1] = y, ans[++tot][0] = x, ans[tot][1] = y + 1,
    ans[++tot][0] = x + 1, ans[tot][1] = y + 1, f[x][y] = 0, f[x + 1][y] = 1,
    f[x][y + 1] = 1, f[x + 1][y + 1] = 1, solve(x, y);
  if (f[x][y] == 1 && f[x + 1][y] == 0 && f[x][y + 1] == 1 &&
      f[x + 1][y + 1] == 0)
    ans[++tot][0] = x, ans[tot][1] = y, ans[++tot][0] = x + 1, ans[tot][1] = y,
    ans[++tot][0] = x + 1, ans[tot][1] = y + 1, f[x][y] = 0, f[x + 1][y] = 1,
    f[x][y + 1] = 1, f[x + 1][y + 1] = 1, solve(x, y);
  if (f[x][y] == 0 && f[x + 1][y] == 0 && f[x][y + 1] == 1 &&
      f[x + 1][y + 1] == 1)
    ans[++tot][0] = x, ans[tot][1] = y, ans[++tot][0] = x + 1, ans[tot][1] = y,
    ans[++tot][0] = x + 1, ans[tot][1] = y + 1, f[x][y] = 1, f[x + 1][y] = 1,
    f[x][y + 1] = 1, f[x + 1][y + 1] = 0, solve(x, y);
  if (f[x][y] == 0 && f[x + 1][y] == 1 && f[x][y + 1] == 0 &&
      f[x + 1][y + 1] == 1)
    ans[++tot][0] = x, ans[tot][1] = y, ans[++tot][0] = x, ans[tot][1] = y + 1,
    ans[++tot][0] = x + 1, ans[tot][1] = y + 1, f[x][y] = 1, f[x + 1][y] = 1,
    f[x][y + 1] = 1, f[x + 1][y + 1] = 0, solve(x, y);
  if (f[x][y] == 1 && f[x + 1][y] == 0 && f[x][y + 1] == 0 &&
      f[x + 1][y + 1] == 0)
    ans[++tot][0] = x, ans[tot][1] = y, ans[++tot][0] = x + 1, ans[tot][1] = y,
    ans[++tot][0] = x, ans[tot][1] = y + 1, f[x][y] = 0, f[x + 1][y] = 1,
    f[x][y + 1] = 1, f[x + 1][y + 1] = 0, solve(x, y);
  if (f[x][y] == 0 && f[x + 1][y] == 1 && f[x][y + 1] == 0 &&
      f[x + 1][y + 1] == 0)
    ans[++tot][0] = x + 1, ans[tot][1] = y, ans[++tot][0] = x,
    ans[tot][1] = y + 1, ans[++tot][0] = x + 1, ans[tot][1] = y + 1,
    f[x][y] = 0, f[x + 1][y] = 0, f[x][y + 1] = 1, f[x + 1][y + 1] = 1,
    solve(x, y);
  if (f[x][y] == 0 && f[x + 1][y] == 0 && f[x][y + 1] == 1 &&
      f[x + 1][y + 1] == 0)
    ans[++tot][0] = x, ans[tot][1] = y, ans[++tot][0] = x + 1, ans[tot][1] = y,
    ans[++tot][0] = x, ans[tot][1] = y + 1, f[x][y] = 1, f[x + 1][y] = 1,
    f[x][y + 1] = 0, f[x + 1][y + 1] = 0, solve(x, y);
  if (f[x][y] == 0 && f[x + 1][y] == 0 && f[x][y + 1] == 0 &&
      f[x + 1][y + 1] == 1)
    ans[++tot][0] = x + 1, ans[tot][1] = y, ans[++tot][0] = x,
    ans[tot][1] = y + 1, ans[++tot][0] = x + 1, ans[tot][1] = y + 1,
    f[x][y] = 0, f[x + 1][y] = 1, f[x][y + 1] = 1, f[x + 1][y + 1] = 0,
    solve(x, y);
  if (f[x][y] == 1 && f[x + 1][y] == 0 && f[x][y + 1] == 0 &&
      f[x + 1][y + 1] == 1)
    ans[++tot][0] = x + 1, ans[tot][1] = y, ans[++tot][0] = x,
    ans[tot][1] = y + 1, ans[++tot][0] = x + 1, ans[tot][1] = y + 1,
    f[x][y] = 1, f[x + 1][y] = 1, f[x][y + 1] = 1, f[x + 1][y + 1] = 0,
    solve(x, y);
  if (f[x][y] == 0 && f[x + 1][y] == 1 && f[x][y + 1] == 1 &&
      f[x + 1][y + 1] == 0)
    ans[++tot][0] = x, ans[tot][1] = y, ans[++tot][0] = x + 1, ans[tot][1] = y,
    ans[++tot][0] = x + 1, ans[tot][1] = y + 1, f[x][y] = 1, f[x + 1][y] = 0,
    f[x][y + 1] = 1, f[x + 1][y + 1] = 1, solve(x, y);
  if (f[x][y] == 1 && f[x + 1][y] == 1 && f[x][y + 1] == 1 &&
      f[x + 1][y + 1] == 1)
    ans[++tot][0] = x + 1, ans[tot][1] = y, ans[++tot][0] = x,
    ans[tot][1] = y + 1, ans[++tot][0] = x + 1, ans[tot][1] = y + 1,
    f[x][y] = 1, f[x + 1][y] = 0, f[x][y + 1] = 0, f[x + 1][y + 1] = 0,
    solve(x, y);
}
signed main() {
  T = read();
  while (T--) {
    tot = 0;
    n = read(), m = read();
    for (long long i = 1; i <= n; i++) {
      scanf("%s", x);
      for (long long j = 0; j < m; j++) {
        if (x[j] == '0')
          f[i][j + 1] = 0;
        else
          f[i][j + 1] = 1;
      }
    }
    if (m % 2 == 1) {
      for (long long i = 1; i <= n / 2; i++) upd1(i * 2 - 1, m - 1);
    }
    if (n % 2 == 1) {
      for (long long i = 1; i <= m / 2; i++) upd2(n - 1, i * 2 - 1);
    }
    for (long long i = 1; i <= n / 2; i++)
      for (long long j = 1; j <= m / 2; j++) solve(i * 2 - 1, j * 2 - 1);
    if (n % 2 == 1 && m % 2 == 1 && f[n][m] == 1) solve(n - 1, m - 1);
    printf("%d\n", tot / 3);
    for (long long i = 1; i <= tot; i++) {
      cout << ans[i][0] << " " << ans[i][1] << " ";
      if (i % 3 == 0) printf("\n");
    }
  }
  return 0;
}
