n,v=map(int,raw_input().split())

sellers=[]

for i in range(n):
    inputs=raw_input().split()
    k=int(inputs[0])
    for j in inputs[1:]:
        if v>int(j):
            print j
            sellers.append(i+1)
            break

sellers.sort()
sellers_list=''

for i in sellers:
    sellers_list += str(i) + ' '

print len(sellers)
print sellers_list


def solve():
    line = raw_input().split(" ")
    n = int(line[0])
    v = int(line[1])
    sellers = [-1]*n
    for i in xrange(n):
        temp = []
        line = raw_input().split(" ")
        q = int(line[0])
        for j in xrange(1, q+1):
            temp.append(int(line[j]))
        cheap = min(temp)
        sellers[i] = cheap
    ans = []
    for num, c in zip(xrange(n), sellers):
        if c <= v:
            ans.append(num)

    for a in ans:
        print(a+1),

if __name__ == "__main__":
    solve()


def solve():
    line = raw_input().split(" ")
    n = int(line[0])
    v = int(line[1])
    sellers = [-1]*n
    for i in xrange(n):
        temp = []
        line = raw_input().split(" ")
        q = int(line[0])
        for j in xrange(1, q+1):
            temp.append(int(line[j]))
        cheap = min(temp)
        sellers[i] = cheap
    ans = []
    for num, c in zip(xrange(n), sellers):
        if c < v:
            ans.append(num)
    print(len(ans))
    for a in ans:
        print(a+1),

if __name__ == "__main__":
    solve()


def solve():
    line = raw_input().split(" ")
    n = int(line[0])
    v = int(line[1])
    sellers = [-1]*n
    for i in xrange(n):
        temp = []
        line = raw_input().split(" ")
        q = int(line[0])
        for j in xrange(1, q+1):
            temp.append(int(line[j]))
        cheap = min(temp)
        sellers[i] = cheap
    ans = []
    for num, c in zip(xrange(n), sellers):
        if c <= v:
            ans.append(num)
    print(len(ans))
    for a in ans:
        print(a+1),

if __name__ == "__main__":
    solve()


r = raw_input()
l = r.split(' ')
n = int(l[0])
v = int(l[1])
lists = []
for a in range(0,n):
	q = raw_input()
	l_1 = q.split(' ')
	p = l_1.pop(0)
	l_1 = [int(i) for i in l_1]
	l_1.sort()
	if l_1[0]<v:
		lists.append(p)
lists = [int(i) for i in lists]
lists.sort()
lists = [str(i) for i in lists]
print len(lists)
print ' '.join(lists)


r = raw_input()
l = r.split(' ')
n = int(l[0])
v = int(l[1])
lists = []
for a in range(0,n):
	q = raw_input()
	l_1 = q.split(' ')
	p = l_1.pop(0)
	l_1 = [int(i) for i in l_1]
	l_1.sort()
	if l_1[0]<v:
		lists.append(a+1)
lists = [int(i) for i in lists]
lists.sort()
lists = [str(i) for i in lists]
print len(lists)
print ' '.join(lists)


n, v = map(int, raw_input().split())
l = []
for i in range(n):
  if any(x < v for x in map(int, raw_input().split())[1:]):
    l.append(str(i + 1))
print len(l)
print ' '.join(l)


n, v = map(int, raw_input().split())
l = []
for i in range(n):
  if any(x < v for x in map(int, raw_input().split())):
    l.append(str(i + 1))
print len(l)
print ' '.join(l)


def main():
    n, m = map(int, raw_input().split())
    res = []
    for i in range(n):
        k = map(int, raw_input().split())
        min_ = min(k[1:])
        if m > min_:
            res.append(i+1)
    print len(res)
    print ' '.join(map(str,(res)))

main()


def main():
    n, m = map(int, raw_input().split())
    res = []
    for i in range(n):
        k = map(int, raw_input().split())
        min_ = min(k)
        if m > min_:
            res.append(i+1)
    print len(res)
    print ' '.join(map(str,(res)))

main()


firstline = raw_input().split(' ')
firstline = [int(i) for i in firstline]

numsellers = firstline[0]
money = firstline[1]
selleryes = []

for i in range(numsellers):
    nextline = raw_input().split(' ')
    nextline = [int(j) for j in nextline]
    for j in range(1, nextline[0] + 1):
        if nextline[j] <= money:
            selleryes.append(i + 1)
            break

selleryes.sort()

print len(selleryes)
nums = ""
for i in selleryes:
    nums += str(i) + " "
print nums


firstline = raw_input().split(' ')
firstline = [int(i) for i in firstline]

numsellers = firstline[0]
money = firstline[1]
selleryes = []

for i in range(numsellers):
    nextline = raw_input().split(' ')
    nextline = [int(j) for j in nextline]
    for j in range(1, nextline[0]):
        if nextline[j] <= money:
            selleryes.append(i + 1)
            break

selleryes.sort()

print len(selleryes)
nums = ""
for i in selleryes:
    nums += str(i) + " "
print nums


firstline = raw_input().split(' ')
firstline = [int(i) for i in firstline]

numsellers = firstline[0]
money = firstline[1]
selleryes = []

for i in range(numsellers):
    nextline = raw_input().split(' ')
    nextline = [int(j) for j in nextline]
    for j in range(1, nextline[0] + 1):
        if nextline[j] < money:
            selleryes.append(i + 1)
            break

selleryes.sort()

print len(selleryes)
nums = ""
for i in selleryes:
    nums += str(i) + " "
print nums


n,v=map(int,raw_input().split())
s=[]
i=1
while(n>0):
	a=map(int,raw_input().split())
	if(a[1]<v):
		s.append(i)
	i+=1
	n-=1
print len(s)
for x in s:
	print x,


n,v=map(int,raw_input().split())
s=[]
i=1
while(n>0):
	a=map(int,raw_input().split())
	a=a[1:]
	a.sort()
	if(a[0]<v):
		s.append(i)
	i+=1
	n-=1
print len(s)
#if(len(s)==0):
#	print
for x in s:
	print x,


fun = lambda:map(int,raw_input().split())
n, money = fun()
ans = []
for i in xrange(n):
    data = fun()
    for m in data[1:]:
        if money > m:
            if data[0] not in ans:
                ans.append(data[0])
            break
print len(ans)
print ' '.join(map(str,sorted(ans)))


fun = lambda:map(int,raw_input().split())
n, money = fun()
ans = []
for i in xrange(n):
    data = fun()
    for m in data[1:]:
        if money > m:
            ans.append(data[0])
            break
print len(ans)
print ' '.join(map(str,sorted(ans)))


fun = lambda:map(int,raw_input().split())
n, money = fun()
ans = []
for i in xrange(n):
    data = fun()
    for m in data[1:]:
        if money > m:
            ans.append(i+1)
            break
print len(ans)
print ' '.join(map(str,sorted(ans)))


n, v = map(int, raw_input().split())
ret = []
for i in xrange(n):
    ks = map(int, raw_input().split())
    k = ks.pop(0)
    if min(ks) < v:
        ret.append(k)
print len(ret)
ret.sort()
print ' '.join(map(str, ret))


n, v = map(int, raw_input().split())
ret = []
for i in xrange(n):
    ks = map(int, raw_input().split())
    k = ks.pop(0)
    if min(ks) < v:
        ret.append(k)
print len(ret)
print ' '.join(map(str, ret))


n, v = map(int, raw_input().split())
ret = []
for i in xrange(n):
    ks = map(int, raw_input().split())
    k = ks.pop(0)
    if min(ks) < v:
        ret.append(i+1)
print len(ret)
ret.sort()
print ' '.join(map(str, ret))


res = []
fl = True
# sellers = 0
money = 0
c = -1
while True:
    line = ""
    try:
        c += 1
        line = raw_input()
        if fl:
            # global sellers
            # sellers = int(line.split(" ")[0])
            global money
            money = int(line.split(" ")[1])
            fl = False
        else:
            lineL = line.split(" ")
            lineL = map(lambda x:int(x), lineL)
            for x in xrange(1, len(lineL)):
                if money > lineL[x]:
                    res.append(c)
                    break
    except:
        break

print len(res)
for x in res:
    print x,


import sys
res = []
fl = True
sellers = 0
money = 0

while True:
    line = ""
    try:
        line = raw_input()
        if fl:
            global sellers
            sellers = int(line.split(" ")[0])
            global money
            money = int(line.split(" ")[1])
            fl = False
        else:
            lineL = line.split(" ")
            lineL = map(lambda x:int(x), lineL)
            for x in xrange(1, len(lineL)):
                if money > lineL[x]:
                    res.append(lineL[0])
    except:
        break

print len(res)
for x in res:
    print x,


import sys

a = sys.argv[0]
a = '''3 50000
1 40000
2 20000 60000
3 10000 70000 190000'''

money = 0
sellers = 0
offers = []

def splitStr (strIn):
    lines = strIn.split('\n')

    global sellers
    sellers = int(lines[0].split(" ")[0])

    global money
    money = int(lines[0].split(" ")[1])

    sellersOk = []

    for i in xrange (1, len(lines)):
        global offers
        l = lines[i].split(" ")
        li = map(lambda x: int(x), l)
        offers.append(li)
        res = 0
        for j in xrange (1, len(li)):
            if money > li[j]:
                sellersOk.append(li[0])
    return sellersOk

r = (splitStr(a))
print len(r)
for i in r:
    print i,


res = []
fl = True
# sellers = 0
money = 0

while True:
    line = ""
    try:
        line = raw_input()
        if fl:
            # global sellers
            # sellers = int(line.split(" ")[0])
            global money
            money = int(line.split(" ")[1])
            fl = False
        else:
            lineL = line.split(" ")
            lineL = map(lambda x:int(x), lineL)
            for x in xrange(1, len(lineL)):
                if money > lineL[x]:
                    res.append(lineL[0])
                    break
    except:
        break

print len(res)
for x in res:
    print x,


import sys
res = []
fl = True
sellers = 0
money = 0

while True:
    line = ""
    try:
        line = raw_input()
        if fl:
            global sellers
            sellers = int(line.split(" ")[0])
            global money
            money = int(line.split(" ")[1])
            fl = False
        else:
            lineL = line.split(" ")
            lineL = map(lambda x:int(x), lineL)
            for x in xrange(1, len(lineL)):
                if money >= lineL[x]:
                    res.append(lineL[0])
                    break
    except:
        break

print len(res)
for x in res:
    print x,


import sys

import sys

# a = '''3 50000
# 1 40000
# 2 20000 60000
# 3 10000 70000 190000'''

money = 0
sellers = 0
offers = []

l = str(raw_input())

print l

# def splitStr (strIn):
#     lines = strIn.split('\n')
#
#     global sellers
#     sellers = int(lines[0].split(" ")[0])
#
#     global money
#     money = int(lines[0].split(" ")[1])
#
#     sellersOk = []
#
#     for i in xrange (1, len(lines)):
#         global offers
#         l = lines[i].split(" ")
#         li = map(lambda x: int(x), l)
#         offers.append(li)
#         res = 0
#         for j in xrange (1, len(li)):
#             if money > li[j]:
#                 sellersOk.append(li[0])
#     return sellersOk
#
#
# r = (splitStr(a))
# print len(r)
# for i in r:
#     print i,


res = []
fl = True
# sellers = 0
money = 0

while True:
    line = ""
    try:
        line = raw_input()
        if fl:
            # global sellers
            # sellers = int(line.split(" ")[0])
            global money
            money = int(line.split(" ")[1])
            fl = False
        else:
            lineL = line.split(" ")
            lineL = map(lambda x:int(x), lineL)
            for x in xrange(1, len(lineL)):
                if money >= lineL[x]:
                    res.append(lineL[0])
                    break
    except:
        break

print len(res)
for x in res:
    print x,


import sys

a = sys.argv[0]
# a = '''3 50000
# 1 40000
# 2 20000 60000
# 3 10000 70000 190000'''

money = 0
sellers = 0
offers = []

def splitStr (strIn):
    lines = strIn.split('\n')

    global sellers
    sellers = int(lines[0].split(" ")[0])

    global money
    money = int(lines[0].split(" ")[1])

    sellersOk = []

    for i in xrange (1, len(lines)):
        global offers
        l = lines[i].split(" ")
        li = map(lambda x: int(x), l)
        offers.append(li)
        res = 0
        for j in xrange (1, len(li)):
            if money > li[j]:
                sellersOk.append(li[0])
    return sellersOk

r = (splitStr(a))
print len(r)
for i in r:
    print i,


import sys

a = sys.argv[1]
# a = '''3 50000
# 1 40000
# 2 20000 60000
# 3 10000 70000 190000'''

money = 0
sellers = 0
offers = []

def splitStr (strIn):
    lines = strIn.split('\n')

    global sellers
    sellers = int(lines[0].split(" ")[0])

    global money
    money = int(lines[0].split(" ")[1])

    sellersOk = []

    for i in xrange (1, len(lines)):
        global offers
        l = lines[i].split(" ")
        li = map(lambda x: int(x), l)
        offers.append(li)
        res = 0
        for j in xrange (1, len(li)):
            if money > li[j]:
                sellersOk.append(li[0])
    return sellersOk

r = (splitStr(a))
print len(r)
for i in r:
    print i,


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <numeric>
#include<cctype>
#include<deque>
#include<iomanip>
#include<queue>
#include<cstring>
#include<stack>
#include<unordered_map>
#define endl "\n"

#define ll unsigned long long
using namespace std;

typedef vector<int> v_c;
typedef vector<v_c>vv_c;

ll gcd(ll m, ll n) {

	if (n == 0) {
		return m;
	}
	return gcd(n, m % n);
}
ll lcm(ll m, ll n) {
	return (m / gcd(m, n)) * n;
}

