#include <bits/stdc++.h>
using namespace std;
int t, n, k, m, tot;
vector<int> ax;
vector<int> ay;
char a[110][110];
int check(int x, int y) {
  int sum = 0;
  for (int i = x; i <= x + 1; i++) {
    for (int j = y; j <= y + 1; j++) {
      if (a[i][j] == '0') sum++;
    }
  }
  return sum;
}
void check1(int x, int y) {
  for (int i = x; i <= x + 1; i++) {
    for (int j = y; j <= y + 1; j++) {
      if (a[i][j] == '1') {
        ax.push_back(i);
        ay.push_back(j);
        a[i][j] = '0';
      }
    }
  }
}
void check2(int x, int y) {
  int flag = 1;
  for (int i = x; i <= x + 1; i++) {
    for (int j = y; j <= y + 1; j++) {
      if (a[i][j] == '0' || a[i][j] == '1' && flag) {
        if (a[i][j] == '1') flag--;
        ax.push_back(i);
        ay.push_back(j);
        if (a[i][j] == '0')
          a[i][j] = '1';
        else
          a[i][j] = '0';
      }
    }
  }
  check1(x, y);
}
void check3(int x, int y) {
  int flag = 2;
  for (int i = x; i <= x + 1; i++) {
    for (int j = y; j <= y + 1; j++) {
      if (flag && a[i][j] == '0' || a[i][j] == '1') {
        if (a[i][j] == '0') flag--;
        ax.push_back(i);
        ay.push_back(j);
        if (a[i][j] == '0')
          a[i][j] = '1';
        else
          a[i][j] = '0';
      }
    }
  }
  check2(x, y);
}
void check0(int x, int y) {
  int flag = 3;
  for (int i = x; i <= x + 1; i++) {
    for (int j = y; j <= y + 1; j++) {
      if (flag) {
        flag--;
        ax.push_back(i);
        ay.push_back(j);
        a[i][j] = '0';
      }
    }
  }
  check3(x, y);
}
int main() {
  cin >> t;
  while (t--) {
    ax.clear();
    ay.clear();
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) cin >> a[i][j];
    if (n & 1) {
      for (int j = 1; j <= m - 1; j += 2) {
        int sum = check(n - 1, j);
        if (sum == 4)
          continue;
        else if (sum == 3)
          check3(n - 1, j);
        else if (sum == 2)
          check2(n - 1, j);
        else if (sum == 1)
          check1(n - 1, j);
        else if (sum == 0)
          check0(n - 1, j);
      }
    }
    if (m & 1) {
      for (int i = 1; i <= n - 1; i += 2) {
        int sum = check(i, m - 1);
        if (sum == 4)
          continue;
        else if (sum == 3)
          check3(i, m - 1);
        else if (sum == 2)
          check2(i, m - 1);
        else if (sum == 1)
          check1(i, m - 1);
        else if (sum == 0)
          check0(i, m - 1);
      }
    }
    for (int i = 1; i <= n - 1; i += 2) {
      for (int j = 1; j <= m - 1; j += 2) {
        int sum = check(i, j);
        if (sum == 4)
          continue;
        else if (sum == 3)
          check3(i, j);
        else if (sum == 2)
          check2(i, j);
        else if (sum == 1)
          check1(i, j);
        else if (sum == 0)
          check0(i, j);
      }
    }
    for (int i = 1; i <= n - 1; i++) {
      for (int j = 1; j <= m - 1; j++) {
        int sum = check(i, j);
        if (sum == 4)
          continue;
        else if (sum == 3)
          check3(i, j);
        else if (sum == 2)
          check2(i, j);
        else if (sum == 1)
          check1(i, j);
        else if (sum == 0)
          check0(i, j);
      }
    }
    int len = ax.size();
    cout << len / 3 << endl;
    for (int i = 0; i < len; i += 3) {
      cout << ax[i] << ' ' << ay[i] << ' ' << ax[i + 1] << ' ' << ay[i + 1]
           << ' ' << ax[i + 2] << ' ' << ay[i + 2] << ' ' << endl;
    }
  }
  return 0;
}
