#include <bits/stdc++.h>
using namespace std;
int a[101][101];
void rev(int x, int y) { a[x][y] ^= 1; }
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    vector<pair<int, int>> ans;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) {
        char x;
        cin >> x;
        a[i][j] = x - '0';
      }
    for (int i = 1; i < n - 1; i++) {
      for (int j = 1; j < m; j++) {
        if (a[i][j] && !a[i][j + 1]) {
          ans.push_back(make_pair(i, j));
          ans.push_back(make_pair(i + 1, j));
          ans.push_back(make_pair(i + 1, j + 1));
          rev(i, j);
          rev(i + 1, j);
          rev(i + 1, j + 1);
        } else if (!a[i][j] && a[i][j + 1]) {
          ans.push_back(make_pair(i, j + 1));
          ans.push_back(make_pair(i + 1, j));
          ans.push_back(make_pair(i + 1, j + 1));
          rev(i, j + 1);
          rev(i + 1, j);
          rev(i + 1, j + 1);
        } else if (!a[i][j] && !a[i][j + 1]) {
          continue;
        } else {
          ans.push_back(make_pair(i, j));
          ans.push_back(make_pair(i, j + 1));
          ans.push_back(make_pair(i + 1, j));
          rev(i, j + 1);
          rev(i, j);
          rev(i + 1, j);
        }
      }
    }
    for (int i = n - 1; i < n; i++) {
      for (int j = 1; j < m - 1; j++) {
        if (a[i][j] && !a[i + 1][j]) {
          ans.push_back(make_pair(i, j));
          ans.push_back(make_pair(i, j + 1));
          ans.push_back(make_pair(i + 1, j + 1));
          rev(i, j);
          rev(i, j + 1);
          rev(i + 1, j + 1);
        } else if (!a[i][j] && a[i + 1][j]) {
          ans.push_back(make_pair(i, j + 1));
          ans.push_back(make_pair(i + 1, j));
          ans.push_back(make_pair(i + 1, j + 1));
          rev(i, j + 1);
          rev(i + 1, j);
          rev(i + 1, j + 1);
        } else if (!a[i][j] && !a[i + 1][j]) {
          continue;
        } else {
          ans.push_back(make_pair(i, j));
          ans.push_back(make_pair(i, j + 1));
          ans.push_back(make_pair(i + 1, j));
          rev(i, j + 1);
          rev(i, j);
          rev(i + 1, j);
        }
      }
    }
    vector<pair<int, int>> free;
    vector<pair<int, int>> Notfree;
    for (int i = n - 1; i <= n; i++)
      for (int j = m - 1; j <= m; j++) {
        if (a[i][j]) {
          Notfree.push_back(make_pair(i, j));
        } else {
          free.push_back(make_pair(i, j));
        }
      }
    if (Notfree.size() == 4) {
      for (int i = 0; i < 3; i++) {
        pair<int, int> j = Notfree[i];
        ans.push_back(j);
        free.push_back(j);
        rev(j.first, j.second);
      }
      Notfree.erase(Notfree.begin(), Notfree.begin() + 3);
    }
    if (Notfree.size() == 1) {
      free.push_back(Notfree[0]);
      ans.push_back(Notfree[0]);
      ans.push_back(free[0]);
      ans.push_back(free[1]);
      Notfree.erase(Notfree.begin(), Notfree.end());
      Notfree.push_back(free[0]);
      Notfree.push_back(free[1]);
      free.erase(free.begin(), free.begin() + 2);
    }
    if (Notfree.size() == 2) {
      ans.push_back(Notfree[0]);
      ans.push_back(free[0]);
      ans.push_back(free[1]);
      Notfree.push_back(free[0]);
      Notfree.push_back(free[1]);
      free.push_back(Notfree[0]);
      Notfree.erase(Notfree.begin(), Notfree.begin() + 1);
      free.erase(free.begin(), free.begin() + 2);
    }
    if (Notfree.size() == 3) {
      ans.push_back(Notfree[0]);
      ans.push_back(Notfree[1]);
      ans.push_back(Notfree[2]);
    }
    cout << ans.size() / 3 << endl;
    for (int i = 0; i < ans.size(); i += 3) {
      cout << ans[i].first << ' ' << ans[i].second << ' ' << ans[i + 1].first
           << ' ' << ans[i + 1].second << ' ' << ans[i + 2].first << ' '
           << ans[i + 2].second << endl;
    }
  }
}