int dx[] = { -1,0,-1,0 };
int dy[] = { -1,-1,0,0 };
int main() {

	ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);

	int t;
	cin >> t;
	int n, m;

	while (t--) {
		cin >> n >> m;
		vector<string>V(n);
		for (int i = 0;i < n;i++) {
			cin >> V[i];
		}
		int ans = 0;
		vector<vector<int>>res;
		for (int i = 1;i <= n - 1;i++) {
			for (int j = 1;j <= m - 1;j++) {

				vector<int>ones;
				vector<int>zeros;
				for (int k = 0;k < 4;k++) {
					if (V[i + dx[k]][j + dy[k]] == '1') {
						ones.push_back( i + dx[k] + 1 );
						ones.push_back(j + dy[k] + 1);
					}
					else {
						zeros.push_back(i + dx[k] + 1);
						zeros.push_back(j + dy[k] + 1);
					}
				}
				if (ones.size() == 8) {
					ans += 4;
					res.push_back({ i,j,i + 1,j,j,i,j+1 });
					res.push_back({ i + 1,j,i,j + 1,i + 1,j + 1 });
					res.push_back({ i,j,i+1,j,i + 1,j + 1});
					res.push_back({ i,j,i,j + 1,i + 1,j + 1 });
				}
				else if (ones.size() == 6) {
					ans += 1;
					if (V[i-1][j-1] == '0') {
						res.push_back({ i + 1,j,i,j + 1,i + 1,j + 1 });
					}
					else if (V[i ][j-1] == '0') {
						res.push_back({ i,j,i,j + 1,i + 1,j + 1 });
					}
					else if (V[i-1][j] == '0') {
						res.push_back({ i,j,i + 1,j,i + 1,j + 1 });
					}
					else {
						res.push_back({ i,j,i + 1,j,i,j + 1 });
					}
				}
				else if (ones.size() == 4) {
					ans += 2;
					res.push_back({ ones[0],ones[1],zeros[0],zeros[1],zeros[2],zeros[3] });
					res.push_back({ones[2],ones[3],zeros[0],zeros[1],zeros[2],zeros[3] });
				}

				V[i - 1][j - 1] = '0';
				V[i][j] = '0';
				V[i - 1][j] = '0';
				V[i][j - 1] = '0';
			}

		}
		cout << ans << endl;
		for (vector<int>v : res) {
			for (int i : v)cout << i << ' ';
			cout << endl;
		}

	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <numeric>
#include<cctype>
#include<deque>
#include<iomanip>
#include<queue>
#include<cstring>
#include<stack>
#include<unordered_map>
#define endl "\n"

#define ll unsigned long long
using namespace std;

typedef vector<int> v_c;
typedef vector<v_c>vv_c;

ll gcd(ll m, ll n) {

	if (n == 0) {
		return m;
	}
	return gcd(n, m % n);
}
ll lcm(ll m, ll n) {
	return (m / gcd(m, n)) * n;
}

int dx[] = { -1,0,-1,0 };
int dy[] = { -1,-1,0,0 };
int main() {

	ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);

	int t;
	cin >> t;
	int n, m;

	while (t--) {
		cin >> n >> m;
		vector<string>V(n);
		for (int i = 0;i < n;i++) {
			cin >> V[i];
		}
		int ans = 0;
		vector<vector<int>>res;
		for (int i = 1;i <= n - 1;i++) {
			for (int j = 1;j <= m - 1;j++) {

				vector<int>ones;
				vector<int>zeros;
				for (int k = 0;k < 4;k++) {
					if (V[i + dx[k]][j + dy[k]] == '1') {
						ones.push_back( i + dx[k] + 1 );
						ones.push_back(j + dy[k] + 1);
					}
					else {
						zeros.push_back(i + dx[k] + 1);
						zeros.push_back(j + dy[k] + 1);
					}
				}
				if (ones.size() == 8) {
					ans += 4;
					res.push_back({ i,j,i + 1,j,i,j+1 });
					res.push_back({ i + 1,j,i,j + 1,i + 1,j + 1 });
					res.push_back({ i,j,i+1,j,i + 1,j + 1});
					res.push_back({ i,j,i,j + 1,i + 1,j + 1 });
				}
				else if (ones.size() == 6) {
					ans += 1;
					res.push_back({ ones[0],ones[1],ones[2],ones[3],ones[4],ones[5] });
				}
				else if (ones.size() == 4) {
					ans += 2;

					res.push_back({ ones[0],ones[1],zeros[0],zeros[1],zeros[2],zeros[3] });
					res.push_back({ ones[2],ones[3],zeros[0],zeros[1],zeros[2],zeros[3] });
				}
				else {
					ans += 5;
					res.push_back({ zeros[0],zeros[1],zeros[2] ,zeros[3] ,zeros[4] ,zeros[5] });
					res.push_back({ i,j,i + 1,j,i,j + 1 });
					res.push_back({ i + 1,j,i,j + 1,i + 1,j + 1 });
					res.push_back({ i,j,i + 1,j,i + 1,j + 1 });
					res.push_back({ i,j,i,j + 1,i + 1,j + 1 });
				}

				V[i - 1][j - 1] = '0';
				V[i][j] = '0';
				V[i - 1][j] = '0';
				V[i][j - 1] = '0';
			}

		}
		cout << ans << endl;
		for (vector<int>v : res) {
			for (int i : v)cout << i << ' ';
			cout << endl;
		}

	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <numeric>
#include<cctype>
#include<deque>
#include<iomanip>
#include<queue>
#include<cstring>
#include<stack>
#include<unordered_map>
#define endl "\n"

#define ll unsigned long long
using namespace std;

typedef vector<int> v_c;
typedef vector<v_c>vv_c;

ll gcd(ll m, ll n) {

	if (n == 0) {
		return m;
	}
	return gcd(n, m % n);
}
ll lcm(ll m, ll n) {
	return (m / gcd(m, n)) * n;
}

int dx[] = { -1,0,-1,0 };
int dy[] = { -1,-1,0,0 };
int main() {

	ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);

	int t;
	cin >> t;
	int n, m;

	while (t--) {
		cin >> n >> m;
		vector<string>V(n);
		for (int i = 0;i < n;i++) {
			cin >> V[i];
		}
		int ans = 0;
		vector<vector<int>>res;
		for (int i = 1;i <= n - 1;i++) {
			for (int j = 1;j <= m - 1;j++) {

				vector<int>ones;
				vector<int>zeros;
				for (int k = 0;k < 4;k++) {
					if (V[i + dx[k]][j + dy[k]] == '1') {
						ones.push_back( i + dx[k] + 1 );
						ones.push_back(j + dy[k] + 1);
					}
					else {
						zeros.push_back(i + dx[k] + 1);
						zeros.push_back(j + dy[k] + 1);
					}
				}
				if (ones.size() == 8) {
					ans += 4;
					res.push_back({ i,j,i + 1,j,i,j+1 });
					res.push_back({ i + 1,j,i,j + 1,i + 1,j + 1 });
					res.push_back({ i,j,i+1,j,i + 1,j + 1});
					res.push_back({ i,j,i,j + 1,i + 1,j + 1 });
				}
				else if (ones.size() == 6) {
					ans += 1;
					res.push_back({ ones[0],ones[1],ones[2],ones[3],ones[4],ones[5] });
				}
				else if (ones.size() == 4) {
					ans += 2;

					res.push_back({ ones[0],ones[1],zeros[0],zeros[1],zeros[2],zeros[3] });
					res.push_back({ ones[2],ones[3],zeros[0],zeros[1],zeros[2],zeros[3] });
				}
				else if(ones.size()==2){
					ans += 5;
					res.push_back({ zeros[0],zeros[1],zeros[2] ,zeros[3] ,zeros[4] ,zeros[5] });
					res.push_back({ i,j,i + 1,j,i,j + 1 });
					res.push_back({ i + 1,j,i,j + 1,i + 1,j + 1 });
					res.push_back({ i,j,i + 1,j,i + 1,j + 1 });
					res.push_back({ i,j,i,j + 1,i + 1,j + 1 });
				}

				V[i - 1][j - 1] = '0';
				V[i][j] = '0';
				V[i - 1][j] = '0';
				V[i][j - 1] = '0';
			}

		}
		cout << ans << endl;
		for (vector<int>v : res) {
			for (int i : v)cout << i << ' ';
			cout << endl;
		}

	}
	return 0;
}


#include <cstdio>
#include <iostream>
#include <time.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
#include <stack>
#include <map>
#include <set>
#include <complex>

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef complex<double> cpx;
typedef vector<cpx> vec;

const double PI = acos(-1);
const int INF = 1e9 + 7;
const int MAX = 111;
const ll MOD = 1e9 + 7;

struct pp {
    int a[6];

    pp(): pp(0,0,0,0,0,0){}
    pp(int x1, int x2, int x3, int x4, int x5, int x6) {
        a[0] = x1;
        a[1] = x2;
        a[2] = x3;
        a[3] = x4;
        a[4] = x5;
        a[5] = x6;
    }
    void print_pp() {
        for (int i = 0; i < 6; i++) cout << a[i] << " ";
        cout << endl;
    }
};

int n, m;

int cnt;
int arr[MAX][MAX];
vector<pp> ans;

void print(int x1, int y1, int x2, int y2, int x3, int y3) {
    //cout << x1 << " " << y1 << " " << x2 << " " << y2 << " " << x3 << " " << y3 << endl;
    ans.push_back(pp(x1, y1, x2, y2, x3, y3));
    cnt++;
    if (arr[x1][y1] == 1) arr[x1][y1] = 0;
    else arr[x1][y1] = 1;
    if (arr[x2][y2] == 1) arr[x2][y2] = 0;
    else arr[x2][y2] = 1;
    if (arr[x3][y3] == 1) arr[x3][y3] = 0;
    else arr[x3][y3] = 1;
    return;
}

void m1(int x, int y) {
    if (arr[x][y] == 0 && arr[x][y + 1] == 0) return;
    if (arr[x][y] == 0 && arr[x][y + 1] == 1) {
        print(x, y + 1, x + 1, y, x + 1, y + 1);
        return;
    }
    if (arr[x][y] == 1 && arr[x][y + 1] == 0) {
        print(x, y, x + 1, y, x + 1, y + 1);
        return;
    }
    if (arr[x][y] == 1 && arr[x][y + 1] == 1) {
        print(x, y, x, y + 1, x + 1, y + 1);
        return;
    }
}

void m2(int x, int y) {
    if (arr[x][y] == 0 && arr[x][y + 1] == 0 && arr[x][y + 2]==0) return;
    if (arr[x][y] == 0 && arr[x][y + 1] == 0 && arr[x][y + 2]==1) {
        print(x, y + 2, x + 1, y + 2, x + 1, y + 1);
        return;
    }
    if (arr[x][y] == 0 && arr[x][y + 1] == 1 && arr[x][y + 2]==0){
        print(x, y + 1, x + 1, y + 1, x + 1, y);
        return;
    }
    if (arr[x][y] == 0 && arr[x][y + 1] == 1 && arr[x][y + 2]==1){
        print(x, y + 1, x, y + 2, x + 1, y + 1);
        return;
    }
    if (arr[x][y] == 1 && arr[x][y + 1] == 0 && arr[x][y + 2]==0){
        print(x, y, x + 1, y, x + 1, y + 1);
        return;
    }
    if (arr[x][y] == 1 && arr[x][y + 1] == 0 && arr[x][y + 2]==1){
        print(x, y, x + 1, y, x + 1, y + 1);
        print(x, y + 2, x + 1, y + 2, x + 1, y + 1);
        return;
    }
    if (arr[x][y] == 1 && arr[x][y + 1] == 1 && arr[x][y + 2]==0){
        print(x, y, x, y + 1, x + 1, y);
        return;
    }
    if (arr[x][y] == 1 && arr[x][y + 1] == 1 && arr[x][y + 2]==1){
        print(x, y, x + 1, y, x + 1, y + 1);
        print(x, y + 1, x, y + 2, x + 1, y + 2);
        return;
    }
}

void m3(int x, int y) {
    if (arr[x][y] == 0 && arr[x+1][y] == 0) return;
    if (arr[x][y] == 0 && arr[x+1][y] == 1) {
        print(x + 1, y, x, y + 1, x + 1, y + 1);
        return;
    }
    if (arr[x][y] == 1 && arr[x + 1][y] == 0) {
        print(x, y, x, y + 1, x + 1, y + 1);
        return;
    }
    if (arr[x][y] == 1 && arr[x + 1][y] == 1) {
        print(x, y, x + 1, y, x, y + 1);
        return;
    }
}

void m4(int x, int y) {
    if (arr[x][y] == 0 && arr[x][y + 1] == 0 && arr[x + 1][y] == 0 && arr[x + 1][y + 1] == 0) {
        return;
    }
    if (arr[x][y] == 0 && arr[x][y + 1] == 0 && arr[x + 1][y] == 0 && arr[x + 1][y + 1] == 1) {
        print(x + 1, y + 1, x, y, x, y + 1);
        print(x + 1, y + 1, x, y, x + 1, y);
        print(x + 1, y + 1, x + 1, y, x, y + 1);
        return;
    }
    if (arr[x][y] == 0 && arr[x][y + 1] == 0 && arr[x + 1][y] == 1 && arr[x + 1][y + 1] == 0) {
        print(x + 1, y, x, y, x, y + 1);
        print(x + 1, y, x, y + 1, x + 1, y + 1);
        print(x + 1, y, x + 1, y + 1, x, y);
        return;
    }
    if (arr[x][y] == 0 && arr[x][y + 1] == 0 && arr[x + 1][y] == 1 && arr[x + 1][y + 1] == 1) {
        print(x, y, x, y + 1, x + 1, y);
        print(x, y, x, y + 1, x + 1, y + 1);
        return;
    }
    if (arr[x][y] == 0 && arr[x][y + 1] == 1 && arr[x + 1][y] == 0 && arr[x + 1][y + 1] == 0) {
        print(x, y + 1, x, y, x + 1, y);
        print(x, y + 1, x + 1, y, x + 1, y + 1);
        print(x, y + 1, x + 1, y + 1, x, y);
        return;
    }
    if (arr[x][y] == 0 && arr[x][y + 1] == 1 && arr[x + 1][y] == 0 && arr[x + 1][y + 1] == 1) {
        print(x, y, x + 1, y, x, y + 1);
        print(x, y, x + 1, y, x + 1, y + 1);
        return;
    }
    if (arr[x][y] == 0 && arr[x][y + 1] == 1 && arr[x + 1][y] == 1 && arr[x + 1][y + 1] == 0) {
        print(x, y, x + 1, y + 1, x, y + 1);
        print(x, y, x + 1, y + 1, x + 1, y);
        return;
    }
    if (arr[x][y] == 0 && arr[x][y + 1] == 1 && arr[x + 1][y] == 1 && arr[x + 1][y + 1] == 1) {
        print(x, y + 1, x + 1, y, x + 1, y + 1);
        return;
    }
    if (arr[x][y] == 1 && arr[x][y + 1] == 0 && arr[x + 1][y] == 0 && arr[x + 1][y + 1] == 0) {
        print(x, y, x, y + 1, x + 1, y);
        print(x, y, x + 1, y, x + 1, y + 1);
        print(x, y, x + 1, y + 1, x, y + 1);
        return;
    }
    if (arr[x][y] == 1 && arr[x][y + 1] == 0 && arr[x + 1][y] == 0 && arr[x + 1][y + 1] == 1) {
        print(x, y + 1, x + 1, y, x, y);
        print(x, y + 1, x + 1, y, x + 1, y + 1);
        return;
    }
    if (arr[x][y] == 1 && arr[x][y + 1] == 0 && arr[x + 1][y] == 1 && arr[x + 1][y + 1] == 0) {
        print(x, y + 1, x + 1, y + 1, x, y);
        print(x, y + 1, x + 1, y + 1, x + 1, y);
        return;
    }
    if (arr[x][y] == 1 && arr[x][y + 1] == 0 && arr[x + 1][y] == 1 && arr[x + 1][y + 1] == 1) {
        print(x, y, x + 1, y, x + 1, y + 1);
        return;
    }
    if (arr[x][y] == 1 && arr[x][y + 1] == 1 && arr[x + 1][y] == 0 && arr[x + 1][y + 1] == 0) {
        print(x + 1, y, x + 1, y + 1, x, y);
        print(x + 1, y, x + 1, y + 1, x, y + 1);
        return;
    }
    if (arr[x][y] == 1 && arr[x][y + 1] == 1 && arr[x + 1][y] == 0 && arr[x + 1][y + 1] == 1) {
        print(x, y, x, y + 1, x + 1, y + 1);
        return;
    }
    if (arr[x][y] == 1 && arr[x][y + 1] == 1 && arr[x + 1][y] == 1 && arr[x + 1][y + 1] == 0) {
        print(x, y, x, y + 1, x + 1, y);
        return;
    }
    if (arr[x][y] == 1 && arr[x][y + 1] == 1 && arr[x + 1][y] == 1 && arr[x + 1][y + 1] == 1) {
        print(x, y, x, y + 1, x + 1, y);
        print(x, y, x, y + 1, x + 1, y + 1);
        print(x, y, x + 1, y, x + 1, y + 1);
        print(x, y + 1, x + 1, y, x + 1, y + 1);
        return;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T;
    cin >> T;
    for (int tc = 1; tc <= T; tc++) {
        ans.clear();
        cnt = 0;
        cin >> n >> m;
        for (int i = 1; i <= n; i++) {
            string s;
            cin >> s;
            for (int j = 1; j <= m; j++) {
                if (s[j-1] == '0') arr[i][j] = 0;
                else arr[i][j] = 1;
            }
        }

        for (int i = 1; i <= n - 2; i++) {
            for (int j = 1; j < m / 2; j++) {
                m1(i, 2 * j - 1);
            }
            if (m % 2 == 1) m2(i, m - 2);
            else m1(i, m - 1);
        }
        int i = n - 1;
        for (int j = 1; j <= m - 2; j++) {
            m3(i, j);
        }
        m4(n - 1, m - 1);

        cout << cnt << endl;
        for (pp p : ans) {
            p.print_pp();
        }
    }
}


#include <cstdio>
#include <iostream>
#include <time.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
#include <stack>
#include <map>
#include <set>
#include <complex>

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef complex<double> cpx;
typedef vector<cpx> vec;

const double PI = acos(-1);
const int INF = 1e9 + 7;
const int MAX = 111;
const ll MOD = 1e9 + 7;

int n, m;

int arr[MAX][MAX];

void print(int x1, int y1, int x2, int y2, int x3, int y3) {
    cout << x1 << " " << y1 << " " << x2 << " " << y2 << " " << x3 << " " << y3 << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T;
    cin >> T;
    for (int tc = 1; tc <= T; tc++) {
        cin >> n >> m;
        for (int i = 0; i < n; i++) {
            string s;
            cin >> s;
            for (int j = 0; j < m; j++) {
                if (s[j] == '0') arr[i][j] = 0;
                else arr[i][j] = 1;
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (arr[i][j] == 0) continue;
                if (i == 0) {
                    if (j == m - 1) {
                        print(0, m - 1, 0, m - 2, 1, m - 2);
                        print(0, m - 1, 0, m - 2, 1, m-1);
                        print(0, m - 1, 1,m-2, 1, m-1);
                    }
                    else {
                        print(0, j, 0, j + 1, 1, j);
                        print(0, j, 0, j + 1, 1, j + 1);
                        print(0, j, 1, j, 1, j + 1);
                    }
                }
                else {
                    if (j == 0) {
                        print(i, 0, i - 1, 0, i, 1);
                        print(i, 0, i-1, 0, i-1, 1);
                        print(i, 0, i - 1, 1, i, 1);
                    }
                    else {
                        print(i, j, i - 1, j, i, j - 1);
                        print(i, j, i - 1, j, i - 1, j - 1);
                        print(i, j, i, j - 1, i - 1, j - 1);
                    }
                }
            }
        }
    }
}


//sort(a,b, std::greater<>()); 降順
//vector a = b はDeepCopy
//sort(a,b,[](const fruit& x, const fruit& y) { return x.price > y.price;});
//#define PI 3.14159265359
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

bool stage[100][100] = { false };
struct Ans {
	int a, b, c, d, e, f;
	Ans() {}
	Ans(int A, int B, int C, int D, int E, int F) {
		a = A;
		b = B;
		c = C;
		d = D;
		e = E;
		f = F;
		stage[a][b] = !stage[a][b];
		stage[c][d] = !stage[c][d];
		stage[e][f] = !stage[e][f];
	}
};
vector<Ans>ans;
int main()
{
	int t = 1;
	cin >> t;
	for (int z = 0; z < t; z++) {
		int m, n;
		cin >> m >> n;
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				char a;
				cin >> a;
				if (a == '1') {
					stage[i][j] = true;
				}
			}
		}
		for (int i = 0; i < m - 1; i++) {
			for (int j = 0; j < n - 1; j++) {
				if (i == m - 2 && j == n - 2) {
					int counter = 0;
					if (stage[i][j] == true) {
						counter++;
					}
					if (stage[i][j + 1] == true) {
						counter++;
					}
					if (stage[i + 1][j] == true) {
						counter++;
					}
					if (stage[i + 1][j + 1] == true) {
						counter++;
					}
					if (counter == 4) {
						ans.push_back(Ans(i, j, i + 1, j, i, j + 1));
						counter = 1;
					}
					if (counter == 1) {
						if (stage[i][j] == false) {
							ans.push_back(Ans(i, j + 1, i + 1, j, i + 1, j + 1));
							counter = 2;
						}
						else {
							ans.push_back(Ans(i, j, i + 1, j, i + 1, j + 1));
							counter = 2;
						}
					}
					if (counter == 2) {
						if (stage[i][j] == true) {
							ans.push_back(Ans(i, j + 1, i + 1, j, i + 1, j + 1));
							counter = 3;
						}
						else if (stage[i][j + 1] == true) {
							ans.push_back(Ans(i, j, i + 1, j, i + 1, j + 1));
							counter = 3;
						}
						else {
							ans.push_back(Ans(i, j, i, j + 1, i + 1, j + 1));
							counter = 3;
						}
					}
					if (counter == 3) {
						if (stage[i][j] == false) {
							ans.push_back(Ans(i, j + 1, i + 1, j, i + 1, j + 1));
							counter = 3;
						}
						else if (stage[i][j + 1] == false) {
							ans.push_back(Ans(i, j, i + 1, j, i + 1, j + 1));
							counter = 3;
						}
						else if(stage[i+1][j] == false){
							ans.push_back(Ans(i, j, i, j + 1, i + 1, j + 1));
							counter = 3;
						}
						else {
							ans.push_back(Ans(i, j, i, j + 1, i + 1, j));
							counter = 3;
						}
					}
				}
				else if(j != n - 2){
					if (stage[i][j] == false && stage[i + 1][j] == false) {
						continue;
					}
					else if (stage[i][j] == true && stage[i + 1][j] == false) {
						ans.push_back(Ans(i, j, i, j + 1, i + 1, j + 1));
					}
					else if (stage[i][j] == true && stage[i + 1][j] == true) {
						ans.push_back(Ans(i, j, i + 1, j, i + 1, j + 1));
					}
					else {
						ans.push_back(Ans(i + 1, j, i, j + 1, i + 1, j + 1));
					}
				}
				else {
					if (stage[i][j] == false && stage[i][j + 1] == false) {
						continue;
					}
					else if (stage[i][j] == true && stage[i][j + 1] == false) {
						ans.push_back(Ans(i, j, i + 1, j, i + 1, j + 1));
					}
					else if (stage[i][j] == true && stage[i][j + 1] == true) {
						ans.push_back(Ans(i, j, i, j + 1, i + 1, j + 1));
					}
					else {
						ans.push_back(Ans(i, j + 1, i + 1, j, i + 1, j + 1));
					}
				}

			}
		}
		cout << ans.size() << endl;
		for (Ans a : ans) {
			cout << a.a + 1 << " " << a.b + 1 << " " << a.c + 1 << " " << a.d + 1 << " " << a.e + 1 << " " << a.f + 1 << endl;
		}
		ans.clear();
	}
}


