#include <bits/stdc++.h>
using namespace std;
const int MX = 105;
string str[MX];
vector<pair<int, int> > ans;
void process(int x, int y) {
  ans.push_back({x, y});
  if (str[x][y] == '0')
    str[x][y] = '1';
  else if (str[x][y] == '1')
    str[x][y] = '0';
}
int main() {
  int i, j, k;
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    for (i = 0; i < n; ++i) {
      cin >> str[i];
    }
    vector<pair<int, int> > p;
    for (i = 0; i < n - 1; ++i) {
      for (j = 0; j < m; j += 2) {
        p.clear();
        if (str[i][j] == '1') p.push_back({i, j});
        if (j + 1 < m && str[i][j + 1] == '1') p.push_back({i, j + 1});
        if (p.size() < 3) p.push_back({i + 1, j});
        if (j + 1 < m) {
          if (p.size() < 3) p.push_back({i + 1, j + 1});
        } else {
          if (p.size() < 3) p.push_back({i + 1, j - 1});
        }
        if (p.size() != 3) continue;
        for (auto x : p) {
          process(x.first, x.second);
        }
      }
    }
    i = n - 1;
    for (j = 0; j < m; ++j) {
      if (str[i][j] == '0') continue;
      if (j + 1 < m) {
        if (str[i][j + 1] == '0') {
          if (j + 2 < m) {
            process(i, j);
            process(i, j + 1);
            process(i - 1, j + 1);
            process(i, j + 1);
            process(i - 1, j + 1);
            process(i, j + 2);
          } else {
            process(i, j);
            process(i - 1, j);
            process(i, j + 1);
            process(i, j);
            process(i, j + 1);
            process(i - 1, j + 1);
            process(i, j);
            process(i - 1, j);
            process(i - 1, j + 1);
          }
        } else {
          process(i, j);
          process(i - 1, j + 1);
          process(i - 1, j);
          process(i - 1, j);
          process(i - 1, j + 1);
          process(i, j + 1);
        }
      } else {
        process(i, j);
        process(i - 1, j);
        process(i, j - 1);
        process(i, j);
        process(i - 1, j);
        process(i - 1, j - 1);
        process(i, j);
        process(i, j - 1);
        process(i - 1, j - 1);
      }
    }
    int cnt = ans.size();
    printf("%d\n", cnt / 3);
    for (i = 0; i < ans.size(); i += 3) {
      printf("%d %d ", ans[i].first + 1, ans[i].second + 1);
      printf("%d %d ", ans[i + 1].first + 1, ans[i + 1].second + 1);
      printf("%d %d\n", ans[i + 2].first + 1, ans[i + 2].second + 1);
    }
    ans.clear();
  }
}
