#include <bits/stdc++.h>
using namespace std;
struct pt {
  long long x, y;
};
void solveCase() {
  long long n = 0, m = 0;
  cin >> n >> m;
  vector<string> v(n);
  for (long long i = 0; i < n; i++) cin >> v[i];
  auto notperf = [&](long long i, long long j) {
    long long sum = 0;
    for (long long x = i; x < i + 2; x++)
      for (long long y = j; y < j + 2; y++) sum += v[x][y] == '0';
    return sum != 4;
  };
  vector<pt> ans;
  auto transform = [&](long long i, long long j) {
    vector<pt> z, o;
    for (long long x = i; x < i + 2; x++)
      for (long long y = j; y < j + 2; y++)
        if (v[x][y] == '1')
          o.push_back({x, y});
        else
          z.push_back({x, y});
    auto act = [&](pt pos) { ans.push_back(pos), v[pos.x][pos.y] ^= 1; };
    if (o.size() == 3)
      for (auto pos : o) act(pos);
    else if (o.size() == 4)
      for (long long i = 0; i < 3; i++) act(o[i]);
    else if (o.size() == 1) {
      act(o[0]);
      for (long long i = 0; i < 2; i++) act(z[i]);
    } else {
      act(o[0]);
      for (auto pos : z) act(pos);
    }
  };
  for (long long i = 0; i < n; i += 2) {
    if (i == n - 1 && n % 2) i--;
    for (long long j = 0; j < m - (m % 2); j += 2)
      while (notperf(i, j)) transform(i, j);
    if (m % 2)
      while (notperf(i, m - 2)) transform(i, m - 2);
  }
  cout << ans.size() / 3 << '\n';
  for (long long i = 0; i < ans.size(); i += 3) {
    for (long long j = 0; j < 3; j++)
      cout << ans[i + j].x + 1 << ' ' << ans[i + j].y + 1 << ' ';
    cout << '\n';
  }
}
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(NULL);
  long long t = 0;
  cin >> t;
  while (t--) solveCase();
}