#include <iostream>
#include <fstream>
#include <vector>
#include <utility>
#include <string.h>
#include <algorithm>
#include <math.h>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vc = vector<char>;
using pii = pair<int, int>;
using vpii = vector<pii>;

#define FORI(i, a, b, p) for (int i = a; i < b; i += p)
#define FOR(i, a, b) FORI(i, a, b, 1)
#define FOR0(i,b) FOR(i, 0, b)
#define RFOR(i, a, b) for (int i = a; i >= b; i--)
#define RFOR0(i, a) RFOR(i, a, 0)

#define MOD 998244353

int t;
char table[100][100];
int moves[30000][2];

void st(int x, int y, int& mc) {
	moves[mc][0] = x + 1;
	moves[mc][1] = y + 1;
	mc++;
}

bool is1(int x, int y) {
	return table[x][y] == '1';
}

void processSquare(int i, int j, int& mc) {
	int count = 0;
	bool ij = is1(i, j);
	bool i1j = is1(i + 1, j);
	bool ij1 = is1(i, j + 1);
	bool i1j1 = is1(i + 1, j + 1);
	if (ij) {
		count++;
	}
	if (i1j) {
		count++;
	}
	if (ij1) {
		count++;
	}
	if (i1j1) {
		count++;
	}

	if (count == 0) {
		return;
	}
	if (count == 4) {
		st(i, j, mc);
		st(i + 1, j, mc);
		st(i, j + 1, mc);
		count = 1;
	}
	if (count == 1) {
		if (ij) {
			st(i, j, mc);
			st(i + 1, j, mc);
			st(i, j + 1, mc);
		}
		else {
			st(i, j + 1, mc);
			st(i + 1, j, mc);
			st(i + 1, j + 1, mc);
		}
		count++;
	}
	if (count == 2) {
		int n1c = 0;
		if (!ij || n1c == 0) {
			st(i, j, mc);
			if (ij) {
				n1c++;
			}
		}
		if (!i1j || n1c == 0) {
			st(i + 1, j, mc);
			if (i1j) {
				n1c++;
			}
		}
		if (!ij1 || n1c == 0) {
			st(i, j + 1, mc);
			if (ij1) {
				n1c++;
			}
		}
		if (!i1j1 || n1c == 0) {
			st(i + 1, j + 1, mc);
			if (i1j1) {
				n1c++;
			}
		}
		count++;
	}
	if (count == 3) {
		if (ij) {
			st(i, j, mc);
		}
		if (i1j) {
			st(i + 1, j, mc);
		}
		if (ij1) {
			st(i, j + 1, mc);
		}
		if (i1j1) {
			st(i + 1, j + 1, mc);
		}
	}
}

int main() {
	cin >> t;
	while (t--) {
		memset(moves, 0, sizeof(moves));
		int n, m;
		cin >> n >> m;
		FOR0(i, n) {
			cin >> table[i];
		}
		int mc = 0;
		FORI(i, 0, n, 2) {
			FORI(j, 0, m, 2) {
				processSquare(i, j, mc);
			}
		}
		bool nOdd = n % 2 == 1;
		bool mOdd = m % 2 == 1;
		if (nOdd) {
			FORI(i, 0, m, 2) {
				processSquare(n - 2, i, mc);
			}
		}
		if (mOdd) {
			FORI(i, 0, n, 2) {
				processSquare(i, m - 2, mc);
			}
		}
		if (nOdd && mOdd) {
			processSquare(n - 2, m - 2, mc);
		}
		cout << mc / 3 << '\n';
		FOR0(i, mc / 3) {
			int p = i * 3;
			cout << moves[p][0];
			FOR(j, 1, 6) {
				cout << ' ' << moves[p][j];
			}
			cout << '\n';
		}
	}
}


#include <iostream>
#include <fstream>
#include <vector>
#include <utility>
#include <string.h>
#include <algorithm>
#include <math.h>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vc = vector<char>;
using pii = pair<int, int>;
using vpii = vector<pii>;

#define FORI(i, a, b, p) for (int i = a; i < b; i += p)
#define FOR(i, a, b) FORI(i, a, b, 1)
#define FOR0(i,b) FOR(i, 0, b)
#define RFOR(i, a, b) for (int i = a; i >= b; i--)
#define RFOR0(i, a) RFOR(i, a, 0)

#define MOD 998244353

int t;
char table[100][100];
int moves[30000][2];

void st(int x, int y, int& mc) {
	moves[mc][0] = x + 1;
	moves[mc][1] = y + 1;
	mc++;
}

bool is1(int x, int y) {
	return table[x][y] == '1';
}

void processSquare(int i, int j, int& mc) {
	int count = 0;
	bool ij = is1(i, j);
	bool i1j = is1(i + 1, j);
	bool ij1 = is1(i, j + 1);
	bool i1j1 = is1(i + 1, j + 1);
	if (ij) {
		count++;
	}
	if (i1j) {
		count++;
	}
	if (ij1) {
		count++;
	}
	if (i1j1) {
		count++;
	}

	if (count == 0) {
		return;
	}
	if (count == 4) {
		st(i, j, mc);
		st(i + 1, j, mc);
		st(i, j + 1, mc);
		count = 1;
	}
	ij = is1(i, j);
	i1j = is1(i + 1, j);
	ij1 = is1(i, j + 1);
	i1j1 = is1(i + 1, j + 1);
	if (count == 1) {
		if (ij) {
			st(i, j, mc);
			st(i + 1, j, mc);
			st(i, j + 1, mc);
		}
		else {
			st(i, j + 1, mc);
			st(i + 1, j, mc);
			st(i + 1, j + 1, mc);
		}
		count++;
	}
	ij = is1(i, j);
	i1j = is1(i + 1, j);
	ij1 = is1(i, j + 1);
	i1j1 = is1(i + 1, j + 1);
	if (count == 2) {
  		int n1c = 0;
		if (!ij || n1c == 0) {
			st(i, j, mc);
			if (ij) {
				n1c++;
			}
		}
		if (!i1j || n1c == 0) {
			st(i + 1, j, mc);
			if (i1j) {
				n1c++;
			}
		}
		if (!ij1 || n1c == 0) {
			st(i, j + 1, mc);
			if (ij1) {
				n1c++;
			}
		}
		if (!i1j1 || n1c == 0) {
			st(i + 1, j + 1, mc);
			if (i1j1) {
				n1c++;
			}
		}
		count++;
	}
	ij = is1(i, j);
	i1j = is1(i + 1, j);
	ij1 = is1(i, j + 1);
	i1j1 = is1(i + 1, j + 1);
	if (count == 3) {
		if (ij) {
			st(i, j, mc);
		}
		if (i1j) {
			st(i + 1, j, mc);
		}
		if (ij1) {
			st(i, j + 1, mc);
		}
		if (i1j1) {
			st(i + 1, j + 1, mc);
		}
	}
}

