#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int n, m, ans1, ans2[N * N][6];
bool g[N][N];
inline char getch() {
  char ch = getchar();
  while (isspace(ch)) ch = getchar();
  return ch;
}
inline void modify(int x1, int y1, int x2, int y2, int x3, int y3) {
  ans1++;
  ans2[ans1][0] = x1;
  ans2[ans1][1] = y1;
  ans2[ans1][2] = x2;
  ans2[ans1][3] = y2;
  ans2[ans1][4] = x3;
  ans2[ans1][5] = y3;
  g[x1][y1] ^= 1;
  g[x2][y2] ^= 1;
  g[x3][y3] ^= 1;
}
void Main() {
  ans1 = 0;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= (n); i++)
    for (int j = 1; j <= (m); j++) g[i][j] = getch() == '1';
  for (int i = n; i >= (3); i--) {
    for (int j = 1; j <= (m - 1); j++)
      if (g[i][j]) modify(i, j, i - 1, j, i - 1, j + 1);
    if (g[i][m]) modify(i, m, i - 1, m, i - 1, m - 1);
  }
  for (int i = m; i >= (2); i--) {
    if (g[1][i] && g[2][i]) modify(1, i, 2, i, 1, i - 1);
    if (g[1][i]) modify(1, i, 1, i - 1, 2, i - 1);
    if (g[2][i]) modify(2, i, 1, i - 1, 2, i - 1);
  }
  if (g[1][1] && g[2][1]) modify(1, 1, 1, 2, 2, 2), modify(1, 2, 2, 1, 2, 2);
  if (g[1][1])
    modify(1, 1, 1, 2, 2, 2), modify(1, 1, 1, 2, 2, 1),
        modify(1, 1, 2, 1, 2, 2);
  if (g[2][1])
    modify(1, 1, 2, 1, 1, 2), modify(1, 1, 2, 1, 2, 2),
        modify(2, 1, 1, 2, 2, 2);
  printf("%d\n", ans1);
  for (int i = 1; i <= (ans1); i++) {
    for (int j = 0; j <= (5); j++) printf("%d ", ans2[i][j]);
    putchar('\n');
  }
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) Main();
}
