#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
long long int mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
pair<long long int, long long int> fib(long long int n) {
  if (n == 0) return {0, 1};
  auto p = fib(n >> 1);
  long long int c = p.first * (2 * p.second - p.first);
  long long int d = p.first * p.first + p.second * p.second;
  if (n & 1)
    return {d, c + d};
  else
    return {c, d};
}
long long int fact(long long int n) {
  long long int res = 1;
  for (long long int i = n; i >= 1; i--) (res *= i) %= mod;
  return (res % mod);
}
long long int power(long long int a, long long int b, long long int m) {
  long long int ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return ans;
}
bool isPrime(long long n) {
  if (n <= 1) return false;
  for (long long i = 2; i <= sqrt(n); i++)
    if (n % i == 0) return false;
  return true;
}
vector<long long> segmentedSieve(long long L, long long R) {
  long long lim = sqrt(R);
  vector<bool> mark(lim + 1, false);
  vector<long long> primes;
  for (long long i = 2; i <= lim; ++i) {
    if (!mark[i]) {
      primes.emplace_back(i);
      for (long long j = i * i; j <= lim; j += i) mark[j] = true;
    }
  }
  vector<bool> isPrime(R - L + 1, true);
  for (long long i : primes)
    for (long long j = max(i * i, (L + i - 1) / i * i); j <= R; j += i)
      isPrime[j - L] = false;
  if (L == 1) isPrime[0] = false;
  vector<long long> realprime;
  for (long long int i = 0; i <= R - L; i++) {
    if (isPrime[i]) {
      realprime.emplace_back(i + L);
    }
  }
  return realprime;
}
bool isPalindrome(string s) {
  long long int l = 0;
  long long int h = s.size() - 1;
  while (h > l) {
    if (s[l++] != s[h--]) {
      return false;
    }
  }
  return true;
}
long long int ternarySearch(long long int l, long long int r, long long int key,
                            long long int ar[]) {
  while (r >= l) {
    long long int mid1 = l + (r - l) / 3;
    long long int mid2 = r - (r - l) / 3;
    if (ar[mid1] == key) {
      return mid1;
    }
    if (ar[mid2] == key) {
      return mid2;
    }
    if (key < ar[mid1]) {
      r = mid1 - 1;
    } else if (key > ar[mid2]) {
      l = mid2 + 1;
    } else {
      l = mid1 + 1;
      r = mid2 - 1;
    }
  }
  return -1;
}
long long int binarySearch(long long int arr[], long long int l,
                           long long int r, long long int x) {
  while (l <= r) {
    long long int m = l + (r - l) / 2;
    if (arr[m] == x) return m;
    if (arr[m] < x)
      l = m + 1;
    else
      r = m - 1;
  }
  return -1;
}
long long maxsubarraysum(long long *array, long long n) {
  long long best = 0, sum = 0;
  for (long long k = 0; k < n; k++) {
    sum = max(array[k], sum + array[k]);
    best = max(best, sum);
  }
  return best;
}
string findSum(string str1, string str2) {
  if (str1.length() > str2.length()) swap(str1, str2);
  string str = "";
  long long int n1 = str1.length(), n2 = str2.length();
  reverse(str1.begin(), str1.end());
  reverse(str2.begin(), str2.end());
  long long int carry = 0;
  for (long long int i = 0; i < n1; i++) {
    long long int sum = ((str1[i] - '0') + (str2[i] - '0') + carry);
    str.push_back(sum % 10 + '0');
    carry = sum / 10;
  }
  for (long long int i = n1; i < n2; i++) {
    long long int sum = ((str2[i] - '0') + carry);
    str.push_back(sum % 10 + '0');
    carry = sum / 10;
  }
  if (carry) str.push_back(carry + '0');
  reverse(str.begin(), str.end());
  return str;
}
string smin(string a, string b) {
  if (a.size() < b.size()) return a;
  if (a.size() > b.size()) return b;
  if (a <= b)
    return a;
  else
    return b;
}
bool so(const pair<long long int, long long int> &a,
        const pair<long long int, long long int> &b) {
  return (a.second < b.second);
}
long long int setBitNumber(long long int n) {
  n |= n >> 1;
  n |= n >> 2;
  n |= n >> 4;
  n |= n >> 8;
  n |= n >> 16;
  n = n + 1;
  return (n >> 1);
}
bool CompareVector(vector<string> first, vector<string> second) {
  if (first[0] < second[0]) return true;
  if (first[1] < second[1]) return true;
  if (first[2] < second[2]) return true;
  return false;
}
unsigned countBits(unsigned long long int number) {
  return (long long int)log2(number) + 1;
}
long long int mul(long long int a, long long int b) { return (a * b) % mod; }
void addmod(long long int &a, long long int b) {
  a += b;
  if (a >= mod) {
    a -= mod;
  }
}
long long int myXOR(long long int x, long long int y) {
  long long int res = 0;
  for (long long int i = 31; i >= 0; i--) {
    bool b1 = x & (1 << i);
    bool b2 = y & (1 << i);
    bool xoredBit = (b1 & b2) ? 0 : (b1 | b2);
    res <<= 1;
    res |= xoredBit;
  }
  return res;
}
long long int nCr(long long int n, long long int r) {
  return (fact(n)) / (fact(r) * fact(n - r));
}
vector<long long int> v[100005];
pair<long long int, long long int> dfs(long long int node) {
  long long int mex = 0;
  long long int size = 1;
  for (long long int u : v[node]) {
    auto temp = dfs(u);
    mex = max(mex, temp.first);
    size += temp.second;
  }
  return {mex + size, size};
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, m;
    cin >> n >> m;
    char b[n + 1][m + 1];
    long long int a[n + 1][m + 1];
    for (long long int i = 1; i <= n; i++) {
      for (long long int j = 1; j <= m; j++) {
        cin >> b[i][j];
        a[i][j] = b[i][j] - '0';
      }
    }
    vector<pair<long long int, long long int>> v;
    for (long long int i = 1; i < n; i++) {
      for (long long int j = 1; j <= m; j++) {
        if (a[i][j] == 1 && j < m) {
          v.push_back({i, j});
          v.push_back({i + 1, j});
          v.push_back({i + 1, j + 1});
          a[i][j] = 0;
          a[i + 1][j] = (a[i + 1][j]) ^ 1;
          a[i + 1][j + 1] = a[i + 1][j + 1] ^ 1;
        }
        if (a[i][j] == 1 && j == m) {
          v.push_back({i, j});
          v.push_back({i + 1, j});
          v.push_back({i + 1, j - 1});
          a[i][j] = 0;
          a[i + 1][j] = a[i + 1][j] ^ 1;
          a[i + 1][j - 1] = a[i + 1][j - 1] ^ 1;
        }
      }
    }
    for (long long int j = 1; j < m; j++) {
      if (a[n][j] == 1) {
        v.push_back({n, j});
        v.push_back({n - 1, j});
        v.push_back({n - 1, j + 1});
        v.push_back({n, j + 1});
        v.push_back({n - 1, j});
        v.push_back({n - 1, j + 1});
        a[n][j] = 0;
        a[n - 1][j] = a[n - 1][j] ^ 1;
        a[n - 1][j + 1] = a[n - 1][j + 1] ^ 1;
        a[n][j + 1] = a[n][j + 1] ^ 1;
        a[n - 1][j] = a[n - 1][j] ^ 1;
        a[n - 1][j + 1] = a[n - 1][j + 1] ^ 1;
      }
    }
    if (a[n][m] == 1) {
      v.push_back({n, m});
      v.push_back({n - 1, m});
      v.push_back({n - 1, m - 1});
      v.push_back({n - 1, m - 1});
      v.push_back({n, m - 1});
      v.push_back({n, m});
      v.push_back({n, m - 1});
      v.push_back({n, m});
      v.push_back({n - 1, m});
      a[n][m] = 0;
      a[n - 1][m] = a[n - 1][m] ^ 1;
      a[n - 1][m - 1] = a[n - 1][m - 1] ^ 1;
      a[n - 1][m - 1] = a[n - 1][m - 1] ^ 1;
      a[n][m - 1] = a[n][m - 1] ^ 1;
      a[n][m] = a[n][m] ^ 1;
      a[n][m - 1] = a[n][m - 1] ^ 1;
      a[n][m] = a[n][m] ^ 1;
      a[n - 1][m] = a[n - 1][m] ^ 1;
    }
    cout << v.size() / 3 << "\n";
    long long int c = 0;
    for (long long int i = 0; i < v.size(); i++) {
      cout << v[i].first << " " << v[i].second << " ";
      c++;
      if (c == 3) {
        cout << "\n";
        c = 0;
      }
    }
  }
  return 0;
}