int main() {
	cin >> t;
	while (t--) {
		memset(moves, 0, sizeof(moves));
		int n, m;
		cin >> n >> m;
		FOR0(i, n) {
			cin >> table[i];
		}
		int mc = 0;
		FORI(i, 0, n, 2) {
			FORI(j, 0, m, 2) {
				processSquare(i, j, mc);
			}
		}
		bool nOdd = n % 2 == 1;
		bool mOdd = m % 2 == 1;
		if (nOdd) {
			FORI(i, 0, m, 2) {
				processSquare(n - 2, i, mc);
			}
		}
		if (mOdd) {
			FORI(i, 0, n, 2) {
				processSquare(i, m - 2, mc);
			}
		}
		if (nOdd && mOdd) {
			processSquare(n - 2, m - 2, mc);
		}
		cout << mc / 3 << '\n';
		FOR0(i, mc / 3) {
			int p = i * 3;
			cout << moves[p][0];
			FOR(j, 1, 6) {
				cout << ' ' << moves[p][j];
			}
			cout << '\n';
		}
	}
}


#include <iostream>
#include <fstream>
#include <vector>
#include <utility>
#include <string.h>
#include <algorithm>
#include <math.h>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vc = vector<char>;
using pii = pair<int, int>;
using vpii = vector<pii>;

#define FORI(i, a, b, p) for (int i = a; i < b; i += p)
#define FOR(i, a, b) FORI(i, a, b, 1)
#define FOR0(i,b) FOR(i, 0, b)
#define RFOR(i, a, b) for (int i = a; i >= b; i--)
#define RFOR0(i, a) RFOR(i, a, 0)

#define MOD 998244353

int t;
char table[100][100];
int moves[30000][2];

void st(int x, int y, int& mc) {
	if (table[x][y] == '0') {
		table[x][y] = '1';
	}
	else {
		table[x][y] = '0';
	}
	moves[mc][0] = x + 1;
	moves[mc][1] = y + 1;
	mc++;
}

bool is1(int x, int y) {
	return table[x][y] == '1';
}

void processSquare(int i, int j, int& mc) {
	int count = 0;
	bool ij = is1(i, j);
	bool i1j = is1(i + 1, j);
 	bool ij1 = is1(i, j + 1);
	bool i1j1 = is1(i + 1, j + 1);
	if (ij) {
		count++;
	}
	if (i1j) {
		count++;
	}
	if (ij1) {
		count++;
	}
	if (i1j1) {
		count++;
	}

	if (count == 0) {
		return;
	}
	if (count == 4) {
		st(i, j, mc);
		st(i + 1, j, mc);
		st(i, j + 1, mc);
		count = 1;
	}
	ij = is1(i, j);
	i1j = is1(i + 1, j);
	ij1 = is1(i, j + 1);
	i1j1 = is1(i + 1, j + 1);
	if (count == 1) {
		if (ij) {
			st(i, j, mc);
			st(i + 1, j, mc);
			st(i, j + 1, mc);
		}
		else {
			st(i, j + 1, mc);
			st(i + 1, j, mc);
			st(i + 1, j + 1, mc);
		}
		count++;
	}
	ij = is1(i, j);
	i1j = is1(i + 1, j);
	ij1 = is1(i, j + 1);
	i1j1 = is1(i + 1, j + 1);
	if (count == 2) {
  		int n1c = 0;
		if (!ij || n1c == 0) {
			st(i, j, mc);
			if (ij) {
				n1c++;
			}
		}
		if (!i1j || n1c == 0) {
			st(i + 1, j, mc);
			if (i1j) {
				n1c++;
			}
		}
		if (!ij1 || n1c == 0) {
			st(i, j + 1, mc);
			if (ij1) {
				n1c++;
			}
		}
		if (!i1j1 || n1c == 0) {
			st(i + 1, j + 1, mc);
			if (i1j1) {
				n1c++;
			}
		}
		count++;
	}
	ij = is1(i, j);
	i1j = is1(i + 1, j);
	ij1 = is1(i, j + 1);
	i1j1 = is1(i + 1, j + 1);
	if (count == 3) {
		if (ij) {
			st(i, j, mc);
		}
		if (i1j) {
			st(i + 1, j, mc);
		}
		if (ij1) {
			st(i, j + 1, mc);
		}
		if (i1j1) {
			st(i + 1, j + 1, mc);
		}
	}
}

int main() {
	cin >> t;
	while (t--) {
		memset(moves, 0, sizeof(moves));
		int n, m;
		cin >> n >> m;
		FOR0(i, n) {
			cin >> table[i];
		}
		int mc = 0;
		FORI(i, 0, n - 1, 2) {
			FORI(j, 0, m - 1, 2) {
				processSquare(i, j, mc);
			}
		}
		bool nOdd = n % 2 == 1;
		bool mOdd = m % 2 == 1;
		if (nOdd) {
			FORI(i, 0, m - 1, 2) {
				processSquare(n - 2, i, mc);
			}
		}
		if (mOdd) {
			FORI(i, 0, n - 1, 2) {
				processSquare(i, m - 2, mc);
			}
		}
		if (nOdd && mOdd) {
			processSquare(n - 2, m - 2, mc);
		}
		cout << mc / 3 << '\n';
		FORI(i, 0, mc, 3) {
			cout << moves[i][0] << ' ' << moves[i][1];
			FOR(j, 1, 3) {
				cout << ' ' << moves[i + j][0] << ' ' << moves[i + j][1];
			}
			cout << '\n';
		}
	}
}


#include <iostream>
#include <fstream>
#include <vector>
#include <utility>
#include <string.h>
#include <algorithm>
#include <math.h>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vc = vector<char>;
using pii = pair<int, int>;
using vpii = vector<pii>;

#define FORI(i, a, b, p) for (int i = a; i < b; i += p)
#define FOR(i, a, b) FORI(i, a, b, 1)
#define FOR0(i,b) FOR(i, 0, b)
#define RFOR(i, a, b) for (int i = a; i >= b; i--)
#define RFOR0(i, a) RFOR(i, a, 0)

#define MOD 998244353

int t;
char table[100][100];
int moves[30000][2];

void st(int x, int y, int& mc) {
	moves[mc][0] = x + 1;
	moves[mc][1] = y + 1;
	mc++;
}

bool is1(int x, int y) {
	return table[x][y] == '1';
}

void processSquare(int i, int j, int& mc) {
	int count = 0;
	bool ij = is1(i, j);
	bool i1j = is1(i + 1, j);
	bool ij1 = is1(i, j + 1);
	bool i1j1 = is1(i + 1, j + 1);
	if (ij) {
		count++;
	}
	if (i1j) {
		count++;
	}
	if (ij1) {
		count++;
	}
	if (i1j1) {
		count++;
	}

	if (count == 0) {
		return;
	}
	if (count == 4) {
		st(i, j, mc);
		st(i + 1, j, mc);
		st(i, j + 1, mc);
		count = 1;
	}
	if (count == 1) {
		if (ij) {
			st(i, j, mc);
			st(i + 1, j, mc);
			st(i, j + 1, mc);
		}
		else {
			st(i, j + 1, mc);
			st(i + 1, j, mc);
			st(i + 1, j + 1, mc);
		}
		count++;
	}
	if (count == 2) {
		int n1c = 0;
		if (!ij || n1c == 0) {
			st(i, j, mc);
			if (ij) {
				n1c++;
			}
		}
		if (!i1j || n1c == 0) {
			st(i + 1, j, mc);
			if (i1j) {
				n1c++;
			}
		}
		if (!ij1 || n1c == 0) {
			st(i, j + 1, mc);
			if (ij1) {
				n1c++;
			}
		}
		if (!i1j1 || n1c == 0) {
			st(i + 1, j + 1, mc);
			if (i1j1) {
				n1c++;
			}
		}
		count++;
	}
	if (count == 3) {
		if (ij) {
			st(i, j, mc);
		}
		if (i1j) {
			st(i + 1, j, mc);
		}
		if (ij1) {
			st(i, j + 1, mc);
		}
		if (i1j1) {
			st(i + 1, j + 1, mc);
		}
	}
}

int main() {
	cin >> t;
	while (t--) {
		int n, m;
		cin >> n >> m;
		FOR0(i, n) {
			cin >> table[i];
		}
		int mc = 0;
		FORI(i, 0, n, 2) {
			FORI(j, 0, m, 2) {
				processSquare(i, j, mc);
			}
		}
		bool nOdd = n % 2 == 1;
		bool mOdd = m % 2 == 1;
		if (nOdd) {
			FORI(i, 0, m, 2) {
				processSquare(n - 2, i, mc);
			}
		}
		if (mOdd) {
			FORI(i, 0, n, 2) {
				processSquare(i, m - 2, mc);
			}
		}
		if (nOdd && mOdd) {
			processSquare(n - 2, m - 2, mc);
		}
		cout << mc / 3 << '\n';
		FOR0(i, mc / 3) {
			int p = i * 3;
			cout << moves[p][0];
			FOR(j, 1, 6) {
				cout << ' ' << moves[p][j];
			}
			cout << '\n';
		}
	}
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<stdio.h>
#include<string>
#include<set>
#include<iomanip>
#include<numeric>
#include<map>
#include<limits>
#include<unordered_set>
#include<array>
#include<deque>

using namespace std;

int modi(vector<vector<int>>& a,int m,int n,vector<vector<int>>&b)
{
	int count = 0;
	int total = 0;
	vector<int> temp;
	for (int i = m; i <= m + 1; i++)
	{
		for (int j = n; j <= n + 1; j++)
		{
			if (a[i][j] == 1)
			{
				count++;
			}
		}
	}
	if (count == 0)
	{
		return 0;
	}
	if (count == 3)
	{
		for (int i = m; i <= m + 1; i++)
		{
			for (int j = n; j <= n + 1; j++)
			{
				if (a[i][j] == 1)
				{
					temp.push_back(i);
					temp.push_back(j);
					a[i][j] = 0;
				}
			}
		}
		b.push_back(temp);
		return 1;
	}
	if (count == 2)
	{
		if (a[m][n] == a[m + 1][n + 1])
		{
			if (a[m][n] == 0)
			{
				for (int i = m; i <= m + 1; i++)
				{
					for (int j = n; j <= n + 1; j++)
					{
						if (!(i==m+1 && j==n))
						{
							temp.push_back(i);
							temp.push_back(j);
							a[i][j] = !a[i][j];
						}
					}
				}
			}
			else {
				for (int i = m; i <= m + 1; i++)
				{
					for (int j = n; j <= n + 1; j++)
					{
						if (i != m + 1 || j != n+1)
						{
							temp.push_back(i);
							temp.push_back(j);
							a[i][j] = !a[i][j];
						}
					}
				}
			}
		}
		else {
			int flag = 0;
			for (int i = m; i <= m + 1; i++)
			{
				for (int j = n; j <= n + 1; j++)
				{
					if (a[i][j]==0)
					{
						temp.push_back(i);
						temp.push_back(j);
						a[i][j] = !a[i][j];
					}
					else if (flag == 0)
					{
						temp.push_back(i);
						temp.push_back(j);
						a[i][j] = !a[i][j];
						flag = 1;
					}
				}
			}
		}
		total += 1;
		b.push_back(temp);
		total += modi(a, m, n,b);
	}
	if (count == 1)
	{
		int flag = 0;
		for (int i = m; i <= m + 1; i++)
		{
			for (int j = n; j <= n + 1; j++)
			{
				if (a[i][j] == 1)
				{
					temp.push_back(i);
					temp.push_back(j);
					a[i][j] = !a[i][j];
				}
				else if (flag <2)
				{
					temp.push_back(i);
					temp.push_back(j);
					a[i][j] = !a[i][j];
					flag++;
				}
			}
		}
		total += 1;
		b.push_back(temp);
		total += modi(a, m, n,b);
	}
	if (count == 4)
	{
		int flag = 0;
		for (int i = m; i <= m + 1; i++)
		{
			for (int j = n; j <= n + 1; j++)
			{
				if (a[i][j] == 1 && flag<3)
				{
					temp.push_back(i);
					temp.push_back(j);
					a[i][j] = !a[i][j];
					flag++;
				}
			}
		}
		total += 1;
		b.push_back(temp);
		total += modi(a, m, n,b);

	}
}

int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
std::cout.tie(0);
long long t, q,x,l,y,r,g,k,c,m,p;
long long n;
string s;
cin >> t;
while(t--)
{
	cin >> n >> m;
	vector<vector<int>>a(n, vector<int>(m));
	vector<vector<int>>b;
	char p;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> p;
			a[i][j] = p - '0';
		}
	}
	for (int i = 0; i < n-1; i++)
	{
		for (int j = 0; j < m-1; j++)
		{
			modi(a, i, j,b);
		}
	}
	std::cout << b.size()<<endl;
	for (int i = 0; i < b.size(); i++)
	{
		for (int j = 0; j < 6; j++)
		{
			std::cout << b[i][j] +1 << " ";
		}
		std::cout << endl;
	}
}
return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<stdio.h>
#include<string>
#include<set>
#include<iomanip>
#include<numeric>
#include<map>
#include<limits>
#include<unordered_set>
#include<array>
#include<deque>

using namespace std;

