#include <bits/stdc++.h>
using namespace std;
struct Z {
  int x1, __y1__;
  int x2, y2;
  int x3, y3;
};
int T, N, M, B[105][105];
char A[105][105];
vector<Z> ans;
void f(int x, int y) { B[x][y] ^= 1; }
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> T;
  while (T--) {
    ans.clear();
    cin >> N >> M;
    for (int i = 1; i <= N; i++) cin >> (A[i] + 1);
    for (int i = 1; i <= N; i++)
      for (int j = 1; j <= M; j++) {
        if (A[i][j] == '1')
          B[i][j] = 1;
        else if (A[i][j] == '0')
          B[i][j] = 0;
      }
    for (int i = 1; i < N; i++)
      for (int j = 1; j < M; j++) {
        if (j == M - 1) {
          if (!B[i][j + 1] && !B[i][j]) continue;
          if (!B[i][j] && B[i][j + 1]) {
            ans.push_back({i, j + 1, i + 1, j, i + 1, j + 1});
            f(i, j + 1);
            f(i + 1, j);
            f(i + 1, j + 1);
          } else if (B[i][j] && !B[i][j + 1]) {
            ans.push_back({i, j, i + 1, j, i + 1, j + 1});
            f(i, j);
            f(i + 1, j);
            f(i + 1, j + 1);
          } else {
            ans.push_back({i, j, i, j + 1, i + 1, j});
            f(i, j);
            f(i, j + 1);
            f(i + 1, j);
          }
          continue;
        }
        if (i == N - 1) {
          if (B[i][j] && B[i + 1][j]) {
            ans.push_back({i, j, i + 1, j, i + 1, j + 1});
            f(i, j), f(i + 1, j), f(i + 1, j + 1);
          } else if (B[i][j] && !B[i + 1][j]) {
            ans.push_back({i, j, i, j + 1, i + 1, j + 1});
            f(i, j), f(i, j + 1), f(i + 1, j + 1);
          } else if (!B[i][j] && B[i + 1][j]) {
            ans.push_back({i + 1, j, i, j + 1, i + 1, j + 1});
            f(i + 1, j), f(i, j + 1), f(i + 1, j + 1);
          }
          continue;
        }
        if (!B[i][j]) continue;
        if (B[i + 1][j]) {
          ans.push_back({i, j, i + 1, j, i + 1, j + 1});
          f(i, j);
          f(i + 1, j);
          f(i + 1, j + 1);
        } else {
          ans.push_back({i, j, i, j + 1, i + 1, j + 1});
          f(i, j);
          f(i, j + 1);
          f(i + 1, j + 1);
        }
      }
    int bit = ((B[N - 1][M] << 2) + (B[N][M - 1] << 1) + (B[N][M] << 0));
    if (bit == 1) {
      ans.push_back({N - 1, M - 1, N - 1, M, N, M});
      ans.push_back({N, M, N - 1, M, N, M - 1});
      ans.push_back({N - 1, M - 1, N, M - 1, N, M});
    } else if (bit == 2) {
      ans.push_back({N - 1, M - 1, N - 1, M, N, M - 1});
      ans.push_back({N, M, N - 1, M, N, M - 1});
      ans.push_back({N - 1, M - 1, N, M - 1, N, M});
    } else if (bit == 3) {
      ans.push_back({N - 1, M - 1, N - 1, M, N, M});
      ans.push_back({N - 1, M - 1, N, M - 1, N - 1, M});
    } else if (bit == 4) {
      ans.push_back({N - 1, M, N, M - 1, N, M});
      ans.push_back({N - 1, M - 1, N - 1, M, N, M});
      ans.push_back({N - 1, M - 1, N, M - 1, N - 1, M});
    } else if (bit == 5) {
      ans.push_back({N - 1, M - 1, N, M - 1, N, M});
      ans.push_back({N - 1, M - 1, N, M - 1, N - 1, M});
    } else if (bit == 6) {
      ans.push_back({N - 1, M - 1, N - 1, M, N, M});
      ans.push_back({N - 1, M - 1, N, M - 1, N, M});
    } else if (bit == 7) {
      ans.push_back({N - 1, M, N, M - 1, N, M});
    }
    cout << ans.size() << "\n";
    for (auto it : ans)
      cout << it.x1 << " " << it.__y1__ << " " << it.x2 << " " << it.y2 << " "
           << it.x3 << " " << it.y3 << "\n";
  }
}
