#include <bits/stdc++.h>
using namespace std;
int n, m;
char s[110][110];
struct op {
  int x1, y1, x2, y2, x3, y3;
  op(int x1 = 0, int y1 = 0, int x2 = 0, int y2 = 0, int x3 = 0, int y3 = 0)
      : x1(x1), y1(y1), x2(x2), y2(y2), x3(x3), y3(y3) {}
};
vector<op> ans;
void read() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%s", s[i] + 1);
}
void op1(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
  ans.push_back({x1, y1, x2, y2, x4, y4});
  ans.push_back({x1, y1, x3, y3, x4, y4});
  ans.push_back({x1, y1, x2, y2, x3, y3});
}
void op2(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
  ans.push_back({x1, y1, x3, y3, x4, y4});
  ans.push_back({x2, y2, x3, y3, x4, y4});
}
void op3(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
  ans.push_back({x1, y1, x2, y2, x3, y3});
}
void go1(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
  if (s[x1][y1] == '0') {
    if (s[x4][y4] == '1') {
      swap(x1, x4);
      swap(y1, y4);
    } else if (s[x3][y3] == '1') {
      swap(x1, x3);
      swap(y1, y3);
    } else if (s[x2][y2] == '1') {
      swap(x1, x2);
      swap(y1, y2);
    }
  }
  if (s[x2][y2] == '0') {
    if (s[x4][y4] == '1') {
      swap(x2, x4);
      swap(y2, y4);
    } else if (s[x3][y3] == '1') {
      swap(x2, x3);
      swap(y2, y3);
    }
  }
  if (s[x3][y3] == '0') {
    if (s[x4][y4] == '1') {
      swap(x3, x4);
      swap(y3, y4);
    }
  }
  int cnt = (s[x1][y1] == '1') + (s[x2][y2] == '1') + (s[x3][y3] == '1') +
            (s[x4][y4] == '1');
  if (cnt == 1)
    op1(x1, y1, x2, y2, x3, y3, x4, y4);
  else if (cnt == 2)
    op2(x1, y1, x2, y2, x3, y3, x4, y4);
  else if (cnt == 3)
    op3(x1, y1, x2, y2, x3, y3, x4, y4);
  else if (cnt == 4) {
    op3(x1, y1, x2, y2, x3, y3, x4, y4);
    op1(x4, y4, x2, y2, x3, y3, x1, y1);
  }
  s[x1][y1] = s[x2][y2] = s[x3][y3] = s[x4][y4] = '0';
}
void go2(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
  if (s[x1][y1] == '0') {
    if (s[x4][y4] == '1') {
      swap(x1, x4);
      swap(y1, y4);
    } else if (s[x3][y3] == '1') {
      swap(x1, x3);
      swap(y1, y3);
    } else if (s[x2][y2] == '1') {
      swap(x1, x2);
      swap(y1, y2);
    }
  }
  if (s[x2][y2] == '0') {
    if (s[x4][y4] == '1') {
      swap(x2, x4);
      swap(y2, y4);
    } else if (s[x3][y3] == '1') {
      swap(x2, x3);
      swap(y2, y3);
    }
  }
  if (s[x3][y3] == '0') {
    if (s[x4][y4] == '1') {
      swap(x3, x4);
      swap(y3, y4);
    }
  }
  int cnt = (s[x1][y1] == '1') + (s[x2][y2] == '1') + (s[x3][y3] == '1') +
            (s[x4][y4] == '1');
  if (cnt == 1) {
    op3(x1, y1, x2, y2, x3, y3, x4, y4);
    s[x1][y1] ^= 1;
    s[x2][y2] ^= 1;
    s[x3][y3] ^= 1;
  } else if (cnt == 2) {
    op2(x1, y1, x2, y2, x3, y3, x4, y4);
    s[x1][y1] = s[x2][y2] = s[x3][y3] = s[x4][y4] = '0';
  } else if (cnt == 3) {
    op3(x1, y1, x2, y2, x3, y3, x4, y4);
    s[x1][y1] = s[x2][y2] = s[x3][y3] = s[x4][y4] = '0';
  } else if (cnt == 4) {
    op3(x1, y1, x4, y4, x2, y2, x3, y3);
    s[x1][y1] = s[x2][y2] = s[x4][y4] = '0';
  }
}
void work() {
  ans.clear();
  for (int i = 1; i < n; ++i) {
    for (int j = 1; j < m; ++j) {
      if (s[i][j] == '0') continue;
      go2(i, j, i + 1, j, i + 1, j + 1, i, j + 1);
    }
    if (s[i][m] == '1') {
      go2(i, m, i + 1, m, i + 1, m - 1, i, m - 1);
    }
  }
  for (int j = 1; j < m; ++j) {
    if (s[n][j] == '0' && s[n - 1][j] == '0') continue;
    go2(n, j, n, j + 1, n - 1, j + 1, n - 1, j);
  }
  go1(n, m, n - 1, m, n, m - 1, n - 1, m - 1);
  printf("%d\n", (int)ans.size());
  for (auto &it : ans) {
    printf("%d %d %d %d %d %d\n", it.x1, it.y1, it.x2, it.y2, it.x3, it.y3);
  }
}
int main() {
  int T;
  for (scanf("%d", &T); T; --T) {
    read();
    work();
  }
  return 0;
}