int modi(vector<vector<int>>& a,int m,int n,vector<vector<int>>&b)
{
	int count = 0;
	int total = 0;
	vector<int> temp;
	for (int i = m; i <= m + 1; i++)
	{
		for (int j = n; j <= n + 1; j++)
		{
			if (a[i][j] == 1)
			{
				count++;
			}
		}
	}
	if (count == 0)
	{
		return 0;
	}
	if (count == 3)
	{
		for (int i = m; i <= m + 1; i++)
		{
			for (int j = n; j <= n + 1; j++)
			{
				if (a[i][j] == 1)
				{
					temp.push_back(i);
					temp.push_back(j);
					a[i][j] = 0;
				}
			}
		}
		b.push_back(temp);
		return 1;
	}
	if (count == 2)
	{
		if (a[m][n] == a[m + 1][n + 1])
		{
			if (a[m][n] == 0)
			{
				for (int i = m; i <= m + 1; i++)
				{
					for (int j = n; j <= n + 1; j++)
					{
						if (!(i==m+1 && j==n))
						{
							temp.push_back(i);
							temp.push_back(j);
							a[i][j] = !a[i][j];
						}
					}
				}
			}
			else {
				for (int i = m; i <= m + 1; i++)
				{
					for (int j = n; j <= n + 1; j++)
					{
						if (i != m + 1 && j != n+1)
						{
							temp.push_back(i);
							temp.push_back(j);
							a[i][j] = !a[i][j];
						}
					}
				}
			}
		}
		else {
			int flag = 0;
			for (int i = m; i <= m + 1; i++)
			{
				for (int j = n; j <= n + 1; j++)
				{
					if (a[i][j]==0)
					{
						temp.push_back(i);
						temp.push_back(j);
						a[i][j] = !a[i][j];
					}
					else if (flag == 0)
					{
						temp.push_back(i);
						temp.push_back(j);
						a[i][j] = !a[i][j];
						flag = 1;
					}
				}
			}
		}
		total += 1;
		b.push_back(temp);
		total += modi(a, m, n,b);
	}
	if (count == 1)
	{
		int flag = 0;
		for (int i = m; i <= m + 1; i++)
		{
			for (int j = n; j <= n + 1; j++)
			{
				if (a[i][j] == 1)
				{
					temp.push_back(i);
					temp.push_back(j);
					a[i][j] = !a[i][j];
				}
				else if (flag <2)
				{
					temp.push_back(i);
					temp.push_back(j);
					a[i][j] = !a[i][j];
					flag++;
				}
			}
		}
		total += 1;
		b.push_back(temp);
		total += modi(a, m, n,b);
	}
	if (count == 4)
	{
		int flag = 0;
		for (int i = m; i <= m + 1; i++)
		{
			for (int j = n; j <= n + 1; j++)
			{
				if (a[i][j] == 1 && flag<3)
				{
					temp.push_back(i);
					temp.push_back(j);
					a[i][j] = !a[i][j];
					flag++;
				}
			}
		}
		total += 1;
		b.push_back(temp);
		total += modi(a, m, n,b);

	}
}

int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
std::cout.tie(0);
long long t, q,x,l,y,r,g,k,c,m,p;
long long n;
string s;
cin >> t;
while(t--)
{
	cin >> n >> m;
	vector<vector<int>>a(n, vector<int>(m));
	vector<vector<int>>b;
	char p;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> p;
			a[i][j] = p - '0';
		}
	}
	for (int i = 0; i < n-1; i++)
	{
		for (int j = 0; j < m-1; j++)
		{
			modi(a, i, j,b);
		}
	}
	std::cout << b.size()<<endl;
	for (int i = 0; i < b.size(); i++)
	{
		for (int j = 0; j < 6; j++)
		{
			std::cout << b[i][j] +1 << " ";
		}
		std::cout << endl;
	}
}
return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <iomanip>
#include <set>
#include <stack>
#include <math.h>
#include <cstring>
using namespace std;
#define ll long long
#define mp make_pair

int a[105][105];
int n, m;
vector <vector <pair<int, int>>> op;

void test() {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) cout << a[i][j] << " ";
		cout << endl;
	}
}
void one_zero(int i, int j) {
	vector <pair <int, int>> v;
	for (int ii = i; ii < i + 2; ii++) {
		for (int jj = j; jj < j + 2; jj++) {
			if (a[ii][jj] == 1) {
				a[ii][jj] = 0;
				v.push_back(mp(ii, jj));
			}
		}
	}
	op.push_back(v);
	return;
}
void two_0(int i, int j) {
	vector <pair <int, int>> v;
	int change_zeroes = 2, change_ones = 1;
	for (int ii = i; ii < i + 2; ii++) {
		for (int jj = j; jj < j + 2; jj++) {
			if (a[ii][jj] == 0 && change_zeroes) {
				a[ii][jj] = 1;
				v.push_back(mp(ii, jj));
				change_zeroes--;
			}
			else if (a[ii][jj] == 1 && change_ones) {
				a[ii][jj] = 0;
				v.push_back(mp(ii, jj));
				change_ones--;
			}
		}
	}
	op.push_back(v);
	one_zero(i, j);
	return;
}
void three_0(int i, int j) {
	vector <pair<int, int>> v;
	int change_ones = 1, change_zeroes = 2;
	for (int ii = i; ii < i + 2; ii++) {
		for (int jj = j; jj < j + 2; jj++) {
			if (a[ii][jj] == 0 && change_zeroes) {
				a[ii][jj] = 1;
				v.push_back(mp(ii, jj));
				change_zeroes--;
			}
			else if (a[ii][jj] == 1 && change_ones) {
				a[ii][jj] = 0;
				v.push_back(mp(ii, jj));
				change_ones--;
			}
		}
	}
	op.push_back(v);
	two_0(i, j);
	return;
}
void zero_0(int i, int j) {
	a[i][j] = a[i + 1][j] = a[i][j + 1] = 0;
	vector <pair<int, int>> v(3);
	v[0] = mp(i, j);
	v[1] = mp(i + 1, j);
	v[2] = mp(i, j + 1);
	op.push_back(v);
	three_0(i, j);
	return;
}
int main()
{
	int t;
	cin >> t;
	while (t--) {
		char x;
		op.clear();
		cin >> n >> m;
		for (int i = 0; i < n; i++){
			for (int j = 0; j < m; j++) {
				cin >> x;
				a[i][j] = x - '0';
			}
		}
		int sum = 0;
		for (int i = 0; i < n - 1; i++)
		{
			for (int j = 0; j < m - 1; j++) {
				sum = a[i][j] + a[i + 1][j] + a[i][j + 1] + a[i + 1][j + 1];
				if (sum == 4) zero_0(i, j);
				else if (sum == 3) one_zero(i, j);
				else if (sum == 2) two_0(i, j);
				else if (sum == 1) three_0(i, j);
				else continue;
			}
		}

		cout << op.size() << endl;
		for (int i = 0; i < op.size(); i++) {
			for (int j = 0; j < op[i].size(); j++) {
				cout << op[i][j].first + 1 << " " << op[i][j].second + 1 << " ";
			}
			cout << endl;
		}
	}
}


#include <set>
#include <map>
#include <iostream>
#include <vector>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <deque>
using namespace std;

int main() {
	int a;
	cin >> a;
	for (int i = 0; i < a; ++i) {
		int n;
		cin >> n;
		int m;
		cin >> m;
		string exa = "01";
		char zer = exa[0];
		char on = exa[1];
		vector<string> num;
		for (int i = 0; i < n; ++i) {
			string l;
			cin >> l;
			num.push_back(l);

		}
		int tn = 0;
		int tm = 0;
		if (n % 2 == 1) {
			tn = 1;
			n = n + 1;
			string O;
			for (int az = 0; az < m; ++az) {
				O.push_back(zer);
			}
			num.push_back(O);
		}
		if (m % 2 == 1) {
			tm = 1;
			m = m + 1;
			for (int az = 0; az < num.size(); ++az) {
				num[az].push_back(zer);
			}
		}

		vector<pair<int, int>> lost;
		for (int q = 0; q < n / 2; ++q) {
			for (int w = 0; w < m / 2; ++w) {
				int it1 = q * 2;
				int it2 = w * 2;
				int chck = 0;
				if (num[it1][it2] == on)
					chck = chck + 1;
				if (num[it1][it2+1] == on)
					chck = chck + 1;
				if (num[it1+1][it2] == on)
					chck = chck + 1;
				if (num[it1+1][it2+1] == on)
					chck = chck + 1;
				int div = chck % 2;
				char divs;
				if (div == 0)
					divs = zer;
				else divs = on;

				if (chck > 0) {
					if (num[it1][it2] != divs) {
						pair<int, int> p;
						p.first = it1 + 1;
						p.second = it2 + 1;
						lost.push_back(p);
						--p.first;
						lost.push_back(p);
						++p.first;
						--p.second;
						lost.push_back(p);
					}

					if (num[it1 + 1][it2 + 1] != divs) {
						pair<int, int> p;
						p.first = it1;
						p.second = it2;
						lost.push_back(p);
						++p.first;
						lost.push_back(p);
						--p.first;
						++p.second;
						lost.push_back(p);
					}

					if (num[it1 + 1][it2] != divs) {
						pair<int, int> p;
						p.first = it1 + 1;
						p.second = it2 + 1;
						lost.push_back(p);
						--p.first;
						lost.push_back(p);
						--p.second;
						lost.push_back(p);
					}

					if (num[it1][it2 + 1] != divs) {
						pair<int, int> p;
						p.first = it1 + 1;
						p.second = it2 + 1;
						lost.push_back(p);
						--p.second;
						lost.push_back(p);
						--p.first;
						lost.push_back(p);
					}

				}

			}

		}

		int y = 0;
		cout << lost.size() / 3 << "\n";
		for (int o = 0; o < lost.size(); ++o) {
			if (lost[o].first == n-1 && tn == 1) {
				lost[o].first = n - 3;
			}
			if (lost[o].second == m - 1 && tm == 1) {
				lost[o].second = m - 3;
			}

			cout << lost[o].first+1 << " " << lost[o].second+1 << " ";

			++y;
			if (y%3 == 0)
				cout << "\n";

		}

	}
	return 0;

}


#include <set>
#include <map>
#include <iostream>
#include <vector>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <deque>
using namespace std;

int main() {
	int a;
	cin >> a;
	for (int i = 0; i < a; ++i) {
		int n;
		cin >> n;
		int m;
		cin >> m;
		string exa = "01";
		char zer = exa[0];
		char on = exa[1];
		vector<string> num;
		for (int i = 0; i < n; ++i) {
			string l;
			cin >> l;
			num.push_back(l);

		}
		int tn = 0;
		int tm = 0;
		if (n % 2 == 1) {
			tn = 1;
			n = n + 1;
			string O;
			for (int az = 0; az < m; ++az) {
				O.push_back(zer);
			}
			num.push_back(O);
		}
		if (m % 2 == 1) {
			tm = 1;
			m = m + 1;
			for (int az = 0; az < num.size(); ++az) {
				num[az].push_back(0);
			}
		}

		vector<pair<int, int>> lost;
		for (int q = 0; q < n / 2; ++q) {
			for (int w = 0; w < m / 2; ++w) {
				int it1 = q * 2;
				int it2 = w * 2;
				int chck = 0;
				if (num[it1][it2] == on)
					chck = chck + 1;
				if (num[it1][it2+1] == on)
					chck = chck + 1;
				if (num[it1+1][it2] == on)
					chck = chck + 1;
				if (num[it1+1][it2+1] == on)
					chck = chck + 1;
				int div = chck % 2;
				char divs;
				if (div == 0)
					divs = zer;
				else divs = on;

				if (num[it1][it2] != divs) {
					pair<int, int> p;
					p.first = it1+1;
					p.second = it2+1;
					lost.push_back(p);
					--p.first;
					lost.push_back(p);
					++p.first;
					--p.second;
					lost.push_back(p);
				}

				if (num[it1+1][it2+1] != divs) {
					pair<int, int> p;
					p.first = it1;
					p.second = it2;
					lost.push_back(p);
					++p.first;
					lost.push_back(p);
					--p.first;
					++p.second;
					lost.push_back(p);
				}

				if (num[it1+1][it2] != divs) {
					pair<int, int> p;
					p.first = it1 + 1;
					p.second = it2 + 1;
					lost.push_back(p);
					--p.first;
					lost.push_back(p);
					--p.second;
					lost.push_back(p);
				}

				if (num[it1][it2+1] != divs) {
					pair<int, int> p;
					p.first = it1 + 1;
					p.second = it2 + 1;
					lost.push_back(p);
					--p.second;
					lost.push_back(p);
					--p.first;
					lost.push_back(p);
				}

			}

		}

		int y = 0;
		cout << lost.size() / 3 << "\n";
		for (int o = 0; o < lost.size(); ++o) {
			if (lost[o].first == n-1 && tn == 1) {
				lost[o].first = n - 3;
			}
			if (lost[o].second == m - 1 && tm == 1) {
				lost[o].second = m - 3;
			}

			cout << lost[o].first+1 << " " << lost[o].second+1 << " ";

			++y;
			if (y%3 == 0)
				cout << "\n";

		}

	}
	return 0;

}


#include <set>
#include <map>
#include <iostream>
#include <vector>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <deque>
using namespace std;

int main() {
	int a;
	cin >> a;
	for (int i = 0; i < a; ++i) {
		int n;
		cin >> n;
		int m;
		cin >> m;
		string exa = "01";
		char zer = exa[0];
		char on = exa[1];
		vector<string> num;
		for (int i = 0; i < n; ++i) {
			string l;
			cin >> l;
			num.push_back(l);

		}
		int tn = 0;
		int tm = 0;
		if (n % 2 == 1) {
			tn = 1;
			n = n + 1;
			string O;
			for (int az = 0; az < m; ++az) {
				O.push_back(zer);
			}
			num.push_back(O);
		}
		if (m % 2 == 1) {
			tm = 1;
			m = m + 1;
			for (int az = 0; az < num.size(); ++az) {
				num[az].push_back(0);
			}
		}

		vector<pair<int, int>> lost;
		for (int q = 0; q < n / 2; ++q) {
			for (int w = 0; w < m / 2; ++w) {
				int it1 = q * 2;
				int it2 = w * 2;
				int chck = 0;
				if (num[it1][it2] == on)
					chck = chck + 1;
				if (num[it1][it2+1] == on)
					chck = chck + 1;
				if (num[it1+1][it2] == on)
					chck = chck + 1;
				if (num[it1+1][it2+1] == on)
					chck = chck + 1;
				int div = chck % 2;
				char divs;
				if (div == 0)
					divs = zer;
				else divs = on;

				if (num[it1][it2] != divs) {
					pair<int, int> p;
					p.first = it1+1;
					p.second = it2+1;
					lost.push_back(p);
					--p.first;
					lost.push_back(p);
					++p.first;
					--p.second;
					lost.push_back(p);
				}

				if (num[it1+1][it2+1] != divs) {
					pair<int, int> p;
					p.first = it1;
					p.second = it2;
					lost.push_back(p);
					++p.first;
					lost.push_back(p);
					--p.first;
					++p.second;
					lost.push_back(p);
				}

				if (num[it1+1][it2] != divs) {
					pair<int, int> p;
					p.first = it1 + 1;
					p.second = it2 + 1;
					lost.push_back(p);
					--p.first;
					lost.push_back(p);
					--p.second;
					lost.push_back(p);
				}

				if (num[it1][it2+1] != divs) {
					pair<int, int> p;
					p.first = it1 + 1;
					p.second = it2 + 1;
					lost.push_back(p);
					--p.second;
					lost.push_back(p);
					--p.first;
					lost.push_back(p);
				}

			}

		}

		int y = 0;
		cout << lost.size() / 3 << "\n";
		for (int o = 0; o < lost.size(); ++o) {
			if (lost[o].first == n-1 && tn == 1) {
				lost[o].first = n - 2;
			}
			if (lost[o].second == m - 1 && tm == 1) {
				lost[o].second = m - 2;
			}

			cout << lost[o].first+1 << " " << lost[o].second+1 << " ";

			++y;
			if (y%3 == 0)
				cout << "\n";

		}

	}
	return 0;

}


