#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int maxn = 100 + 10;
const int inf = 0x3f3f3f3f;
int n, m;
char G[maxn][maxn];
struct REC {
  int x1, y1, x2, y2, x3, y3;
};
vector<REC> rec;
void change(int x1, int y1, int x2, int y2, int x3, int y3) {
  G[x1][y1] = !(G[x1][y1] - '0') + '0';
  G[x2][y2] = !(G[x2][y2] - '0') + '0';
  G[x3][y3] = !(G[x3][y3] - '0') + '0';
  rec.push_back({x1, y1, x2, y2, x3, y3});
}
void solve(int x, int y) {
  int sta = 0;
  for (int i = x; i < x + 2; ++i)
    for (int j = y; j < y + 2; ++j)
      sta = sta * 10 + G[i][j] - '0', G[i][j] = '0';
  while (sta != 0) {
    if (sta == 1111) {
      rec.push_back({x, y, x + 1, y, x, y + 1});
      sta = 1;
    } else if (sta == 1) {
      rec.push_back({x, y + 1, x + 1, y, x + 1, y + 1});
      sta = 110;
    } else if (sta == 10) {
      rec.push_back({x, y, x + 1, y, x + 1, y + 1});
      sta = 1001;
    } else if (sta == 100) {
      rec.push_back({x, y + 1, x + 1, y, x + 1, y + 1});
      sta = 11;
    } else if (sta == 1000) {
      rec.push_back({x, y, x + 1, y, x + 1, y + 1});
      sta = 11;
    } else if (sta == 1110) {
      rec.push_back({x, y, x, y + 1, x + 1, y});
      sta = 0;
    } else if (sta == 1101) {
      rec.push_back({x, y, x, y + 1, x + 1, y + 1});
      sta = 0;
    } else if (sta == 1011) {
      rec.push_back({x, y, x + 1, y, x + 1, y + 1});
      sta = 0;
    } else if (sta == 111) {
      rec.push_back({x, y + 1, x + 1, y, x + 1, y + 1});
      sta = 0;
    } else if (sta == 1100) {
      rec.push_back({x, y, x + 1, y, x + 1, y + 1});
      sta = 111;
    } else if (sta == 110) {
      rec.push_back({x, y, x + 1, y, x + 1, y + 1});
      sta = 1101;
    } else if (sta == 11) {
      rec.push_back({x, y, x, y + 1, x + 1, y + 1});
      sta = 1110;
    } else if (sta == 1001) {
      rec.push_back({x, y, x + 1, y, x, y + 1});
      sta = 111;
    } else if (sta == 1010) {
      rec.push_back({x, y, x, y + 1, x + 1, y + 1});
      sta = 111;
    } else if (sta == 101) {
      rec.push_back({x, y, x + 1, y, x + 1, y + 1});
      sta = 1110;
    }
  }
}
int main() {
  int T;
  scanf("%d\n", &T);
  while (T--) {
    scanf("%d%d", &n, &m);
    rec.clear();
    for (int i = 1; i <= n; ++i) scanf("%s", G[i] + 1);
    if (n & 1) {
      if (G[n][1] - '0') change(n, 1, n - 1, 1, n - 1, 2);
      for (int i = 2; i <= m; ++i)
        if (G[n][i] - '0') change(n, i, n - 1, i, n - 1, i - 1);
      --n;
    }
    if (m & 1) {
      if (G[1][m] - '0') change(1, m, 1, m - 1, 2, m - 1);
      for (int i = 2; i <= n; ++i)
        if (G[i][m] - '0') change(i, m, i, m - 1, i - 1, m - 1);
      --m;
    }
    for (int i = 1; i <= n; i += 2)
      for (int j = 1; j <= m; j += 2) solve(i, j);
    printf("%d\n", rec.size());
    for (int i = 0; i < rec.size(); ++i)
      printf("%d %d %d %d %d %d\n", rec[i].x1, rec[i].y1, rec[i].x2, rec[i].y2,
             rec[i].x3, rec[i].y3);
  }
  return 0;
}
