#include <bits/stdc++.h>
using namespace std;
int t, n, m;
vector<string> grid;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> t;
  while (t--) {
    cin >> n >> m;
    grid = vector<string>(n);
    for (int i = 0; i < (n); i++) cin >> grid[i];
    vector<string> res;
    for (int i = 0; i < (n - 1); i++)
      for (int j = 0; j < (m); j++) {
        if (grid[i][j] == '0') continue;
        grid[i][j] = '0';
        grid[i + 1][j] = grid[i + 1][j] == '0' ? '1' : '0';
        string move = to_string(i + 1) + " " + to_string(j + 1) + " " +
                      to_string(i + 2) + " " + to_string(j + 1);
        if (j < m - 1) {
          grid[i + 1][j + 1] = grid[i + 1][j + 1] == '0' ? '1' : '0';
          move += " " + to_string(i + 2) + " " + to_string(j + 2);
        } else {
          grid[i + 1][j - 1] = grid[i + 1][j - 1] == '0' ? '1' : '0';
          move += " " + to_string(i + 2) + " " + to_string(j);
        }
        res.emplace_back(move);
      }
    for (int j = 0; j < (m - 1); j++) {
      if (grid[n - 1][j] == '0') continue;
      grid[n - 1][j] = '0';
      grid[n - 1][j + 1] = grid[n - 1][j + 1] == '0' ? '1' : '0';
      string move = to_string(n - 1) + " " + to_string(j + 1) + " " +
                    to_string(n - 1) + " " + to_string(j + 2);
      res.emplace_back(to_string(n) + " " + to_string(j + 1) + " " + move);
      res.emplace_back(to_string(n) + " " + to_string(j + 2) + " " + move);
    }
    if (grid[n - 1][m - 1] == '1') {
      string one = to_string(n - 1) + " " + to_string(m - 1);
      string two = to_string(n - 1) + " " + to_string(m);
      string three = to_string(n) + " " + to_string(m - 1);
      string four = to_string(n) + " " + to_string(m);
      res.emplace_back(two + " " + three + " " + four);
      res.emplace_back(one + " " + three + " " + four);
      res.emplace_back(one + " " + two + " " + four);
    }
    cout << (int)(res).size() << '\n';
    for (int i = 0; i < ((int)(res).size()); i++) cout << res[i] << '\n';
  }
  return 0;
}