#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<map>
#include<set>
#include<queue>
#include<time.h>
#include<algorithm>
#include<utility>
#include <sstream>
#include<iomanip>
#define  rep(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define ff(a,b) for(int a=0;a<b;a++)
#define mod 998244353
#define M_PI  3.14159265358979323846   // pi
using namespace std;

pair<int, int>res[50005];
int main() {
	std::ios::sync_with_stdio(false);
	int t;
	cin >> t;
	while (t--)
	{
		int n, m, num = 0, num1 = 0,num2=0;
		char a[105][105];
		cin >> n >> m;
		rep(i, 1, n + 1)
		{
			rep(j, 1, m + 1)
			{
				cin >> a[i][j];
			}
		}
		for (int  i = 1; i < n; i++)
		{
			for (int j = 1; j < m; j++)
			{
				num = 0;
				num1 = 0;
				pair<int, int>p[105];
				pair<int, int>q[105];
				if (a[i][j] == '0')
				{
					p[num].first = i;
					p[num].second = j;
					num++;
				}
				else
				{
					q[num1].first = i;
					q[num1].second = j;
					num1++;
				}if (a[i+1][j] == '0')
				{
					p[num].first = i+1;
					p[num].second = j;
					num++;
				}
				else
				{
					q[num1].first = i+1;
					q[num1].second = j;
					num1++;
				}
				if (a[i][j+1] == '0')
				{
					p[num].first = i;
					p[num].second = j+1;
					num++;
				}
				else
				{
					q[num1].first = i;
					q[num1].second = j+1;
					num1++;
				}
				if (a[i+1][j+1] == '0')
				{
					p[num].first = i+1;
					p[num].second = j+1;
					num++;
				}
				else
				{
					q[num1].first = i+1;
					q[num1].second = j+1;
					num1++;
				}
				if (num == 2)
				{

					res[num2].first = p[num - 1].first;
					res[num2].second = p[num - 1].second;
					res[++num2].first= p[num - 2].first;
					res[num2].second = p[num - 2].second;
					res[++num2].first = q[num1 - 1].first;
					res[num2].second = q[num1 - 1].second;

					res[++num2].first = q[num1 - 2].first;
					res[num2].second = q[num1 - 2].second;
					res[++num2].first = res[num2 - 4].first;
					res[num2].second = res[num2 - 4].second;
					res[++num2].first = res[num2 - 4].first;
					res[num2++].second = res[num2 - 4].second;

				}
				if (num == 1)
				{
					res[num2].first = q[num1 - 1].first;
					res[num2].second = q[num1 - 1].second;
					res[++num2].first = q[num1 - 2].first;
					res[num2].second = q[num1 - 2].second;
					res[++num2].first = q[num1 - 3].first;
					res[num2++].second = q[num1 - 3].second;
				}
				if (num == 3)
				{
					res[num2].first = p[num - 1].first;//1
					res[num2].second = p[num - 1].second;
					res[++num2].first = p[num - 2].first;//1
					res[num2].second = p[num - 2].second;
					res[++num2].first = q[num1 - 1].first;//0
					res[num2].second = q[num1 - 1].second;

					res[++num2].first = p[num - 1].first;//0
					res[num2].second = p[num - 1].second;
					res[++num2].first = p[num - 3].first;//1
					res[num2].second = p[num - 3].second;
					res[++num2].first = q[num1 - 1].first;//1
					res[num2].second = q[num1 - 1].second;

					res[++num2].first = q[num1 - 1].first;
					res[num2].second = q[num1 - 1].second;
					res[++num2].first = p[num - 3].first;//1
					res[num2].second = p[num - 3].second;
					res[++num2].first = p[num - 2].first;//1
					res[num2++].second = p[num - 2].second;
				}
				if (num == 0)
				{
					res[num2].first = q[num1 - 1].first;//0
					res[num2].second = q[num1 - 1].second;
					res[++num2].first = q[num1 - 3].first;//0
					res[num2].second = q[num1 - 3].second;
					res[++num2].first = q[num1 - 2].first;//0
					res[num2].second = q[num1 - 2].second;

					res[++num2].first = q[num1 - 1].first;//1
					res[num2].second = q[num1 - 1].second;
					res[++num2].first = q[num1 - 2].first;//1
					res[num2].second = q[num1 - 2].second;
					res[++num2].first = q[num1 - 4].first;//0
					res[num2].second = q[num1 - 4].second;

					res[++num2].first = q[num1 - 2].first;//0
					res[num2].second = q[num1 - 2].second;
					res[++num2].first = q[num1 - 3].first;//1
					res[num2].second = q[num1 - 3].second;
					res[++num2].first = q[num1 - 4].first;//1
					res[num2].second = q[num1 - 4].second;

					res[++num2].first = q[num1 - 1].first;//0
					res[num2].second = q[num1 - 1].second;
					res[++num2].first = q[num1 - 3].first;//1
					res[num2].second = q[num1 - 3].second;
					res[++num2].first = q[num1 - 4].first;//1
					res[num2++].second = q[num1 - 4].second;
				}
				a[i + 1][j + 1] = '0';
				a[i ][j + 1] = '0';
				a[i + 1][j] = '0';
				a[i][j] = '0';
			}

		}
		cout << (num2+2) / 3 << endl;
		rep(i, 0, num2)
		{
			cout << res[i].first << ' ' << res[i].second;
			if ((i + 1) % 3)
				cout << ' ';
			else cout << endl;

		}
	}
}


#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<map>
#include<set>
#include<queue>
#include<time.h>
#include<algorithm>
#include<utility>
#include <sstream>
#include<iomanip>
#define  rep(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define ff(a,b) for(int a=0;a<b;a++)
#define mod 998244353
#define M_PI  3.14159265358979323846   // pi
using namespace std;
pair<int, int>p[105];
pair<int, int>q[105];
pair<int, int>res[50005];
int main() {
	std::ios::sync_with_stdio(false);
	int t;
	cin >> t;
	while (t--)
	{
		int n, m, num = 0, num1 = 0,num2=0;
		char a[105][105];
		cin >> n >> m;
		rep(i, 1, n + 1)
		{
			rep(j, 1, m + 1)
			{
				cin >> a[i][j];
			}
		}
		for (int  i = 1; i < n; i++)
		{
			for (int j = 1; j < m; j++)
			{
				num = 0;
				num1 = 0;
				if (a[i][j] == '0')
				{
					p[num].first = i;
					p[num].second = j;
					num++;
				}
				else
				{
					q[num1].first = i;
					q[num1].second = j;
					num1++;
				}if (a[i+1][j] == '0')
				{
					p[num].first = i+1;
					p[num].second = j;
					num++;
				}
				else
				{
					q[num1].first = i+1;
					q[num1].second = j;
					num1++;
				}
				if (a[i][j+1] == '0')
				{
					p[num].first = i;
					p[num].second = j+1;
					num++;
				}
				else
				{
					q[num1].first = i;
					q[num1].second = j+1;
					num1++;
				}
				if (a[i+1][j+1] == '0')
				{
					p[num].first = i+1;
					p[num].second = j+1;
					num++;
				}
				else
				{
					q[num1].first = i+1;
					q[num1].second = j+1;
					num1++;
				}
				if (num == 2)
				{

					res[num2].first = p[num - 1].first;
					res[num2].second = p[num - 1].second;
					res[++num2].first= p[num - 2].first;
					res[num2].second = p[num - 2].second;
					res[++num2].first = q[num1 - 1].first;
					res[num2].second = q[num1 - 1].second;

					res[++num2].first = q[num1 - 2].first;
					res[num2].second = q[num1 - 2].second;
					res[++num2].first = res[num2 - 4].first;
					res[num2].second = res[num2 - 4].second;
					res[++num2].first = res[num2 - 4].first;
					res[num2++].second = res[num2 - 4].second;

				}
				if (num == 1)
				{
					res[num2].first = q[num1 - 1].first;
					res[num2].second = q[num1 - 1].second;
					res[++num2].first = q[num1 - 2].first;
					res[num2].second = q[num1 - 2].second;
					res[++num2].first = q[num1 - 3].first;
					res[num2++].second = q[num1 - 3].second;
				}
				if (num == 3)
				{
					res[num2].first = p[num - 1].first;//1
					res[num2].second = p[num - 1].second;
					res[++num2].first = p[num - 2].first;//1
					res[num2].second = p[num - 2].second;
					res[++num2].first = q[num1 - 1].first;//0
					res[num2].second = q[num1 - 1].second;

					res[++num2].first = p[num - 1].first;//0
					res[num2].second = p[num - 1].second;
					res[++num2].first = p[num - 3].first;//1
					res[num2].second = p[num - 3].second;
					res[++num2].first = q[num1 - 1].first;//1
					res[num2].second = q[num1 - 1].second;

					res[++num2].first = q[num1 - 1].first;
					res[num2].second = q[num1 - 1].second;
					res[++num2].first = p[num - 3].first;//1
					res[num2].second = p[num - 3].second;
					res[++num2].first = q[num - 2].first;//1
					res[num2++].second = q[num - 2].second;
				}
				a[i + 1][j + 1] = '0';
				a[i ][j + 1] = '0';
				a[i + 1][j] = '0';
				a[i][j] = '0';
			}

		}
		cout << (num2+2) / 3 << endl;
		rep(i, 0, num2)
		{
			cout << res[i].first << ' ' << res[i].second;
			if ((i + 1) % 3)
				cout << ' ';
			else cout << endl;

		}
	}
}


#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<map>
#include<set>
#include<queue>
#include<time.h>
#include<algorithm>
#include<utility>
#include <sstream>
#include<iomanip>
#define  rep(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define ff(a,b) for(int a=0;a<b;a++)
#define mod 998244353
#define M_PI  3.14159265358979323846   // pi
using namespace std;

pair<int, int>res[50005];
int main() {
	std::ios::sync_with_stdio(false);
	int t;
	cin >> t;
	while (t--)
	{
		int n, m, num = 0, num1 = 0,num2=0;
		char a[105][105];
		cin >> n >> m;
		rep(i, 1, n + 1)
		{
			rep(j, 1, m + 1)
			{
				cin >> a[i][j];
			}
		}
		for (int  i = 1; i < n; i++)
		{
			for (int j = 1; j < m; j++)
			{
				num = 0;
				num1 = 0;
				pair<int, int>p[105];
				pair<int, int>q[105];
				if (a[i][j] == '0')
				{
					p[num].first = i;
					p[num].second = j;
					num++;
				}
				else
				{
					q[num1].first = i;
					q[num1].second = j;
					num1++;
				}if (a[i+1][j] == '0')
				{
					p[num].first = i+1;
					p[num].second = j;
					num++;
				}
				else
				{
					q[num1].first = i+1;
					q[num1].second = j;
					num1++;
				}
				if (a[i][j+1] == '0')
				{
					p[num].first = i;
					p[num].second = j+1;
					num++;
				}
				else
				{
					q[num1].first = i;
					q[num1].second = j+1;
					num1++;
				}
				if (a[i+1][j+1] == '0')
				{
					p[num].first = i+1;
					p[num].second = j+1;
					num++;
				}
				else
				{
					q[num1].first = i+1;
					q[num1].second = j+1;
					num1++;
				}
				if (num == 2)
				{

					res[num2].first = p[num - 1].first;
					res[num2].second = p[num - 1].second;
					res[++num2].first= p[num - 2].first;
					res[num2].second = p[num - 2].second;
					res[++num2].first = q[num1 - 1].first;
					res[num2].second = q[num1 - 1].second;

					res[++num2].first = q[num1 - 2].first;
					res[num2].second = q[num1 - 2].second;
					res[++num2].first = res[num2 - 4].first;
					res[num2].second = res[num2 - 4].second;
					res[++num2].first = res[num2 - 4].first;
					res[num2++].second = res[num2 - 4].second;

				}
				if (num == 1)
				{
					res[num2].first = q[num1 - 1].first;
					res[num2].second = q[num1 - 1].second;
					res[++num2].first = q[num1 - 2].first;
					res[num2].second = q[num1 - 2].second;
					res[++num2].first = q[num1 - 3].first;
					res[num2++].second = q[num1 - 3].second;
				}
				if (num == 3)
				{
					res[num2].first = p[num - 1].first;//1
					res[num2].second = p[num - 1].second;
					res[++num2].first = p[num - 2].first;//1
					res[num2].second = p[num - 2].second;
					res[++num2].first = q[num1 - 1].first;//0
					res[num2].second = q[num1 - 1].second;

					res[++num2].first = p[num - 1].first;//0
					res[num2].second = p[num - 1].second;
					res[++num2].first = p[num - 3].first;//1
					res[num2].second = p[num - 3].second;
					res[++num2].first = q[num1 - 1].first;//1
					res[num2].second = q[num1 - 1].second;

					res[++num2].first = q[num1 - 1].first;
					res[num2].second = q[num1 - 1].second;
					res[++num2].first = p[num - 3].first;//1
					res[num2].second = p[num - 3].second;
					res[++num2].first = p[num - 2].first;//1
					res[num2++].second = p[num - 2].second;
				}
				a[i + 1][j + 1] = '0';
				a[i ][j + 1] = '0';
				a[i + 1][j] = '0';
				a[i][j] = '0';
			}

		}
		cout << (num2+2) / 3 << endl;
		rep(i, 0, num2)
		{
			cout << res[i].first << ' ' << res[i].second;
			if ((i + 1) % 3)
				cout << ' ';
			else cout << endl;

		}
	}
}


#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<cstring>
#include<functional>

using namespace std;

