#include <bits/stdc++.h>
using namespace std;
inline void p(vector<long long int> x, int n) {
  int i;
  for (i = 0; i < n; i++) cout << x[i] << " ";
  cout << "\n";
}
void rev(char &a) {
  if (a == '1')
    a = '0';
  else {
    a = '1';
  }
}
void solve() {
  long long int M, K, k, i, j, tot = 0, ro = 0, re = 0, bo = 0, be = 0;
  long long int N, f = 0, mx;
  cin >> N >> K;
  string second[N];
  for (i = 0; i < N; i++) cin >> second[i];
  vector<vector<long long int>> ans;
  for (i = 0; i < N - 1; i++) {
    for (j = 0; j < K; j++) {
      if (second[i][j] == '1' && j != K - 1) {
        vector<long long int> x;
        rev(second[i][j]);
        rev(second[i][j + 1]);
        rev(second[i + 1][j]);
        x.push_back(i + 1);
        x.push_back(j + 1);
        x.push_back(i + 1);
        x.push_back(j + 2);
        x.push_back(i + 2);
        x.push_back(j + 1);
        ans.push_back(x);
      } else if (second[i][j] == '1') {
        vector<long long int> x;
        rev(second[i][j]);
        rev(second[i + 1][j]);
        rev(second[i + 1][j - 1]);
        x.push_back(i + 1);
        x.push_back(j + 1);
        x.push_back(i + 2);
        x.push_back(j + 1);
        x.push_back(i + 2);
        x.push_back(j);
        ans.push_back(x);
      }
    }
  }
  for (j = 0; j < K - 1; j++) {
    if (second[N - 1][j] == '1' && second[N - 1][j + 1] == '1') {
      vector<long long int> x, y;
      rev(second[N - 1][j]);
      rev(second[N - 2][j]);
      rev(second[N - 2][j + 1]);
      x.push_back(N);
      x.push_back(j + 1);
      x.push_back(N - 1);
      x.push_back(j + 1);
      x.push_back(N - 1);
      x.push_back(j + 2);
      ans.push_back(x);
      rev(second[N - 1][j + 1]);
      rev(second[N - 2][j]);
      rev(second[N - 2][j + 1]);
      y.push_back(N);
      y.push_back(j + 2);
      y.push_back(N - 1);
      y.push_back(j + 1);
      y.push_back(N - 1);
      y.push_back(j + 2);
      ans.push_back(y);
    } else if ((second[N - 1][j] == '1') && (second[N - 1][j + 1] != '1')) {
      vector<long long int> x, y, z;
      rev(second[N - 1][j]);
      rev(second[N - 2][j]);
      rev(second[N - 2][j + 1]);
      x.push_back(N);
      x.push_back(j + 1);
      x.push_back(N - 1);
      x.push_back(j + 1);
      x.push_back(N - 1);
      x.push_back(j + 2);
      ans.push_back(x);
      rev(second[N - 2][j + 1]);
      rev(second[N - 1][j]);
      rev(second[N - 1][j + 1]);
      y.push_back(N - 1);
      y.push_back(j + 2);
      y.push_back(N);
      y.push_back(j + 1);
      y.push_back(N);
      y.push_back(j + 2);
      ans.push_back(y);
      rev(second[N - 2][j]);
      rev(second[N - 1][j]);
      rev(second[N - 1][j + 1]);
      z.push_back(N - 1);
      z.push_back(j + 1);
      z.push_back(N);
      z.push_back(j + 1);
      z.push_back(N);
      z.push_back(j + 2);
      ans.push_back(z);
    }
  }
  if (second[N - 1][K - 1] == '1') {
    vector<long long int> x, y, z;
    rev(second[N - 1][K - 1]);
    rev(second[N - 2][K - 1]);
    rev(second[N - 2][K - 2]);
    x.push_back(N);
    x.push_back(K);
    x.push_back(N - 1);
    x.push_back(K);
    x.push_back(N - 1);
    x.push_back(K - 1);
    ans.push_back(x);
    rev(second[N - 2][K - 2]);
    rev(second[N - 1][K - 2]);
    rev(second[N - 1][K - 1]);
    y.push_back(N - 1);
    y.push_back(K - 1);
    y.push_back(N);
    y.push_back(K - 1);
    y.push_back(N);
    y.push_back(K);
    ans.push_back(y);
    rev(second[N - 1][K - 1]);
    rev(second[N - 1][K - 2]);
    rev(second[N - 2][K - 1]);
    z.push_back(N);
    z.push_back(K);
    z.push_back(N);
    z.push_back(K - 1);
    z.push_back(N - 1);
    z.push_back(K);
    ans.push_back(z);
  }
  cout << ans.size() << "\n";
  for (i = 0; i < ans.size(); i++) {
    p(ans[i], 6);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1, c = 1;
  cin >> t;
  while (t--) {
    solve();
    cout << "\n";
  }
  return 0;
}
