#include <bits/stdc++.h>
using namespace std;
void rotate(vector<vector<int>> &a) {
  int tmp = a[0][1];
  a[0][1] = a[1][0];
  a[1][0] = tmp;
  tmp = a[0][0];
  a[0][0] = a[0][1];
  a[0][1] = tmp;
  tmp = a[1][0];
  a[1][0] = a[1][1];
  a[1][1] = tmp;
  return;
}
void solve(int n, int m, vector<vector<int>> &a) {
  vector<vector<int>> ops;
  for (int i = 0; i < n - 1; i++) {
    for (int j = 0; j < m - 1; j++) {
      vector<vector<int>> orient = {{1, 1}, {1, 0}};
      int count = a[i][j] + a[i][j + 1] + a[i + 1][j] + a[i + 1][j + 1];
      while (count) {
        if (count == 3) {
          if (a[i][j] == 1 and a[i][j + 1] == 1 and a[i + 1][j] == 1) {
            a[i][j] ^= 1;
            a[i][j + 1] ^= 1;
            a[i + 1][j] ^= 1;
            ops.push_back({i, j, i, j + 1, i + 1, j});
          } else if (a[i + 1][j] == 1 and a[i][j] == 1 and
                     a[i + 1][j + 1] == 1) {
            a[i + 1][j] ^= 1;
            a[i][j] ^= 1;
            a[i + 1][j + 1] ^= 1;
            ops.push_back({i + 1, j, i, j, i + 1, j + 1});
          } else if (a[i + 1][j + 1] == 1 and a[i + 1][j] == 1 and
                     a[i][j + 1] == 1) {
            a[i + 1][j + 1] ^= 1;
            a[i + 1][j] ^= 1;
            a[i][j + 1] ^= 1;
            ops.push_back({i + 1, j + 1, i + 1, j, i, j + 1});
          } else {
            a[i][j + 1] ^= 1;
            a[i][j] ^= 1;
            a[i + 1][j + 1] ^= 1;
            ops.push_back({i, j + 1, i, j, i + 1, j + 1});
          }
          break;
        }
        ops.push_back({});
        if (orient[0][0]) {
          a[i][j] ^= 1;
          ops.back().push_back(i);
          ops.back().push_back(j);
        }
        if (orient[0][1]) {
          a[i][j + 1] ^= 1;
          ops.back().push_back(i);
          ops.back().push_back(j + 1);
        }
        if (orient[1][0]) {
          a[i + 1][j] ^= 1;
          ops.back().push_back(i + 1);
          ops.back().push_back(j);
        }
        if (orient[1][1]) {
          a[i + 1][j + 1] ^= 1;
          ops.back().push_back(i + 1);
          ops.back().push_back(j + 1);
        }
        rotate(orient);
        count = a[i][j] + a[i][j + 1] + a[i + 1][j] + a[i + 1][j + 1];
      }
    }
  }
  cout << ops.size() << endl;
  for (auto x : ops) {
    for (auto y : x) {
      cout << y + 1 << " ";
    }
    cout << endl;
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> a(n, vector<int>(m, 0));
    for (int i = 0; i < n; i++) {
      string s;
      cin >> s;
      for (int j = 0; j < m; j++) {
        a[i][j] = stoi(string(1, s[j]));
      }
    }
    solve(n, m, a);
  }
  return 0;
}