int main()
{
	//freopen("input.txt", "r", stdin);

	int cases;

	scanf("%d", &cases);

	const int dx[2][9] = { { 0,0,1,0,0,1,0,1,1 },{ 0,0,-1,0,0,-1,0,-1,-1 } };
	const int dy[2][9] = { { 0,1,0,0,1,1,0,0,1 },{ 0,-1,0,0,-1,-1,0,0,-1 } };

	for (int tc = 0; tc < cases; tc++)
	{
		int n, m;

		scanf("%d %d", &n, &m);

		vector<string> arr;

		int cnt = 0;

		for (int i = 0; i < n; i++)
		{
			char input[101];

			scanf("%s", input);

			const string str = input;

			arr.push_back(str);

			for (int j = 0; j < m; j++)
			{
				cnt += str[j] - '0';
			}
		}

		printf("%d\n", cnt * 3);

		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < m; j++)
			{
				if (arr[i][j] == '1')
				{
					int xidx = !!i;
					int yidx = !!j;

					for (int k = 0; k < 3; k++)
					{
						for (int l = 0; l < 3; l++)
						{
							printf("%d %d ", i + dx[xidx][k * 3 + l] + 1, j + dy[yidx][k * 3 + l] + 1);
						}

						printf("\n");
					}
				}
			}
		}
	}

	return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <stdint.h>
#include <set>
#include <unordered_map>
#include <map>
#include <bitset>
#include <string>
#include <cmath>
#include <queue>
#include <iterator>
#include <iomanip>
#include <numeric>

#include <random>
#include <functional>

#pragma O3

using namespace std;

#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define forn(i, n) for(int i = 0; i < int(n); i++)

template <class T>
vector<T> ReadVec(const int count, const T inc = 0)
{
	vector<T> res(count);
	forn(i, count)
	{
		std::cin >> res[i];
		res[i] += inc;
	}
	return res;
}

template <class T>
void PrintVecOneLine(const vector<T>& src)
{
	forn(i, src.size())
	{
		std::cout << src[i];
		if (i + 1 != src.size())
			std::cout << " ";
	}
	std::cout << "\n";
}

template <class T>
void PrintVecManyLine(const vector<T>& src)
{
	forn(i, src.size())
	{
		std::cout << src[i] << "\n";
	}
}

int main()
{
#ifdef HOME
	freopen("input.txt", "r", stdin);
#else
	std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);
	std::cout.setf(std::ios::fixed); std::cout.precision(20);
#endif
	int64_t t;
	cin >> t;
	while (t--)
	{
		int64_t n, m;
		cin >> n >> m;
		vector<vector<int>> table(n, vector<int>(m));
		for (size_t i = 0; i < n; ++i)
		{
			string str;
			cin >> str;
			for (size_t j = 0; j < m; ++j)
			{
				table[i][j] = str[j] - '0';
			}
		}
		auto getIdxEq = [&](int startI, int startJ, int val)
		{
			vector<pair<int, int>> idxs;
			for (int i = startI; i < startI + 2; ++i)
			{

				for (int j = startJ; j < startJ + 2; ++j)
				{
					if (table[i][j] == val)
						idxs.emplace_back(i, j);
				}
			}
			return idxs;
		};
		std::vector<std::vector<pair<int, int>> > operations;
		for (int i = 0 ; i < n; i+= 2)
		{
			if (i + 1 == n) {
				i -= 3;
				continue;
			}
			for (int j = 0; j < m; j+= 2)
			{
				if (j + 1 == m) {
					j -= 3;
					continue;
				}
				auto idxs = getIdxEq(i, j, 1);
				while (!idxs.empty())
				{
					if (idxs.size() >= 3)
					{
						operations.push_back(vector<pair<int, int>>());
						for (int k = 0; k < 3; ++k)
						{
							table[idxs[k].first][idxs[k].second] = !table[idxs[k].first][idxs[k].second];
							operations.back().emplace_back(idxs[k].first, idxs[k].second);
						}
					}
					else if (idxs.size() == 2)
					{
						operations.push_back(vector<pair<int, int>>());
						auto zeroIdx = getIdxEq(i, j, 0);
						for (auto z : zeroIdx) {
							table[z.first][z.second] = !table[z.first][z.second];
							operations.back().emplace_back(z.first, z.second);
						}
						table[idxs[0].first][idxs[0].second] = !table[idxs[0].first][idxs[0].second];
						operations.back().emplace_back(idxs[0].first, idxs[0].second);
					}
					else if (idxs.size() == 1)
					{
						operations.push_back(vector<pair<int, int>>());
						auto zeroIdx = getIdxEq(i, j, 0);
						for (int k = 0; k < 2; ++k) {
							auto z = zeroIdx[k];
							table[z.first][z.second] = !table[z.first][z.second];
							operations.back().emplace_back(z.first, z.second);
						}
						table[idxs[0].first][idxs[0].second] = !table[idxs[0].first][idxs[0].second];
						operations.back().emplace_back(idxs[0].first, idxs[0].second);
					}
					idxs = getIdxEq(i, j, 1);
				}
			}
		}
		cout << operations.size() << "\n";
		for (auto op : operations)
		{
			for (auto pr : op)
			{
				cout << pr.first << " " << pr.second << " ";
			}
			cout << "\n";
		}
	}
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <stdint.h>
#include <set>
#include <unordered_map>
#include <map>
#include <bitset>
#include <string>
#include <cmath>
#include <queue>
#include <iterator>
#include <iomanip>
#include <numeric>

#include <random>
#include <functional>

#pragma O3

using namespace std;

#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define forn(i, n) for(int i = 0; i < int(n); i++)

template <class T>
vector<T> ReadVec(const int count, const T inc = 0)
{
	vector<T> res(count);
	forn(i, count)
	{
		std::cin >> res[i];
		res[i] += inc;
	}
	return res;
}

template <class T>
void PrintVecOneLine(const vector<T>& src)
{
	forn(i, src.size())
	{
		std::cout << src[i];
		if (i + 1 != src.size())
			std::cout << " ";
	}
	std::cout << "\n";
}

template <class T>
void PrintVecManyLine(const vector<T>& src)
{
	forn(i, src.size())
	{
		std::cout << src[i] << "\n";
	}
}

int main()
{
#ifdef HOME
	freopen("input.txt", "r", stdin);
#else
	std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);
	std::cout.setf(std::ios::fixed); std::cout.precision(20);
#endif
	int64_t t;
	cin >> t;
	while (t--)
	{
		int64_t n, m;
		cin >> n >> m;
		vector<vector<int>> table(n, vector<int>(m));
		for (size_t i = 0; i < n; ++i)
		{
			string str;
			cin >> str;
			for (size_t j = 0; j < m; ++j)
			{
				table[i][j] = str[j] - '0';
			}
		}
		auto getIdxEq = [&](int startI, int startJ, int val)
		{
			vector<pair<int, int>> idxs;
			for (int i = startI; i < startI + 2; ++i)
			{

				for (int j = startJ; j < startJ + 2; ++j)
				{
					if (table[i][j] == val)
						idxs.emplace_back(i, j);
				}
			}
			return idxs;
		};
		std::vector<std::vector<pair<int, int>> > operations;
		for (int i = 0 ; i < n; i+= 2)
		{
			if (i + 1 == n) {
				i -= 3;
				continue;
			}
			for (int j = 0; j < m; j+= 2)
			{
				if (j + 1 == m) {
					j -= 3;
					continue;
				}
				auto idxs = getIdxEq(i, j, 1);
				while (!idxs.empty())
				{
					if (idxs.size() >= 3)
					{
						operations.push_back(vector<pair<int, int>>());
						for (int k = 0; k < 3; ++k)
						{
							table[idxs[k].first][idxs[k].second] = !table[idxs[k].first][idxs[k].second];
							operations.back().emplace_back(idxs[k].first, idxs[k].second);
						}
					}
					else if (idxs.size() == 2)
					{
						operations.push_back(vector<pair<int, int>>());
						auto zeroIdx = getIdxEq(i, j, 0);
						for (auto z : zeroIdx) {
							table[z.first][z.second] = !table[z.first][z.second];
							operations.back().emplace_back(z.first, z.second);
						}
						table[idxs[0].first][idxs[0].second] = !table[idxs[0].first][idxs[0].second];
						operations.back().emplace_back(idxs[0].first, idxs[0].second);
					}
					else if (idxs.size() == 1)
					{
						operations.push_back(vector<pair<int, int>>());
						auto zeroIdx = getIdxEq(i, j, 0);
						for (int k = 0; k < 2; ++k) {
							auto z = zeroIdx[k];
							table[z.first][z.second] = !table[z.first][z.second];
							operations.back().emplace_back(z.first, z.second);
						}
						table[idxs[0].first][idxs[0].second] = !table[idxs[0].first][idxs[0].second];
						operations.back().emplace_back(idxs[0].first, idxs[0].second);
					}
					idxs = getIdxEq(i, j, 1);
				}
			}
		}
		cout << operations.size() << "\n";
		for (auto op : operations)
		{
			for (auto pr : op)
			{
				cout << pr.first + 1 << " " << pr.second + 1 << " ";
			}
			cout << "\n";
		}
	}
	return 0;
}


#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
#include <chrono>
#include<unordered_map>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(u) (u).begin(),(u).end()

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define LL long long
#define ULL unsigned LL
#define LD long double

typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef tuple<int, int, int> TIII;
typedef vector<int> VI;

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

void fast_io() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const int MR = 110;

char s[MR][MR];

vector<vector<PII>> go(int r, int c)
{
    // kwadrat 2x2 zaczynajacy sie w r i c
    vector<vector<PII>> res;

    int ile = 0;
    REP(i, 2)REP(j, 2)
        if (s[r + i][c + j] == '1')
            ile++;

    if (ile == 4)
    {
        vector<PII> mv;
        mv.push_back(MP(r, c));
        mv.push_back(MP(r, c + 1));
        mv.push_back(MP(r + 1, c));

        for (const auto &p : mv)
            s[p.first][p.second] = '0';

        res.push_back(mv);

        ile = 1;
    }

    if (ile == 1)
    {
        vector<PII> mv;
        REP(i, 2)REP(j, 2)
            if (s[r + i][c + j] == '0' && mv.size() < 2)
                mv.push_back(MP(r + i, c + j));

        REP(i, 2)REP(j, 2)
            if (s[r + i][c + j] == '1')
                mv.push_back(MP(r + i, c + j));

        for (const auto &p : mv)
            s[p.first][p.second] = 1 - (s[p.first][p.second] - '0') + '0';

        res.push_back(mv);

        ile = 2;
    }

    if (ile == 2)
    {
        vector<PII> mv;
        REP(i, 2)REP(j, 2)
            if (s[r + i][c + j] == '0')
                mv.push_back(MP(r + i, c + j));

        REP(i, 2)REP(j, 2)
            if (s[r + i][c + j] == '1' && mv.size() < 3)
                mv.push_back(MP(r + i, c + j));

        for (const auto &p : mv)
            s[p.first][p.second] = 1 - (s[p.first][p.second] - '0') + '0';

        res.push_back(mv);

        ile = 3;
    }

    if (ile == 3)
    {
        vector<PII> mv;
        REP(i, 2)REP(j, 2)
            if (s[r + i][c + j] == '1')
            {
                mv.push_back(MP(r + i, c + j));
                s[r + i][c + j] = '0';
            }

        res.push_back(mv);
        ile = 0;
    }

    return res;
}

int main()
{
    fast_io();

    int T;
    scanf("%d", &T);
    REP(xxx, T)
    {
        int n, m;
        scanf("%d%d", &n, &m);
        REP(i, n)
            scanf("%s", s[i]);

        vector<vector<PII>> res;

        // bez ostatnich 2 wierszy jedz zachlannie
        REP(i, n - 2)
        {
            REP(j, m - 1)
                if (s[i][j] == '1')
                {
                    set<PII> mv;
                    mv.insert(MP(i, j));

                    if (s[i][j + 1] == '1')
                        mv.insert(MP(i, j + 1));

                    REP(add, 2)
                        if (mv.size() < 3 && s[i + 1][j + add] == '1')
                            mv.insert(MP(i + 1, j + add));

                    REP(add, 2)
                        if (mv.size() < 3)
                            mv.insert(MP(i + 1, j + add));

                    vector<PII> tmp;
                    for (const auto &p : mv)
                    {
                        s[p.first][p.second] = 1 - (s[p.first][p.second] - '0') + '0';
                        tmp.push_back(p);
                    }

                    res.push_back(tmp);
                }

            // ostatnia kolumna
            if (s[i][m - 1] == '1')
            {
                vector<PII> mv;
                mv.push_back(MP(i, m - 1));
                s[i][m - 1] = '0';

                REP(sub, 2)
                {
                    mv.push_back(MP(i + 1, m - 1 - sub));
                    s[i + 1][m - 1 - sub] = 1 - (s[i + 1][m - 1 - sub] - '0') + '0';
                }

                res.push_back(mv);
            }
        }

        // ostatnie 2 wiersze, bez ostatniego kwadratu 2x2
        REP(i, m - 2)
            if (s[n - 2][i] == '1' || s[n - 1][i] == '1')
            {
                set<PII> mv;
                REP(sub, 2)
                    if (s[n - sub - 1][i] == '1')
                        mv.insert(MP(n - sub - 1, i));

                REP(sub, 2)
                    if (mv.size() < 3 && s[n - sub - 1][i + 1] == '1')
                        mv.insert(MP(n - sub - 1, i + 1));

                REP(sub, 2)
                    if (mv.size() < 3)
                        mv.insert(MP(n - sub - 1, i + 1));

                vector<PII> tmp;
                for (const auto &p : mv)
                {
                    s[p.first][p.second] = 1 - (s[p.first][p.second] - '0') + '0';
                    tmp.push_back(p);
                }

                res.push_back(tmp);
            }

        // ostatni kwadrat 2x2
        auto add = go(n - 2, m - 2);

        for (const auto& e : add)
            res.push_back(e);

        printf("%d\n", res.size());
        for (const auto& mv : res)
            printf("%d %d %d %d %d %d\n", mv[0].first + 1, mv[0].second + 1, mv[1].first + 1, mv[1].second + 1, mv[2].first + 1, mv[2].second + 1);

    }

    return 0;
}

// FOR GNU C++ use the following pattern:
// Uncomment the code below and change your main into main2
// It does not build in MS C++
// But it does increase the stack size from 256 MB on CF and uses GNU C++

//#include <Processthreadsapi.h>
//#include <iostream>
//#include <Synchapi.h>
//#include <windows.h>
//#include <process.h>
//
//DWORD WINAPI MyThreadFunction(LPVOID lpParam) {
//    main2(nullptr);
//    return 0;
//}
//int main() {
//    auto h = CreateThread(nullptr, 1024 << 20, MyThreadFunction, nullptr, STACK_SIZE_PARAM_IS_A_RESERVATION, nullptr);
//    WaitForSingleObject(h, INFINITE);
//}


