因为操作次数最多有 $nm$ 次,所以可以考虑对每个点操作一次,$0$ 的点不需要操作,剩下的只有 $1$ 的点,为了尽量缩小一次操作影响的范围,可以只考虑比较小的棋盘,大小分别为横向的 $1 \times 2$ 和纵向的 $2 \times 1$。为了不覆盖之前的结果,可以考虑从右下角开始构造,先考虑最后一行,从右往左扫描,遇到 $1$ 就构造一个 $1 \times 2$ 的矩形,这个棋盘就是 $[0, 1]$,遇到 $0$ 就跳过。当遇到第一列的 $1$,需要构造 $2 \times 1$ 的矩形:${0\brack 1}$,只有一种情况可以判定无解:当在第一行并且纵向的矩形无法构造。

// Date: Tue Dec 12 21:38:26 2023

#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;
const double eps = 1e-8;
const int dir[8][2] = {
    {0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1},
};

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<int, int> PII;

const ull Pr = 131;

#define For(i, a, b) for (int i = int(a); i < int(b); ++i)
#define Rof(i, a, b) for (int i = int(b) - 1; i >= int(a); --i)
#define For1(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define Rof1(i, a, b) for (int i = int(b); i >= int(a); --i)
#define ForE(i, j) for (int i = h[j]; i != -1; i = ne[i])

#define f1 first
#define f2 second
#define pb push_back
#define has(a, x) (a.find(x) != a.end())
#define nonempty(a) (!a.empty())
#define all(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())

#ifdef _DEBUG
#define debug1(x) cout << #x " = " << x << endl;
#define debug2(x, y) cout << #x " = " << x << " " #y " = " << y << endl;
#define debug3(x, y, z)                                                        \
  cout << #x " = " << x << " " #y " = " << y << " " #z " = " << z << endl;
#else
#define debug1
#define debug2
#define debug3
#endif

const int N = 110;
int t, n, m;
char a[N][N], b[N][N];

struct point {
  PII p1, p2;
  point(int x1, int y1, int x2, int y2) : p1({x1, y1}), p2({x2, y2}) {}
  void print() {
    cout << p1.f1 + 1 << ' ' << p1.f2 + 1 << ' ' << p2.f1 + 1 << ' '
         << p2.f2 + 1;
  }
};

int main(void) {
#ifdef _DEBUG
  freopen("1647c.in", "r", stdin);
#endif
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  cin >> t;

  while (t--) {
    cin >> n >> m;
    memset(b, 0, sizeof b);

    For(i, 0, n) { cin >> a[i]; }

    bool flag = true;
    vector<point> res;

    Rof(i, 0, n) {
      if (!flag)
        break;

      Rof(j, 0, m) {
        if (a[i][j] != '0') {
          if (!j) {
            if (!i) {
              flag = false;
              break;
            }
            b[i - 1][j] = '0';
            res.pb(point(i - 1, j, i, j));
          } else {
            b[i][j - 1] = '0';
            res.pb(point(i, j - 1, i, j));
          }
        }
        b[i][j] = a[i][j];
      }
    }

    if (!flag) {
      cout << "-1\n";
      continue;
    }

    int len = SZ(res);
    cout << len << '\n';
    if (len) {
      For(i, 0, len) {
        res[i].print();
        cout << '\n';
      }
    }
  }

  return 0;
}