#include <bits/stdc++.h>
using namespace std;
int n, m;
char g[105][105];
int op[105][105][4];
vector<pair<int, int>> getop(int x, int y, int t) {
  vector<pair<int, int>> ans;
  ans.push_back({x, y});
  ans.push_back({x + 1, y});
  if (t == 0) {
    ans.push_back({x, y + 1});
  } else if (t == 1) {
    ans.push_back({x + 1, y - 1});
  } else if (t == 2) {
    ans.push_back({x, y - 1});
  } else if (t == 3) {
    ans.push_back({x + 1, y + 1});
  }
  return ans;
}
void performop(int x, int y, int t) {
  op[x][y][t] = 1 - op[x][y][t];
  vector<pair<int, int>> ind = getop(x, y, t);
  for (auto it : ind) {
    g[it.first][it.second] = '0' + '1' - g[it.first][it.second];
  }
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++) {
      scanf("%s", g[i]);
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        op[i][j][0] = op[i][j][1] = op[i][j][2] = op[i][j][3] = 0;
      }
    }
    for (int i = 0; i < n - 1; i++) {
      for (int j = 0; j < m - 1; j++) {
        if (g[i][j] == '1') performop(i, j, 0);
      }
      if (g[i][m - 1] == '1') performop(i, m - 1, 1);
    }
    for (int j = 0; j < m - 2; j++) {
      if (g[n - 1][j] == '1') {
        performop(n - 2, j, 0);
        performop(n - 2, j + 1, 2);
      }
    }
    if (g[n - 1][m - 2] == '1' && g[n - 1][m - 1] == '1') {
      performop(n - 2, m - 2, 0);
      performop(n - 2, m - 1, 2);
    } else if (g[n - 1][m - 2] == '1' && g[n - 1][m - 1] == '0') {
      performop(n - 2, m - 1, 1);
      performop(n - 2, m - 2, 0);
      performop(n - 2, m - 2, 3);
    } else if (g[n - 1][m - 2] == '0' && g[n - 1][m - 1] == '1') {
      performop(n - 2, m - 1, 2);
      performop(n - 2, m - 2, 3);
      performop(n - 2, m - 1, 1);
    }
    vector<vector<pair<int, int>>> ans;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        for (int k = 0; k < 4; k++) {
          if (op[i][j][k]) {
            ans.push_back(getop(i, j, k));
          }
        }
      }
    }
    printf("%d\n", (int)ans.size());
    for (auto it : ans) {
      for (auto jt : it) {
        printf("%d %d ", jt.first + 1, jt.second + 1);
      }
      printf("\n");
    }
  }
  return 0;
}