#include<iostream>
#include<stack>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<math.h>
#include<functional>
#include<limits.h>
#include<utility>
#include<queue>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<bitset>
#define lowbit(x) ((x)&(-x))
typedef long long ll;
//
const int maxn = 100 + 10;
const int maxm = 4e5 + 10;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9+7;
const double eps = 1e-7;
using namespace std;
typedef pair<int, int> pii;
/*ll gcd(ll a, ll b)//���Լ��
{
return b == 0 ? a : gcd(b, a%b);
}
ll lcm(ll a, ll b)
{
return a / gcd(a, b)*b;
}
ll fast_pow(ll a, ll k)//������
{
ll ans = 1;
a = a%mod;
while (k != 0)
{
if (k & 1) ans = (ans*a) % mod;
k >>= 1;
a = (a*a) % mod;
}
return ans;
}
ll C(ll n, ll m)
{
return ((fac[n] * fast_pow(fac[m], mod - 2))%mod*fast_pow(fac[n - m], mod - 2)%mod);
}

bool is_prime(ll x)//�����ж�
{
if (x == 2 || x == 3) return true;
if (x % 6 != 1 && x % 6 != 5) return false;
ll temp = sqrt(1.0*x);
for (ll i = 5;i <= temp;i += 6)
if (x%i == 0 || x % (i + 2) == 0) return false;
return true;
}
int prime[maxm], pnum = 0;//������pnum������
bool p[maxm] = { 0 };//�����ɸ������Ϊtrue
void Find_Prime()//�����ɸѡ��������һ���������Ͱ����ı���ȫ��ɸ��
{
for (int i = 2;i < maxm;i++)
{
if (p[i] == false)//����һ����һ�������ж�������
{
prime[pnum++] = i;
for (int j = i + i;j < maxm;j += i)//ɸ�������ı���
p[j] = true;
}
}
}

void Exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) x = 1, y = 0;
else Exgcd(b, a % b, y, x), y -= a / b * x;
}//x��a��mod b�µ���Ԫ
ll CRT(int a[],int m[],int n)
{
ll M=1,ans=0,t,x,y;
for(int i=0; i<n; i++)
{
M*=m[i];///MΪ�����˻�
}
for(int i=0; i<n; i++)
{
t=M/m[i];///����mi�����n-1�������˻�
Exgcd(t,m[i],x,y);///����Ԫ������չŷ�����ת����t*ti+m[i]*y=1����ti
ans=(ans+a[i]*x*t)%M;
}
return (ans+M)%M;
}
struct Edge
{
int to, next;
}edge[maxn<<1];
int cnt, head[maxn];
void add_edge(int u, int v)
{
edge[++cnt].next = head[u];
edge[cnt].to = v;
head[u] = cnt;
}*/

int n, m;
char c[maxn][maxn];
int a[maxn][maxn], d[maxn][maxn];
int x, y;
void solve(int p)
{
	if (p == 1)
	{
		cout << x << " " << y << " " << x + 1 << " " << y << " " << x << " " << y + 1 << endl;
		cout << x << " " << y << " " << x + 1 << " " << y << " " << x + 1 << " " << y + 1 << endl;
		cout << x << " " << y << " " << x << " " << y + 1 << " " << x + 1 << " " << y + 1 << endl;
	}
	else if (p == 2)
	{
		cout << x << " " << y << " " << x + 1 << " " << y << " " << x << " " << y - 1 << endl;
		cout << x << " " << y << " " << x + 1 << " " << y << " " << x + 1 << " " << y - 1 << endl;
		cout << x << " " << y << " " << x << " " << y - 1 << " " << x + 1 << " " << y - 1 << endl;

	}
	else if (p == 3)
	{
		cout << x << " " << y << " " << x - 1 << " " << y << " " << x << " " << y + 1 << endl;
		cout << x << " " << y << " " << x - 1 << " " << y << " " << x - 1 << " " << y + 1 << endl;
		cout << x << " " << y << " " << x << " " << y + 1 << " " << x - 1 << " " << y + 1 << endl;

	}
	else
	{
		cout << x << " " << y << " " << x - 1 << " " << y << " " << x << " " << y - 1 << endl;
		cout << x << " " << y << " " << x - 1 << " " << y << " " << x - 1 << " " << y - 1 << endl;
		cout << x << " " << y << " " << x << " " << y - 1 << " " << x - 1 << " " << y - 1 << endl;

	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int T;
	cin >> T;
	while(T--)
	{
		cin >> n >> m;
		for (int i = 2; i <= n-1; i++)
			for (int j = 2; j <= m-1; j++)
				a[i][j] = 1;
		for (int i = 1; i <= n-1; i++)
			a[i][1] = 1;
		for (int i = 2; i <= m; i++)
			a[1][i] = 2;
		for (int i = 1; i <= m-1; i++)
			a[n][i] = 3;
		for (int i = 2; i <= n; i++)
			a[i][m] = 4;
		int cnt = 0;
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= m; j++)
			{
				cin >> c[i][j];
				if (c[i][j] == '1')  cnt++;
			}

		cout << 3 * cnt << endl;
		for (int i = 1; i <= n; i++)
		{
			for (int j = 1; j <= m; j++)
			{
				if (c[i][j] == '1')
				{
					x = i; y = j;
					solve(a[i][j]);
				}
			}
		}
	}

	return ~~(0 - 0);
}


#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include "stdio.h"

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
#define mp(x,y) make_pair(x,y)

// input

void read(ll a[], int s, int n) {
	for (int i = 0 + s; i < n + s; ++i) {
		scanf("%ll", &a[i]);
	}
}

void read(int a[], int s, int n) {
	for (int i = 0 + s; i < n + s; ++i) {
		scanf("%d", &a[i]);
	}
}

// fenwick

ll getSum(ll bits[], int index)
{
	ll sum = 0;
	while (index > 0)
	{
		sum += bits[index];
		index -= index & (-index);
	}
	return sum;
}

void updateAt(ll bits[], int n, int index, ll val)
{
	while (index <= n)
	{
		bits[index] += val;
		index += index & (-index);
	}
}

static const int MX_VAL = 1e6 + 2;
ll bits[MX_VAL + 1] = {};

// inversions

ll getInvCnt(ll a[], int n)
{
	ll cnt = 0;
	memset(bits, 0, sizeof(bits));
	for (int i = n - 1; i >= 0; i--)
	{
		cnt += getSum(bits, a[i] - 1);
		updateAt(bits, MX_VAL, a[i], 1);
	}

	return cnt;
}

const int N = 200;
string s[N];
vector<vector<int>> res;
void invert(int x, int y) {
	if (res.empty() || res.back().size() == 6)
		res.push_back({});
	if (s[x][y] == '0')
		s[x][y] = '1';
	else
		s[x][y] = '0';

	res.back().push_back(x);
	res.back().push_back(y);
}

void solve_case()
{
	int n, m;
	cin >> n >> m;
	res.clear();
	for (int i = 0; i < n; ++i)
		cin >> s[i];

	for (int i = 0; i < n-1; i++)
		for (int j = 0; j < m - 1; j++) {
			if (s[i][j] == '0' && s[i + 1][j] == '0') continue;
			if (s[i][j] == '1' && s[i + 1][j] == '1') {
				invert(i, j);
				invert(i + 1, j);
				invert(i + 1, j + 1);
			}
			if (s[i][j] == '0' && s[i + 1][j] == '1') {
				invert(i, j+1);
				invert(i + 1, j);
				invert(i + 1, j + 1);
			}
			if (s[i][j] == '1' && s[i + 1][j] == '0') {
				invert(i, j);
				invert(i, j+1);
				invert(i + 1, j + 1);
			}
		}
	int j = m - 2;
	for (int i = 0; i < n - 1; i++)
	{
		if (s[i][j] == '0' && s[i][j+1] == '0') continue;
		if (s[i][j] == '1' && s[i][j+1] == '1') {
			invert(i, j);
			invert(i, j + 1);
			invert(i + 1, j + 1);
		}
		if (s[i][j] == '0' && s[i][j+1] == '1') {
			invert(i, j + 1);
			invert(i + 1, j);
			invert(i + 1, j + 1);
		}
		if (s[i][j] == '1' && s[i][j+1] == '0') {
			invert(i, j);
			invert(i + 1, j);
			invert(i + 1, j + 1);
		}
	}
	int i = n - 1;
	j = m - 2;
	if (s[i][j] == '0' && s[i][j + 1] == '0') {
	}
	else  if (s[i][j] == '1' && s[i][j + 1] == '1') {
		invert(i-1, j);
		invert(i-1, j+1);
		invert(i, j);

		invert(i - 1, j);
		invert(i - 1, j + 1);
		invert(i, j+1);
	}
	if (s[i][j] == '0' && s[i][j + 1] == '1') {
		invert(i, j+1);
		invert(i - 1, j + 1);
		invert(i - 1, j);

		invert(i, j);
		invert(i, j + 1);
		invert(i - 1, j + 1);

		invert(i, j);
		invert(i, j + 1);
		invert(i-1, j);

	}
	if (s[i][j] == '1' && s[i][j + 1] == '0') {
		invert(i, j );
		invert(i - 1, j + 1);
		invert(i - 1, j);

		invert(i, j);
		invert(i, j + 1);
		invert(i - 1, j + 1);

		invert(i, j);
		invert(i, j + 1);
		invert(i - 1, j);
	}

	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j)
			if (s[i][j] == '1')
				throw 34;
	cout << res.size() << endl;
	for (int i = 0; i < res.size(); ++i) {
		for (auto x : res[i]) cout << x + 1<< " ";
		cout << endl;
	}
	cout << endl;
}

void prepare()
{
	cout << (1 << 25) << endl;
	int y = 0;
	cout << 100000 << endl;
	for (int i = 0; i < 1 << 20 && y++ < 100000; ++i) {
		int k = (1 << 20) - i;
		vector<string> s(5, "00000");
		int p = 0;
		cout << "5 5" << endl;
		while (k) {
			s[p % 5][p / 5] = '0' + (k % 2);
			k /= 2;
			p++;
		}
		for (int i = 0; i < 5; ++i)
			cout << s[i] << endl;
	}
}

int main()
{
#ifdef __OLIMP__
	freopen("input.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif

	int T = 1;
	scanf("%d", &T);
	//prepare();
	for (int tc = 1; tc <= T; tc++)
		solve_case();

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include "stdio.h"

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
#define mp(x,y) make_pair(x,y)

// input

void read(ll a[], int s, int n) {
	for (int i = 0 + s; i < n + s; ++i) {
		scanf("%ll", &a[i]);
	}
}

void read(int a[], int s, int n) {
	for (int i = 0 + s; i < n + s; ++i) {
		scanf("%d", &a[i]);
	}
}

// fenwick

ll getSum(ll bits[], int index)
{
	ll sum = 0;
	while (index > 0)
	{
		sum += bits[index];
		index -= index & (-index);
	}
	return sum;
}

void updateAt(ll bits[], int n, int index, ll val)
{
	while (index <= n)
	{
		bits[index] += val;
		index += index & (-index);
	}
}

static const int MX_VAL = 1e6 + 2;
ll bits[MX_VAL + 1] = {};

// inversions

ll getInvCnt(ll a[], int n)
{
	ll cnt = 0;
	memset(bits, 0, sizeof(bits));
	for (int i = n - 1; i >= 0; i--)
	{
		cnt += getSum(bits, a[i] - 1);
		updateAt(bits, MX_VAL, a[i], 1);
	}

	return cnt;
}

const int N = 200;
string s[N];
vector<vector<int>> res;
void invert(int x, int y) {
	if (res.empty() || res.back().size() == 6)
		res.push_back({});
	if (s[x][y] == '0')
		s[x][y] = '1';
	else
		s[x][y] = '0';

	res.back().push_back(x);
	res.back().push_back(y);
}

void solve_case()
{
	int n, m;
	cin >> n >> m;
	res.clear();
	for (int i = 0; i < n; ++i)
		cin >> s[i];

	for (int i = 0; i < n-1; i++)
		for (int j = 0; j < m - 1; j++) {
			if (s[i][j] == '0' && s[i + 1][j] == '0') continue;
			if (s[i][j] == '1' && s[i + 1][j] == '1') {
				invert(i, j);
				invert(i + 1, j);
				invert(i + 1, j + 1);
			}
			if (s[i][j] == '0' && s[i + 1][j] == '1') {
				invert(i, j+1);
				invert(i + 1, j);
				invert(i + 1, j + 1);
			}
			if (s[i][j] == '1' && s[i + 1][j] == '0') {
				invert(i, j+1);
				invert(i + 1, j);
				invert(i + 1, j + 1);
			}
		}
	int j = n - 2;
	for (int i = 0; i < n - 1; i++)
	{
		if (s[i][j] == '0' && s[i][j+1] == '0') continue;
		if (s[i][j] == '1' && s[i][j+1] == '1') {
			invert(i, j);
			invert(i, j + 1);
			invert(i + 1, j + 1);
		}
		if (s[i][j] == '0' && s[i][j+1] == '1') {
			invert(i, j + 1);
			invert(i + 1, j);
			invert(i + 1, j + 1);
		}
		if (s[i][j] == '1' && s[i][j+1] == '0') {
			invert(i, j);
			invert(i + 1, j);
			invert(i + 1, j + 1);
		}
	}
	int i = n - 1;
	j = m - 2;
	if (s[i][j] == '0' && s[i][j + 1] == '0') {
	}
	else  if (s[i][j] == '1' && s[i][j + 1] == '1') {
		invert(i-1, j);
		invert(i-1, j+1);
		invert(i, j);

		invert(i - 1, j);
		invert(i - 1, j + 1);
		invert(i, j+1);
	}
	if (s[i][j] == '0' && s[i][j + 1] == '1') {
		invert(i, j+1);
		invert(i - 1, j + 1);
		invert(i - 1, j);

		invert(i, j);
		invert(i, j + 1);
		invert(i - 1, j + 1);

		invert(i, j);
		invert(i, j + 1);
		invert(i-1, j);

	}
	if (s[i][j] == '1' && s[i][j + 1] == '0') {
		invert(i, j );
		invert(i - 1, j + 1);
		invert(i - 1, j);

		invert(i, j);
		invert(i, j + 1);
		invert(i - 1, j + 1);

		invert(i, j);
		invert(i, j + 1);
		invert(i - 1, j);
	}

	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j)
			if (s[i][j] == '1')
				throw 34;
	cout << res.size() << endl;
	for (int i = 0; i < res.size(); ++i) {
		for (auto x : res[i]) cout << x + 1<< " ";
		cout << endl;
	}
	cout << endl;
}

void prepare()
{

}

int main()
{
#ifdef __OLIMP__
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int T = 1;
	scanf("%d", &T);
	//prepare();
	for (int tc = 1; tc <= T; tc++)
		solve_case();

	return 0;
}