#include <bits/stdc++.h>
using namespace std;
int n, m;
char ch[101][101];
void check(vector<pair<int, int>> &v, int i, int j, int a, int b, int x,
           int y) {
  v.push_back({i + 1, j + 1});
  v.push_back({a + 1, b + 1});
  v.push_back({x + 1, y + 1});
  ch[i][j] = '0';
  if (ch[a][b] == '1')
    ch[a][b] = '0';
  else
    ch[a][b] = '1';
  if (ch[x][y] == '1')
    ch[x][y] = '0';
  else
    ch[x][y] = '1';
}
void solve() {
  vector<pair<int, int>> v;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> ch[i][j];
  }
  for (int i = 0; i < n - 2; i++) {
    for (int j = 0; j < m; j++) {
      if (j == m - 1 && ch[i][j] == '1')
        check(v, i, j, i + 1, j, i + 1, j - 1);
      else if (ch[i][j] == '1')
        check(v, i, j, i + 1, j, i + 1, j + 1);
    }
  }
  for (int j = 0; j < m - 1; j++) {
    int i = n - 2;
    if (ch[i][j] == '1') check(v, i, j, i, j + 1, i + 1, j + 1);
    i++;
    if (ch[i][j] == '1') check(v, i, j, i, j + 1, i - 1, j + 1);
  }
  int i = n - 2, j = m - 1;
  if (ch[i][j] == '1' && ch[i + 1][j] == '1') {
    check(v, i, j - 1, i + 1, j - 1, i + 1, j);
    check(v, i, j - 1, i + 1, j - 1, i, j);
  }
  if (ch[i][j] == '1') {
    check(v, i, j, i, j - 1, i + 1, j);
    check(v, i, j, i + 1, j, i + 1, j - 1);
    check(v, i, j, i, j - 1, i + 1, j - 1);
  }
  i++;
  if (ch[i][j] == '1') {
    check(v, i, j, i - 1, j, i - 1, j - 1);
    check(v, i, j, i - 1, j, i, j - 1);
    check(v, i, j, i, j - 1, i - 1, j - 1);
  }
  int ff = v.size();
  cout << ff / 3 << "\n";
  for (int i = 0; i < ff; i += 3) {
    cout << v[i].first << " " << v[i].second << " " << v[i + 1].first << " "
         << v[i + 1].second << " " << v[i + 2].first << " " << v[i + 2].second
         << "\n";
  }
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int tt = 1;
  cin >> tt;
  while (tt--) solve();
}
