package main

import (
	"fmt"
	"math"
)

func main() {
	var n, nl int
	var s1, s2 string
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&nl)
		fmt.Scan(&s1)
		fmt.Scan(&s2)
		a, b, c, d := 0,0,0,0

		for j, _ := range s1 {
			if s1[j] == '0' {
				if s2[j] == '0' {
					a++
				} else {
					b++
				}
			} else {
				if s2[j] == '0' {
					c++
				} else {
					d++
				}
			}
		}

		res := math.MaxInt
		if b == c {
			res = min(res, b+c)
		}
		if (d - a == 1) {
			res = min(res, d + a)
		}

		if res == math.MaxInt {
			fmt.Println(-1)
		} else {
			fmt.Println(res)
		}
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}

	return b
}

package main

import (
	"bufio"
	"os"
	"fmt"
)

const MOD int64 = 1000000007

var n int

var a, b string

// ByAge implements sort.Interface based on the Age field.
type ByV []*pair

func (a ByV) Len() int           { return len(a) }
func (a ByV) Less(i, j int) bool { return a[i].v < a[j].v }
func (a ByV) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {

	read := bufio.NewReader(os.Stdin)

	var t int
	fmt.Fscan(read, &t)

	for i := 0; i < t; i++ {

		fmt.Fscan(read, &n)

		fmt.Fscan(read, &a, &b)

		fmt.Println(solve())
	}
}

type pair struct {
	v int
	idx []int
}

func solve() int {

	EvenLitOnes := 0
	EvenLitZeros := 0

	oddLitOnes := 0
	oddLitZeroes := 0
	ev := 0
	odd := 0

	for i := 0; i < n; i++ {
		if a[i] == b[i] {
			ev++
			if a[i] == '1' {
				EvenLitOnes++
			} else {
				EvenLitZeros++
			}
		} else {
			odd++
			if a[i] == '1' {
				oddLitOnes++
			} else {
				oddLitZeroes++
			}
		}
	}

	var a int = 1e9
	var b int = 1e9

	if ev % 2 == 1 && EvenLitOnes - EvenLitZeros == 1 {
		a = ev
	}

	if odd % 2 == 0 && oddLitOnes == oddLitZeroes {
		b = odd
	}

	c := min(a, b)

	if c == 1e9 {
		return -1
	}

	return c
}

func min(a, b int) int {
	if a < b {
		return a
	}

	return b
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
)

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func scan(a ...interface{})             { fmt.Fscan(reader, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func main() {
	defer writer.Flush()
// 	redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

func solve() {
	var (
		n    int
		a, b string
	)
	scan(&n, &a, &b)

	var cnt [4]int
	for i := range a {
		cnt[((a[i]-'0')<<1)|(b[i]-'0')]++
	}

	var (
		q = list.New()
		d = make(map[[4]int]int)
	)
	q.PushBack(cnt)
	d[cnt] = 0
	for q.Len() > 0 {
		curr := q.Remove(q.Front()).([4]int)
		nexts := make([][4]int, 0, 2)
		if curr[0b11] > 0 {
			next := curr
			next[0b11], next[0b01] = next[0b01]+1, next[0b11]-1
			next[0b10], next[0b00] = next[0b00], next[0b10]
			nexts = append(nexts, next)
		}
		if curr[0b10] > 0 {
			next := curr
			next[0b10], next[0b00] = next[0b00]+1, next[0b10]-1
			next[0b11], next[0b01] = next[0b01], next[0b11]
			nexts = append(nexts, next)
		}
		for _, next := range nexts {
			if _, ok := d[next]; ok {
				continue
			}
			d[next] = d[curr] + 1
			q.PushBack(next)
		}
	}
	var ans = 1 << 30
	for k, v := range d {
		if k[0b01] == 0 && k[0b10] == 0 && ans > v {
			ans = v
		}
	}
	if ans == 1<<30 {
		ans = -1
	}
	printf("%v\n", ans)
}

package main

import (
	"bufio"
	"errors"
	"fmt"
	"os"
)

var (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
	er  = bufio.NewWriter(os.Stderr)
)

func lit(mode int, a []int) ([]int, error) {
	var res []int
	if mode == 0 {
		res = []int{a[2] - 1, a[3], a[0] + 1, a[1]}
	} else {
		res = []int{a[2], a[3] - 1, a[0], a[1] + 1}
	}
	for i := 0; i < 4; i++ {
		if res[i] < 0 {
			return nil, errors.New("Can no longer litDiff")
		}
	}
	return res, nil
}

func complete(a []int) bool {
	return a[1] == 0 && a[2] == 0
}

func solve(t int) {
	_ = readInt()
	a := readString()
	b := readString()

	if a == b {
		println(0)
		return
	}

	initial := make([]int, 4)
	for i := 0; i < len(a); i++ {
		if a[i] == '0' && b[i] == '0' {
			initial[0]++
		} else if a[i] == '0' && b[i] == '1' {
			initial[1]++
		} else if a[i] == '1' && b[i] == '0' {
			initial[2]++
		} else if a[i] == '1' && b[i] == '1' {
			initial[3]++
		} else {
			panic("Should not happen")
		}
	}

	res := -1

	for starting := 0; starting < 2; starting++ {
		arr := initial
		var err error
		steps := 0
		for mode := starting; !complete(arr); mode = 1 - mode {
			arr, err = lit(mode, arr)
			steps += 1
			if err != nil {
				break
			}
		}
		if err == nil && (steps < res || res == -1) {
			res = steps
		}
	}
	println(res)
}

func main() {
	var t int
	fmt.Fscan(in, &t)

	for i := 0; i < t; i++ {
		solve(i)
	}
}

// READ
func readInt() int {
	var res int
	fmt.Fscan(in, &res)
	return res
}

func readInt64() int64 {
	var res int64
	fmt.Fscan(in, &res)
	return res
}

func readString() string {
	var res string
	fmt.Fscan(in, &res)
	return res
}

// PRINT
func print(args ...interface{}) {
	fmt.Fprint(out, args...)
	out.Flush()
}

func println(args ...interface{}) {
	fmt.Fprintln(out, args...)
	out.Flush()
}

func printErr(args ...interface{}) {
	fmt.Fprint(er, args...)
	er.Flush()
}

func printlnErr(args ...interface{}) {
	fmt.Fprintln(er, args...)
	er.Flush()
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

func solveEven(same, dif int) int {
	if dif%2 == 0 {
		return dif
	}
	return same + dif + 1
}

func solveOdd(same, dif int) int {
	if same%2 == 1 {
		return same
	}
	return same + dif + 1
}

func solve() int {
	var a, b string
	var n int
	var cnt1a = 0
	var cnt1b = 0
	var same = 0
	var dif = 0
	fmt.Fscan(in, &n, &a, &b)
	var ans0 = n + 1
	var ans1 = n + 1
	for i := 0; i < n; i++ {
		if a[i] == b[i] {
			same++
		} else {
			dif++
		}
		if a[i] == '1' {
			cnt1a++
		}
		if b[i] == '1' {
			cnt1b++
		}
	}
	if cnt1a == cnt1b {
		ans0 = solveEven(same, dif)
	}
	if cnt1a == 1+(n-cnt1b) {
		ans1 = solveOdd(same, dif)
	}
	if ans0 < ans1 {
		return ans0
	}
	if ans1 > n {
		return -1
	}
	return ans1
}

func main() {
	var ntc int
	fmt.Fscan(in, &ntc)
	for t := 0; t < ntc; t++ {
		fmt.Fprintf(out, "%d\n", solve())
	}
	out.Flush()
}

package main

import "fmt"

func main() {
	var n, nl int
	var s1, s2 string
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&nl)
		fmt.Scan(&s1)
		fmt.Scan(&s2)

		if checkZero(s1) || checkZero(s2) {
			fmt.Println(-1)
			continue
		}

		xLast := s1[0]
		cnt := 0
		for j, _ := range s1 {
			if s1[j] != s2[j] {
				if xLast != s2[j] {
					cnt++
				}
				xLast = s2[j]
			}
		}

		fmt.Println(cnt)
	}
}

func checkZero(str string) bool {
	for _, elem := range str {
		if elem == '1' {
			return false
		}
	}

	return true
}

package main

import (
	"bufio"
	"os"
	"fmt"
)

const MOD int64 = 1000000007

var n int

var a, b string

// ByAge implements sort.Interface based on the Age field.
type ByV []*pair

func (a ByV) Len() int           { return len(a) }
func (a ByV) Less(i, j int) bool { return a[i].v < a[j].v }
func (a ByV) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {

	read := bufio.NewReader(os.Stdin)

	var t int
	fmt.Fscan(read, &t)

	for i := 0; i < t; i++ {

		fmt.Fscan(read, &n)

		fmt.Fscan(read, &a, &b)

		fmt.Println(solve())
	}
}

type pair struct {
	v int
	idx []int
}

func solve() int {

	if a == b {
		return 0
	}

	hasEvLit := false
	hasOddLit := false
	ev := 0
	odd := 0

	for i := 0; i < n; i++ {
		if a[i] == b[i] {
			ev++
			if a[i] == '1' {
				hasEvLit = true
			}
		} else {
			odd++
			if a[i] == '1' {
				hasOddLit = true
			}
		}
	}

	var a int = 1e9
	var b int = 1e9

	if ev % 2 == 1 && hasEvLit {
		a = ev
	}

	if odd % 2 == 0 && hasOddLit {
		b = odd
	}

	c := min(a, b)

	if c == 1e9 {
		return -1
	}

	return c
}

func min(a, b int) int {
	if a < b {
		return a
	}

	return b
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}


package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func Next() string {
	sc.Scan()
	return sc.Text()
}

func NextInt() int {
	i, err := strconv.Atoi(Next())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	for tt := NextInt(); tt > 0; tt-- {
		n, m := NextInt(), NextInt()
		sum := 0
		for i := 0; i < n; i++ {
			sum += NextInt()
		}
		if sum == m {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	"fmt"
)

func checksum(arr [100]float64, n int, m float64) bool {
	var sum float64
	for i := 0; i < n; i++ {
		sum += arr[i]
	}
	if sum == m {
		return true
	} else {
		return false
	}
}

func main() {
	var t, n int
	var m float64
	var arr [100]float64
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scan(&n)
		fmt.Scan(&m)
		for j := 0; j < n; j++ {
			fmt.Scan(&arr[j])
		}
		if checksum(arr, n, m) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	"fmt"
	"os"
)

func cin(a ...interface{}) (n int, err error) {
	return fmt.Fscan(os.Stdin, a...)
}
func cout(a ...interface{}) (n int, err error) {
	return fmt.Fprintln(os.Stdout, a...)
}
func main() {
	t := 0
	cin(&t)
	for c := 0; c < t; c++ {
		n, m := 0, 0
		cin(&n, &m)
		sum, x := 0, 0
		for i := 0; i < n; i++ {
			cin(&x)
			sum += x
		}
		if sum == m {
			cout("YES")
		} else {
			cout("NO")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var read = bufio.NewReader(os.Stdin)

func scanf(format string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(read, format, a...)
}

func println(a ...interface{}) (n int, err error) {
	return fmt.Fprintln(os.Stdout, a...)
}
func main() {
	t := 0
	fmt.Scan(&t)
	for c := 0; c < t; c++ {
		n, m := 0, 0
		fmt.Scan(&n, &m)
		sum:=0
		for i:=0; i<n;i++{
			x:=0
			fmt.Scan(&x)
			sum+=x
		}
		if sum==m{
			fmt.Println("YES")
		}else{
			fmt.Println("NO")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	t     int8
	n     int8
	m     int32
	count int32
	a     int32
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	fmt.Fscan(reader, &t)

	for ; t > 0; t-- {
		fmt.Fscan(reader, &n, &m)

		//arr := make([]int32, n)
		count = 0

		for ; n > 0; n-- {
			fmt.Fscan(reader, &a)
			count += a
		}

		if count == m {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var t, n, m, a int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n, &m)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a)
			m -= a
		}
		if m == 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import "fmt"

func main() {
	var t, n, m, sum, i, j, a int64
	fmt.Scan(&t)
	for i=0; i<t; i++{
		fmt.Scan(&n, &m)
		for j=0; j<n; j++ {
			fmt.Scan(&a)
			sum += a
		}
		if sum == m {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
		sum = 0
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func(Case int) {
		var n ,m int
		Fscan(in, &n,&m)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		sum := 0
		for _, v := range a {
			sum += v
		}
		if sum == m {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}

	var t int
	Fscan(in, &t)
	for Case := 1; Case <= t; Case++ {
		solve(Case)
	}
}

func main() { run(os.Stdin, os.Stdout) }

package main
import (
	"bufio"
	"fmt"
	"os"
)
var rd = bufio.NewReader(os.Stdin)
func scanf(f string, a... interface{}) {
	fmt.Fscanf(rd, f, a...)
}
func scanArray(n int) []int {
	res := make([]int, n)
	for i := range res {
		if i < n - 1 {
			scanf("%d ", &res[i])
		} else {
			scanf("%d\n", &res[i])
		}
	}
	return res
}
func main() {
	q := 0
	scanf("%d\n", &q)
	for i := 0; i < q; i++ {
		var n, m int
		scanf("%d %d\n", &n, &m)
		a := scanArray(n)
		s := 0
		for _, v := range a {
			s += v
		}
		if s == m {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main
import "fmt"
func main() {
	q := 0
	fmt.Scan(&q)
	for tc := 0; tc < q; tc++ {
		var n, m int
		fmt.Scan(&n, &m)
		s := 0
		for i := 0; i < n; i++ {
			cur := 0
			fmt.Scan(&cur)
			s += cur
		}
		if s == m {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

type kv struct {
	Key   int
	Value int
}

func main() {
	//rd, _ := os.Open("input")
	io := bufio.NewReader(os.Stdin)

	var t, n, m, elem int

	fmt.Fscan(io, &t)
	for ; t > 0; t-- {
		fmt.Fscan(io, &n, &m)
		for i := 0; i < n; i++ {
			fmt.Fscan(io, &elem)
			m -= elem
		}
		if m == 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var Writer = bufio.NewWriter(os.Stdout)
var Reader = bufio.NewReader(os.Stdin)

func Print(args ...interface{}) {
	fmt.Fprint(Writer, args...)
}

func Scan(args ...interface{}) {
	fmt.Fscan(Reader, args...)
}

func main() {
	defer Writer.Flush()

	var t int
	Scan(&t)
	for t!=0{
		var n, m int
		Scan(&n, &m)
		sum := 0
		for i:=0; i<n; i++ {
			var val int
			Scan(&val)
			sum += val
		}

		if sum == m {
			Print("Yes\n")
		} else {
			Print("No\n")
		}
		t--
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

var rw = NewFastIO(os.Stdin, os.Stdout)

func main() {
	defer rw.Flush()
	nt := rw.NextInt()
	for i := 0; i < nt; i++ {
		tCase()
	}
}

func tCase() {
	n, m := rw.NextInt(), rw.NextInt()
	a := rw.NextInts(n)
	for _, x := range a {
		m -= x
	}
	if m == 0 {
		rw.Println("YES")
	} else {
		rw.Println("NO")
	}
}

type FastIO struct {
	*bufio.Writer
	r    io.Reader
	buf  [8192]byte
	i, n int
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{r: r, Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	if f.i == f.n {
		f.n, _ = f.r.Read(f.buf[:])
		if f.n == 0 {
			panic("EOF")
		}
		f.i = 0
	}
	f.i++
	return f.buf[f.i-1]
}

func (f *FastIO) Next() string {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	var s []byte
	for ; c > ' '; c = f.readC() {
		s = append(s, c)
	}
	return string(s)
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}
func (f *FastIO) NextInt64() int64 {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := int64(0)
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int64(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}
func (f *FastIO) NextInt64s(n int) []int64 {
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt64()
	}
	return a
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f, a...)
}

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f, a...)
}
func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}
func (f *FastIO) PrintInt64s(a ...int64) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInt64s(a ...int64) {
	f.PrintInt64s(a...)
	f.Println()
}

package main

import "fmt"

func readSlice(n int) []int {
	x := make([]int, n)
	y := make([]interface{}, n)
	for i := range x {
		y[i] = &x[i]
	}
	_, _ = fmt.Scanln(y...)
	return x[:n]
}

func main() {
	var t, n, m int
	_, _ = fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		_, _ = fmt.Scanf("%d %d\n", &n, &m)
		slice := readSlice(n)
		if m == sum(slice){
			fmt.Println("YES")
		}else{
			fmt.Println("NO")
		}

	}
}

func sum(arr []int) int {
	s := 0
	for i := range arr {
		s += arr[i]
	}
	return s
}

package main

import (
	"fmt"

)

func intSlice(n int) []int {
	x := make([]int, n)
	y := make([]interface{}, len(x))
	for i := 0; i < n; i++ {
		y[i] = &x[i]
	}
	n, _ = fmt.Scanln(y...)
	return x[:n]
}

func main() {
	var t, n, m int
	_, _ = fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		_, _ = fmt.Scanf("%d %d\n", &n, &m)
		slice := intSlice(n)
		if sum(slice) == m{
			fmt.Println("YES")
		}else{
			fmt.Println("NO")
		}
	}

}

func sum(a []int)int{
	s := 0
	for i := range a{
		s += a[i]
	}
	return s
}

package main

import "fmt"

func main() {
	var numCases int
	fmt.Scanf("%d\n", &numCases)

	for i := 0; i < numCases; i++ {
		var n, m int
		fmt.Scanf("%d %d\n", &n, &m)

		format := ""
		for j := 0; j < n-1; j++ {
			format += "%d "
		}
		format += "%d\n"

		testCase, err := readIntArray(n)
		if err != nil {
			panic(err)
		}

		sum := 0
		for _, c := range testCase {
			sum += c
		}

		if sum == m {
			fmt.Printf("YES\n")
		} else {
			fmt.Printf("NO\n")
		}
	}
}

func readIntArray(n int) ([]int, error) {
	x := make([]int, n)
	y := make([]interface{}, n)
	for i := range x {
		y[i] = &x[i]
	}
	n, err := fmt.Scanln(y...)
	x = x[:n]
	return x, err
}

package main

import (
	"fmt"
)

func checksum(arr [100]float64, n int, m float64) bool {
	var sum float64
	for i := 0; i < n; i++ {
		sum += arr[i]
	}
	if sum == m {
		return true
	} else {
		return false
	}
}

func main() {
	var t, n int
	var m float64
	var arr [100]float64
	fmt.Printf("Enter number of test cases:")
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Printf("Enter number of elements in array:")
		fmt.Scan(&n)
		fmt.Printf("Enter sum:")
		fmt.Scan(&m)
		for j := 0; j < n; j++ {
			fmt.Scan(&arr[j])
		}
		if checksum(arr, n, m) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func cin(a ...interface{}) (n int, err error) {
	return fmt.Fscan(in, a...)
}

func cout(a ...interface{}) (n int, err error) {
	return fmt.Fprintln(out, a...)
}
func main() {
	t := 0
	cin(&t)
	for c := 0; c < t; c++ {
		n, m := 0, 0
		cin(&n, &m)
		sum, x := 0, 0
		for i := 0; i < n; i++ {
			cin(&x)
			sum += x
		}
		if sum == m {
			cout("YES")
		} else {
			cout("NO")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var t, n, m, a int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n, &m)
		for j := 0; j < m; j++ {
			fmt.Fscan(in, &a)
			m -= a
		}
		if m == 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import "fmt"

func main() {
	var t, n, m, sum, i, j, a int64
	fmt.Scan(&t)
	for i=0; i<t; i++{
		fmt.Scan(&n, &m)
		for j=0; j<n; j++ {
			fmt.Scan(&a)
			sum += a
		}
		if sum == m {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}


package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscanf(in, "%d\n", &t)
	for tt := 0; tt < t; tt++ {
		x, y := 0, 0
		fmt.Fscanf(in, "%d %d\n", &x, &y)
		x, y = maxmin(x, y)
		diff := y - x
		if diff == 0 {
			fmt.Fprintf(out, "0\n")
			continue
		}
		l := 1
		r := diff
		for l < r {
			mid := (l + r) / 2
			ans := int64(1+mid) * int64(mid) / int64(2)
			//fmt.Println(mid, ans)
			if ans < int64(diff) {
				l = mid + 1
			} else {
				r = mid
			}
		}
		//fmt.Println(l)
		cur := (1 + l) * l / 2
		for (cur-diff)%2 == 1 {
			l++
			cur += l
		}
		fmt.Fprintf(out, "%d\n", l)
	}
	return
}

func maxmin(a, b int) (int, int) {
	if a < b {
		return a, b
	}
	return b, a
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	testCount := 0
	fmt.Fscanf(in, "%d\n", &testCount)

	for i := 0; i < testCount; i++ {
		// input
		a, b := 0, 0
		fmt.Fscanf(in, "%d %d\n", &a, &b)

		if a == b {
			fmt.Fprintln(out, 0)
			continue
		}

		if a > b {
			b, a = a, b
		}

		fmt.Fprintln(out, abCfs(a, b))
	}
}

func abCfs(a, b int) int {
	diff := abs(a, b)

	result := 0
	for result*(result+1)/2 < diff {
		result += 1
	}

	for (result*(result+1)/2)%2 != diff%2 {
		result += 1
	}

	return result
}

func abs(a, b int) int {
	if a-b < 0 {
		return b - a
	}
	return a - b
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

	in := func() float64 {
		sc.Scan()
		i, _ := strconv.ParseFloat(sc.Text(), 10)
		return i
	}

	for t := in(); t > 0 ; t-- {
		a, b := in(), in()

		if a > b {
			a, b = b, a
		}

		n := -1 + math.Sqrt(1-8*(a-b))
		n /= 2

		n = math.Ceil(n)

		for int64(a + n*(n+1)/2 - b) %2 != 0 {
			n++
		}

		fmt.Println(int64(n))
	}
}

package main

import (
	"fmt"
	"math"
)

func check(res int, d int) bool {
	var sum int64
	sum = int64(res) * int64(res + 1) / 2
	if sum < int64(d) {
		return false
	}
	return sum % 2 == int64(d) % 2
}

func prog(t int) int {
	for t > 0 {
		var a, b int
		fmt.Scan(&a, &b)
		d := int(math.Abs(float64(a - b)))
		if d == 0{
			fmt.Println("0")
			t--
			continue
		}
		res := 1
		for true{
			if !check(res, d){
				res++
			} else {
				break
			}
		}
		fmt.Println(res)
		t--
	}
	return 0
}

func main() {
	var t int
	fmt.Scan(&t)
	prog(t)
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		var n1, n2 int64
		fmt.Scanf("%d %d\n", &n1, &n2)

		diff := n2 - n1
		if diff < 0 {
			diff *= -1
		}
		if diff == 0 {
			fmt.Println(0)
			continue
		}

		sum := int64(0)
		for i := int64(1); i <= 1000000000; i++ {
			sum += i
			if sum == diff {
				fmt.Println(i)
				break
			} else if sum > diff && (sum+diff)%2 == 0 {
				fmt.Println(i)
				break
			}
		}
	}
}

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60
const INF_INT32 = math.MaxInt32
const INF_BIT30 = 1 << 30

var t int
var a, b int64

func main() {
	t = ReadInt()

	for tc := 0; tc < t; tc++ {
		a, b = ReadInt64_2()

		solve()
	}
}

func solve() {
	diff := AbsInt(a - b)

	if diff == 0 {
		fmt.Println(0)
		return
	}

	for k := int64(1); ; k++ {
		sum := k * (k + 1) / 2

		if diff%2 == sum%2 && diff <= sum {
			fmt.Println(k)
			return
		}
	}
}

// AbsInt is integer version of math.Abs
func AbsInt(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

/*
- まずは全探索を検討しましょう
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
- いきなりオーバーフローはしていませんか？
	- MOD取る系はint64必須ですよ？
*/

/*
ASCII code

ASCII   10進数  ASCII   10進数  ASCII   10進数
!       33      "       34      #       35
$       36      %       37      &       38
'       39      (       40      )       41
*       42      +       43      ,       44
-       45      .       46      /       47
0       48      1       49      2       50
3       51      4       52      5       53
6       54      7       55      8       56
9       57      :       58      ;       59
<       60      =       61      >       62
?       63      @       64      A       65
B       66      C       67      D       68
E       69      F       70      G       71
H       72      I       73      J       74
K       75      L       76      M       77
N       78      O       79      P       80
Q       81      R       82      S       83
T       84      U       85      V       86
W       87      X       88      Y       89
Z       90      [       91      \       92
]       93      ^       94      _       95
`       96      a       97      b       98
c       99      d       100     e       101
f       102     g       103     h       104
i       105     j       106     k       107
l       108     m       109     n       110
o       111     p       112     q       113
r       114     s       115     t       116
u       117     v       118     w       119
x       120     y       121     z       122
{       123     |       124     }       125
~       126             127
*/

/*******************************************************************/

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func Sol1278B(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var t int
	Fscan(in, &t)
	for case_ := 0; case_ < t; case_++ {
		Fprintln(out, solveCase(in, out))
	}
}

func solveCase(in io.Reader, out io.Writer) int64 {
	var a, b int64
	Fscan(in, &a, &b)
	a -= b
	if a < 0 {
		a = -a
	}
	if a == 0 {
		return 0
	}
	d := math.Sqrt(float64(8*a + 1))
	k := int64((d - 1) / 2)
	tk := (k + 1) * k / 2
	if tk == a {
		return k
	}
	if k&1 == 1 {
		if (a-tk)&1 == 1 {
			return k + 2
		}
		return k + 1
	}
	if (a-tk)&1 == 1 {
		return k + 1
	}
	return k + 3
}

func main() {
	Sol1278B(os.Stdin, os.Stdout)
}

package main

import (
	"fmt"
	"strconv"
)

func main() {
	var n int
	fmt.Scan(&n)

	output := ""
	for i := 0; i < n; i++ {
		var a, b int
		fmt.Scan(&a, &b)

		if a == b {
			output += "0\n"
			continue
		}

		max := func(x, z int) int { if x > z { return x }; return z }

		cur, sum := 0, 0
		for {
			cur++
			sum += cur

			if (a + b + sum) % 2 == 0 && (a + b + sum) / 2 >= max(a, b) {
				break
			}
		}

		output += strconv.Itoa(cur) + "\n"
	}
	fmt.Println(output)
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

	in := func() float64 {
		sc.Scan()
		i, _ := strconv.ParseFloat(sc.Text(), 10)
		return i
	}

	for t := in(); t > 0 ; t-- {
		a, b := in(), in()

		if a > b {
			a, b = b, a
		}

		n := -1 + math.Sqrt(1-8*(a-b))
		n /= 2

		n = math.Ceil(n)

		if (int64((a + n*(n-1)/2 -b))%2 != 0) {
			n++
		}

		fmt.Println(int64(n))
	}
}

package main

import (
	"fmt"
	"math"
)

func check(res int, d int) bool {
	var sum int64
	sum = int64(res) * int64(res + 1) / 2
	if sum < int64(d) {
		return false
	}
	return sum % 2 == int64(d) % 2
}

func prog(t int) int {
	for t > 0 {
		var a, b int
		fmt.Scan(&a, &b)
		d := int(math.Abs(float64(a - b)))
		if d == 0{
			fmt.Println("0")
		}
		res := 1
		for true{
			if !check(res, d){
				res++
			} else {
				break
			}
		}
		fmt.Println(res)
		t--
	}
	return 0
}

func main() {
	var t int
	fmt.Scan(&t)
	prog(t)
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func Sol1278B(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var t int
	Fscan(in, &t)
	for case_ := 0; case_ < t; case_++ {
		Fprintln(out, solveCase(in, out))
	}
}

func solveCase(in io.Reader, out io.Writer) int64 {
	var a, b int64
	Fscan(in, &a, &b)
	a -= b
	if a < 0 {
		a = -a
	}
	if a == 0 {
		return 0
	}
	d := math.Sqrt(float64(8*a + 1))
	k := int64(math.Ceil((d - 1) / 2))
	tk := (k + 1) * k / 2
	if tk == a {
		return k
	}
	if k&1 == 1 {
		if (a-tk)&1 == 1 {
			return k + 2
		}
		return k + 1
	}
	if (a-tk)&1 == 1 {
		return k + 1
	}
	return k + 3
}

func main() {
	Sol1278B(os.Stdin, os.Stdout)
}


package main

import (
	"bufio"
	"fmt"
	"os"
)

func invert(x rune) rune {
	if x == '1' {
		return '0'
	}
	return '1'
}

func main() {
	//rd, _ := os.Open("input")
	//in := bufio.NewReader(rd)
	in := bufio.NewReader(os.Stdin)

	var t, n, m int
	var s string
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &m)

		a := make([][]rune, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &s)
			a[i] = []rune(s)
		}

		opsX := make([]int, 0, 3*n*m)
		opsY := make([]int, 0, 3*n*m)
		for i := 0; i < n-1; i++ {
			for j := 0; j < m-1; j++ {
				if a[i][j] == '1' && a[i+1][j] == '1' {
					if a[i][j+1] == '1' {
						opsX = append(opsX, i, i, i+1)
						opsY = append(opsY, j, j+1, j)
						a[i][j], a[i+1][j], a[i][j+1] = '0', '0', invert(a[i][j+1])
					} else {
						opsX = append(opsX, i, i+1, i+1)
						opsY = append(opsY, j, j+1, j)
						a[i][j], a[i+1][j], a[i+1][j+1] = '0', '0', invert(a[i+1][j+1])
					}
				} else if a[i][j] == '1' {
					opsX = append(opsX, i, i, i+1)
					opsY = append(opsY, j, j+1, j+1)
					a[i][j], a[i][j+1], a[i+1][j+1] = '0', invert(a[i][j+1]), invert(a[i+1][j+1])
				} else if a[i+1][j] == '1' {
					opsX = append(opsX, i, i+1, i+1)
					opsY = append(opsY, j+1, j, j+1)
					a[i+1][j], a[i][j+1], a[i+1][j+1] = '0', invert(a[i][j+1]), invert(a[i+1][j+1])
				}
			}
			// workaround
			if n == 3 && i == 0 {
				if a[i][m-1] == '1' {
					a[i][m-1], a[i+1][m-2], a[i+1][m-1] = '0', invert(a[i+1][m-2]), invert(a[i+1][m-1])
					opsX = append(opsX, i, i+1, i+1)
					opsY = append(opsY, m-1, m-2, m-1)
				}
				continue
			}
			// last column
			if a[i][m-1] == '1' && a[i+1][m-1] == '1' {
				a[i][m-1], a[i+1][m-1] = '0', '0'
				opsX = append(opsX, i, i+1, i)
				opsY = append(opsY, m-2, m-2, m-1)
				opsX = append(opsX, i, i+1, i+1)
				opsY = append(opsY, m-2, m-2, m-1)
			} else if a[i][m-1] == '1' {
				a[i][m-1] = '0'
				opsX = append(opsX, i, i, i+1)
				opsY = append(opsY, m-1, m-2, m-2)
				opsX = append(opsX, i, i, i+1)
				opsY = append(opsY, m-2, m-1, m-1)
				opsX = append(opsX, i+1, i, i+1)
				opsY = append(opsY, m-2, m-1, m-1)
			} else if a[i+1][m-1] == '1' {
				a[i+1][m-1] = '0'
				opsX = append(opsX, i+1, i, i+1)
				opsY = append(opsY, m-1, m-2, m-2)
				opsX = append(opsX, i, i, i+1)
				opsY = append(opsY, m-2, m-1, m-1)
				opsX = append(opsX, i+1, i, i+1)
				opsY = append(opsY, m-2, m-1, m-1)
			}
		}
		opsCnt := len(opsX) / 3
		fmt.Println(opsCnt)

		for i := 0; i < opsCnt; i++ {
			fmt.Printf("%d %d %d %d %d %d\n", opsX[3*i]+1, opsY[3*i]+1, opsX[3*i+1]+1, opsY[3*i+1]+1, opsX[3*i+2]+1, opsY[3*i+2]+1)
		}
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func(Case int) {
		var n, m int
		Fscan(in, &n, &m)
		a := make([][]byte, n)
		for i := range a {
			Fscan(in, &a[i])
		}

		ans := [][][2]int{}
		add := func(ps [][2]int) {
			ans = append(ans, ps)
			for _, p := range ps {
				a[p[0]][p[1]] ^= 1
			}
		}
		for i, row := range a[:n-2] {
			for j, b := range row {
				if b == '1' {
					if j < m-1 {
						add([][2]int{{i, j}, {i + 1, j}, {i + 1, j + 1}})
					} else {
						add([][2]int{{i, j}, {i + 1, j}, {i + 1, j - 1}})
					}
				}
			}
		}
		for j := 0; j < m-2; j++ {
			for i := n - 2; i < n; i++ {
				if a[i][j] == '1' {
					add([][2]int{{i, j}, {n - 2, j + 1}, {n - 1, j + 1}})
				}
			}
		}

		c := [][2]int{{n - 2, m - 2}, {n - 2, m - 1}, {n - 1, m - 2}, {n - 1, m - 1}}
		var p0, p1 []int
		for i, p := range c {
			if a[p[0]][p[1]] == '0' {
				p0 = append(p0, i)
			} else {
				p1 = append(p1, i)
			}
		}
		if len(p1) == 4 {
			ans = append(ans, [][2]int{c[p1[0]], c[p1[1]], c[p1[2]]})
			p0, p1 = p1[:3], p1[3:]
		}
		if len(p1) == 1 {
			ans = append(ans, [][2]int{c[p1[0]], c[p0[0]], c[p0[1]]})
			p1, p0 = p0[:2], append(p0[2:], p1[0])
		}
		if len(p1) == 2 {
			ans = append(ans, [][2]int{c[p1[0]], c[p0[0]], c[p0[1]]})
			p1 = append(p1[1:], p0...)
		}
		if len(p1) == 3 {
			ans = append(ans, [][2]int{c[p1[0]], c[p1[1]], c[p1[2]]})
		}

		Fprintln(out, len(ans))
		for _, ps := range ans {
			for _, p := range ps {
				Fprint(out, p[0]+1, p[1]+1, " ")
			}
			Fprintln(out)
		}
	}

	var t int
	Fscan(in, &t)
	for Case := 1; Case <= t; Case++ {
		solve(Case)
	}
}

func main() { run(os.Stdin, os.Stdout) }

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func(Case int) {
		var n, m int
		Fscan(in, &n, &m)
		a := make([][]byte, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		ans := [][]int{}
		for i := 0; i < n-2; i++ {
			for j, b := range a[i] {
				if b == '1' {
					if j < m-1 {
						ans = append(ans, []int{i, j, i + 1, j, i + 1, j + 1})
						a[i+1][j] ^= 1
						a[i+1][j+1] ^= 1
					} else {
						ans = append(ans, []int{i, j, i + 1, j, i + 1, j - 1})
						a[i+1][j] ^= 1
						a[i+1][j-1] ^= 1
					}
				}
			}
		}
		for j := 0; j < m-2; j++ {
			for i := n - 2; i < n; i++ {
				if a[i][j] == '1' {
					ans = append(ans, []int{i, j, n - 2, j + 1, n - 1, j + 1})
					a[n-2][j+1] ^= 1
					a[n-1][j+1] ^= 1
				}
			}
		}

		b := []byte{a[n-2][m-2], a[n-2][m-1], a[n-1][m-2], a[n-1][m-1]}
		ids := [][]int{{n - 2, m - 2}, {n - 2, m - 1}, {n - 1, m - 2}, {n - 1, m - 1}}

		p0, p1 := []int{}, []int{}
		for i, v := range b {
			if v == '0' {
				p0 = append(p0, i)
			} else {
				p1 = append(p1, i)
			}
		}
		if len(p1) == 4 {
			aa := []int{}
			for _, p := range p1[:3] {
				aa = append(aa, ids[p]...)
			}
			ans = append(ans, aa)
			p0 = p1[:3]
			p1 = p1[3:]
		}
		if len(p1) == 1 {
			aa := []int{}
			tmp := p1[0]
			aa = append(aa, ids[p1[0]]...)
			aa = append(aa, ids[p0[0]]...)
			aa = append(aa, ids[p0[1]]...)
			ans = append(ans, aa)
			p1 = p0[:2]
			p0 = p0[2:]
			p0 = append(p0, tmp)
		}
		if len(p1) == 2 {
			aa := []int{}
			//tmp := p1[0]
			aa = append(aa, ids[p0[0]]...)
			aa = append(aa, ids[p0[1]]...)
			aa = append(aa, ids[p1[0]]...)
			ans = append(ans, aa)
			p1 = append(p1, p0...)
			p0, p1 = p1[:1], p1[1:]
		}
		if len(p1) == 3 {
			aa := []int{}
			for _, p := range p1[:3] {
				aa = append(aa, ids[p]...)
			}
			ans = append(ans, aa)
		}

		Fprintln(out, len(ans))
		for _, a := range ans {
			for _, v := range a {
				Fprint(out, v+1, " ")
			}
			Fprintln(out)
		}
	}

	var t int
	Fscan(in, &t)
	for Case := 1; Case <= t; Case++ {
		solve(Case)
	}
}

func main() { run(os.Stdin, os.Stdout) }

package main

import (
	"bufio"
	"fmt"
	"os"
)

func invert(x rune) rune {
	if x == '1' {
		return '0'
	}
	return '1'
}

func main() {
	//rd, _ := os.Open("input")
	//in := bufio.NewReader(rd)
	in := bufio.NewReader(os.Stdin)

	var t, n, m int
	var s string
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &m)

		a := make([][]rune, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &s)
			a[i] = []rune(s)
		}

		opsX := make([]int, 0, 3*n*m)
		opsY := make([]int, 0, 3*n*m)
		for i := 0; i < n-1; i++ {
			for j := 0; j < m-1; j++ {
				if a[i][j] == '1' && a[i+1][j] == '1' {
					if a[i][j+1] == '1' {
						opsX = append(opsX, i, i, i+1)
						opsY = append(opsY, j, j+1, j)
						a[i][j], a[i+1][j], a[i][j+1] = '0', '0', invert(a[i][j+1])
					} else {
						opsX = append(opsX, i, i+1, i+1)
						opsY = append(opsY, j, j+1, j)
						a[i][j], a[i+1][j], a[i][j+1] = '0', '0', invert(a[i+1][j+1])
					}
				} else if a[i][j] == '1' {
					opsX = append(opsX, i, i, i+1)
					opsY = append(opsY, j, j+1, j+1)
					a[i][j], a[i][j+1], a[i+1][j+1] = '0', invert(a[i][j+1]), invert(a[i+1][j+1])
				} else if a[i+1][j] == '1' {
					opsX = append(opsX, i, i+1, i+1)
					opsY = append(opsY, j+1, j, j+1)
					a[i+1][j], a[i][j+1], a[i+1][j+1] = '0', invert(a[i][j+1]), invert(a[i+1][j+1])
				}
			}
			// workaround
			if n == 3 && i == 0 {
				if a[i][m-1] == '1' {
					a[i][m-1], a[i+1][m-2], a[i+1][m-1] = '0', invert(a[i+1][m-2]), invert(a[i+1][m-1])
					opsX = append(opsX, i, i+1, i+1)
					opsY = append(opsY, m-1, m-2, m-1)
				}
				continue
			}
			// last column
			if a[i][m-1] == '1' && a[i+1][m-1] == '1' {
				a[i][m-1], a[i+1][m-1] = '0', '0'
				opsX = append(opsX, i, i+1, i)
				opsY = append(opsY, m-2, m-2, m-1)
				opsX = append(opsX, i, i+1, i+1)
				opsY = append(opsY, m-2, m-2, m-1)
			} else if a[i][m-1] == '1' {
				a[i][m-1] = '0'
				opsX = append(opsX, i, i, i+1)
				opsY = append(opsY, m-1, m-2, m-2)
				opsX = append(opsX, i, i, i+1)
				opsY = append(opsY, m-2, m-1, m-1)
				opsX = append(opsX, i+1, i, i+1)
				opsY = append(opsY, m-2, m-1, m-1)
			} else if a[i+1][m-1] == '1' {
				a[i+1][m-1] = '0'
				opsX = append(opsX, i+1, i, i+1)
				opsY = append(opsY, m-1, m-2, m-2)
				opsX = append(opsX, i, i, i+1)
				opsY = append(opsY, m-2, m-1, m-1)
				opsX = append(opsX, i+1, i, i+1)
				opsY = append(opsY, m-2, m-1, m-1)
			}
		}
		opsCnt := len(opsX) / 3
		fmt.Println(opsCnt)

		for i := 0; i < opsCnt; i++ {
			fmt.Printf("%d %d %d %d %d %d\n", opsX[3*i]+1, opsY[3*i]+1, opsX[3*i+1]+1, opsY[3*i+1]+1, opsX[3*i+2]+1, opsY[3*i+2]+1)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func invert(x rune) rune {
	if x == '1' {
		return '0'
	}
	return '1'
}

func main() {
	//rd, _ := os.Open("input")
	//in := bufio.NewReader(rd)
	in := bufio.NewReader(os.Stdin)

	var t, n, m int
	var s string
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &m)

		a := make([][]rune, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &s)
			a[i] = []rune(s)
		}

		opsX := make([]int, 0, 3*n*m)
		opsY := make([]int, 0, 3*n*m)
		for i := 0; i < n-1; i++ {
			for j := 0; j < m-1; j++ {
				if a[i][j] == '1' && a[i+1][j] == '1' {
					opsX = append(opsX, i, i, i+1)
					opsY = append(opsY, j, j+1, j)
					a[i][j], a[i+1][j], a[i][j+1] = '0', '0', invert(a[i][j+1])
				} else if a[i][j] == '1' {
					opsX = append(opsX, i, i, i+1)
					opsY = append(opsY, j, j+1, j+1)
					a[i][j], a[i][j+1], a[i+1][j+1] = '0', invert(a[i][j+1]), invert(a[i+1][j+1])
				} else if a[i+1][j] == '1' {
					opsX = append(opsX, i, i+1, i+1)
					opsY = append(opsY, j+1, j, j+1)
					a[i+1][j], a[i][j+1], a[i+1][j+1] = '0', invert(a[i][j+1]), invert(a[i+1][j+1])
				}
			}
			// workaround
			if n == 3 && i == 0 {
				if a[i][m-1] == '1' {
					a[i][m-1], a[i+1][m-2], a[i+1][m-1] = '0', invert(a[i+1][m-2]), invert(a[i+1][m-1])
					opsX = append(opsX, i, i+1, i+1)
					opsY = append(opsY, m-1, m-2, m-1)
				}
				continue
			}
			// last column
			if a[i][m-1] == '1' && a[i+1][m-1] == '1' {
				a[i][m-1], a[i+1][m-1] = '0', '0'
				opsX = append(opsX, i, i+1, i)
				opsY = append(opsY, m-2, m-2, m-1)
				opsX = append(opsX, i, i+1, i+1)
				opsY = append(opsY, m-2, m-2, m-1)
			} else if a[i][m-1] == '1' {
				a[i][m-1] = '0'
				opsX = append(opsX, i, i, i+1)
				opsY = append(opsY, m-1, m-2, m-2)
				opsX = append(opsX, i, i, i+1)
				opsY = append(opsY, m-2, m-1, m-1)
				opsX = append(opsX, i+1, i, i+1)
				opsY = append(opsY, m-2, m-1, m-1)
			} else if a[i+1][m-1] == '1' {
				a[i+1][m-1] = '0'
				opsX = append(opsX, i+1, i, i+1)
				opsY = append(opsY, m-1, m-2, m-2)
				opsX = append(opsX, i, i, i+1)
				opsY = append(opsY, m-2, m-1, m-1)
				opsX = append(opsX, i+1, i, i+1)
				opsY = append(opsY, m-2, m-1, m-1)
			}
		}
		opsCnt := len(opsX) / 3
		fmt.Println(opsCnt)

		for i := 0; i < opsCnt; i++ {
			fmt.Printf("%d %d %d %d %d %d\n", opsX[3*i]+1, opsY[3*i]+1, opsX[3*i+1]+1, opsY[3*i+1]+1, opsX[3*i+2]+1, opsY[3*i+2]+1)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func invert(x rune) rune {
	if x == '1' {
		return '0'
	}
	return '1'
}

func main() {
	//rd, _ := os.Open("input")
	//in := bufio.NewReader(rd)
	in := bufio.NewReader(os.Stdin)

	var t, n, m int
	var s string
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &m)

		a := make([][]rune, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &s)
			a[i] = []rune(s)
		}

		opsX := make([]int, 0, 3*n*m)
		opsY := make([]int, 0, 3*n*m)
		// all rows except last
		for i := 0; i < n-1; i++ {
			// all columns except last
			for j := 0; j < m-1; j++ {
				if a[i][j] == '1' {
					a[i][j] = '0'
					opsX = append(opsX, i)
					opsY = append(opsY, j)
					if a[i][j+1] == '1' {
						a[i][j+1] = '0'
						opsX = append(opsX, i)
						opsY = append(opsY, j+1)
						if a[i+1][j] == '1' {
							a[i+1][j] = '0'
							opsX = append(opsX, i+1)
							opsY = append(opsY, j)
						} else {
							a[i+1][j+1] = invert(a[i+1][j+1])
							opsX = append(opsX, i+1)
							opsY = append(opsY, j+1)
						}
					} else {
						a[i+1][j] = invert(a[i+1][j])
						a[i+1][j+1] = invert(a[i+1][j+1])
						opsX = append(opsX, i+1, i+1)
						opsY = append(opsY, j, j+1)
					}
				}
			}
			// last column
			if a[i][m-1] == '1' {
				a[i][m-1] = '0'
				a[i+1][m-2] = invert(a[i+1][m-2])
				a[i+1][m-1] = invert(a[i+1][m-1])
				opsX = append(opsX, i, i+1, i+1)
				opsY = append(opsY, m-1, m-2, m-1)
			}
		}
		// last row except last column
		for i := 0; i < m-1; i++ {
			if a[n-1][i] == '1' {
				if a[n-2][i] == '1' {
					a[n-2][i] = '0'
					a[n-1][i] = '0'
					a[n-1][i+1] = invert(a[n-1][i+1])
					opsX = append(opsX, n-2, n-1, n-1)
					opsY = append(opsY, i, i, i+1)
				} else {
					if a[n-1][i+1] == '1' {
						a[n-1][i] = '0'
						a[n-1][i+1] = '0'
						opsX = append(opsX, n-2, n-2, n-1)
						opsY = append(opsY, i, i+1, i+1)
						opsX = append(opsX, n-2, n-2, n-1)
						opsY = append(opsY, i, i+1, i)
					} else {
						a[n-1][i] = '0'
						a[n-1][i+1] = '1'
						a[n-2][i+1] = '1'
						opsX = append(opsX, n-2, n-1, n-1)
						opsY = append(opsY, i+1, i, i+1)
					}
				}
			}
		}
		// latest elem
		if a[n-1][m-1] == '1' {
			if a[n-2][m-1] == '1' {
				opsX = append(opsX, n-2, n-2, n-1)
				opsY = append(opsY, m-2, m-1, m-2)
				opsX = append(opsX, n-2, n-1, n-1)
				opsY = append(opsY, m-2, m-2, m-1)
			} else {
				opsX = append(opsX, n-2, n-1, n-1)
				opsY = append(opsY, m-2, m-2, m-1)
				opsX = append(opsX, n-2, n-2, n-1)
				opsY = append(opsY, m-2, m-1, m-1)
				opsX = append(opsX, n-2, n-1, n-1)
				opsY = append(opsY, m-1, m-2, m-1)
			}
		}
		opsCnt := len(opsX) / 3
		fmt.Println(opsCnt)
		for i := 0; i < opsCnt; i++ {
			fmt.Printf("%d %d %d %d %d %d\n", opsX[3*i]+1, opsY[3*i]+1, opsX[3*i+1]+1, opsY[3*i+1]+1, opsX[3*i+2]+1, opsY[3*i+2]+1)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func invert(x rune) rune {
	if x == '1' {
		return '0'
	}
	return '1'
}

func main() {
	//rd, _ := os.Open("input")
	//in := bufio.NewReader(rd)
	in := bufio.NewReader(os.Stdin)

	var t, n, m int
	var s string
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &m)

		a := make([][]rune, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &s)
			a[i] = []rune(s)
		}

		opsX := make([]int, 0, 3*n*m)
		opsY := make([]int, 0, 3*n*m)
		for i := 0; i < n-1; i++ {
			for j := 0; j < m-1; j++ {
				if a[i][j] == '1' && a[i+1][j] == '1' {
					if a[i][j+1] == '1' {
						opsX = append(opsX, i, i, i+1)
						opsY = append(opsY, j, j+1, j)
						a[i][j], a[i+1][j], a[i][j+1] = '0', '0', invert(a[i][j+1])
					} else {
						opsX = append(opsX, i, i+1, i+1)
						opsY = append(opsY, j, j+1, j)
						a[i][j], a[i+1][j], a[i+1][j+1] = '0', '0', invert(a[i+1][j+1])
					}
				} else if a[i][j] == '1' {
					opsX = append(opsX, i, i, i+1)
					opsY = append(opsY, j, j+1, j+1)
					a[i][j], a[i][j+1], a[i+1][j+1] = '0', invert(a[i][j+1]), invert(a[i+1][j+1])
				} else if a[i+1][j] == '1' {
					opsX = append(opsX, i, i+1, i+1)
					opsY = append(opsY, j+1, j, j+1)
					a[i+1][j], a[i][j+1], a[i+1][j+1] = '0', invert(a[i][j+1]), invert(a[i+1][j+1])
				}
			}
			// last column
			if a[i][m-1] == '1' && a[i+1][m-1] == '1' {
				a[i][m-1], a[i+1][m-1] = '0', '0'
				opsX = append(opsX, i, i+1, i)
				opsY = append(opsY, m-2, m-2, m-1)
				opsX = append(opsX, i, i+1, i+1)
				opsY = append(opsY, m-2, m-2, m-1)
			} else if a[i][m-1] == '1' {
				a[i][m-1] = '0'
				opsX = append(opsX, i, i, i+1)
				opsY = append(opsY, m-1, m-2, m-2)
				opsX = append(opsX, i, i, i+1)
				opsY = append(opsY, m-2, m-1, m-1)
				opsX = append(opsX, i+1, i, i+1)
				opsY = append(opsY, m-2, m-1, m-1)
			} else if a[i+1][m-1] == '1' {
				a[i+1][m-1] = '0'
				opsX = append(opsX, i+1, i, i+1)
				opsY = append(opsY, m-1, m-2, m-2)
				opsX = append(opsX, i, i, i+1)
				opsY = append(opsY, m-2, m-1, m-1)
				opsX = append(opsX, i+1, i, i+1)
				opsY = append(opsY, m-2, m-1, m-1)
			}
		}
		opsCnt := len(opsX) / 3
		fmt.Println(opsCnt)
		for i := 0; i < opsCnt; i++ {
			fmt.Printf("%d %d %d %d %d %d\n", opsX[3*i]+1, opsY[3*i]+1, opsX[3*i+1]+1, opsY[3*i+1]+1, opsX[3*i+2]+1, opsY[3*i+2]+1)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func invert(x rune) rune {
	if x == '1' {
		return '0'
	}
	return '1'
}

func main() {
	//rd, _ := os.Open("input")
	//in := bufio.NewReader(rd)
	in := bufio.NewReader(os.Stdin)

	var t, n, m int
	var s string
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &m)

		a := make([][]rune, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &s)
			a[i] = []rune(s)
		}

		opsX := make([]int, 0, 3*n*m)
		opsY := make([]int, 0, 3*n*m)
		for i := 0; i < n-1; i++ {
			for j := 0; j < m-1; j++ {
				if a[i][j] == '1' && a[i+1][j] == '1' {
					opsX = append(opsX, i, i, i+1)
					opsY = append(opsY, j, j+1, j)
					a[i][j], a[i+1][j], a[i][j+1] = '0', '0', invert(a[i][j+1])
				} else if a[i][j] == '1' {
					opsX = append(opsX, i, i, i+1)
					opsY = append(opsY, j, j+1, j+1)
					a[i][j], a[i][j+1], a[i+1][j+1] = '0', invert(a[i][j+1]), invert(a[i+1][j+1])
				} else if a[i+1][j] == '1' {
					opsX = append(opsX, i, i+1, i+1)
					opsY = append(opsY, j+1, j, j+1)
					a[i+1][j], a[i][j+1], a[i+1][j+1] = '0', invert(a[i][j+1]), invert(a[i+1][j+1])
				}
			}
			// last column
			if a[i][m-1] == '1' && a[i+1][m-1] == '1' {
				a[i][m-1], a[i+1][m-1] = '0', '0'
				opsX = append(opsX, i, i+1, i)
				opsY = append(opsY, m-2, m-2, m-1)
				opsX = append(opsX, i, i+1, i+1)
				opsY = append(opsY, m-2, m-2, m-1)
			} else if a[i][m-1] == '1' {
				a[i][m-1] = '0'
				opsX = append(opsX, i, i, i+1)
				opsY = append(opsY, m-1, m-2, m-2)
				opsX = append(opsX, i, i, i+1)
				opsY = append(opsY, m-2, m-1, m-1)
				opsX = append(opsX, i+1, i, i+1)
				opsY = append(opsY, m-2, m-1, m-1)
			} else if a[i+1][m-1] == '1' {
				a[i+1][m-1] = '0'
				opsX = append(opsX, i+1, i, i+1)
				opsY = append(opsY, m-1, m-2, m-2)
				opsX = append(opsX, i, i, i+1)
				opsY = append(opsY, m-2, m-1, m-1)
				opsX = append(opsX, i+1, i, i+1)
				opsY = append(opsY, m-2, m-1, m-1)
			}
		}
		opsCnt := len(opsX) / 3
		fmt.Println(opsCnt)
		for i := 0; i < opsCnt; i++ {
			fmt.Printf("%d %d %d %d %d %d\n", opsX[3*i]+1, opsY[3*i]+1, opsX[3*i+1]+1, opsY[3*i+1]+1, opsX[3*i+2]+1, opsY[3*i+2]+1)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func invert(x rune) rune {
	if x == '1' {
		return '0'
	}
	return '1'
}

func main() {
	//rd, _ := os.Open("input")
	//in := bufio.NewReader(rd)
	in := bufio.NewReader(os.Stdin)

	var t, n, m int
	var s string
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &m)

		a := make([][]rune, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &s)
			a[i] = []rune(s)
		}

		opsX := make([]int, 0, 3*n*m)
		opsY := make([]int, 0, 3*n*m)
		for i := 0; i < n-1; i++ {
			for j := 0; j < m-1; j++ {
				if a[i][j] == '1' && a[i+1][j] == '1' {
					opsX = append(opsX, i, i, i+1)
					opsY = append(opsY, j, j+1, j)
					a[i][j], a[i][j+1], a[i+1][j] = '0', invert(a[i][j+1]), '0'
				} else if a[i][j] == '1' {
					opsX = append(opsX, i, i, i+1)
					opsY = append(opsY, j, j+1, j+1)
					a[i][j], a[i][j+1], a[i+1][j+1] = '0', invert(a[i][j+1]), invert(a[i+1][j+1])
				} else if a[i+1][j] == '1' {
					opsX = append(opsX, i, i+1, i+1)
					opsY = append(opsY, j+1, j, j+1)
					a[i+1][j], a[i][j+1], a[i+1][j+1] = '0', invert(a[i][j+1]), invert(a[i+1][j+1])
				}
			}
			// last column
			if a[i][m-1] == '1' {
				a[i][m-1] = '0'
				a[i+1][m-2] = invert(a[i+1][m-2])
				a[i+1][m-1] = invert(a[i+1][m-1])
				opsX = append(opsX, i, i+1, i+1)
				opsY = append(opsY, m-1, m-2, m-1)
			}
		}
		// last row except last column
		for i := 0; i < m-1; i++ {
			if a[n-1][i] == '1' {
				if a[n-2][i] == '1' {
					a[n-2][i] = '0'
					a[n-1][i] = '0'
					a[n-1][i+1] = invert(a[n-1][i+1])
					opsX = append(opsX, n-2, n-1, n-1)
					opsY = append(opsY, i, i, i+1)
				} else {
					if a[n-1][i+1] == '1' {
						a[n-1][i] = '0'
						a[n-1][i+1] = '0'
						opsX = append(opsX, n-2, n-2, n-1)
						opsY = append(opsY, i, i+1, i+1)
						opsX = append(opsX, n-2, n-2, n-1)
						opsY = append(opsY, i, i+1, i)
					} else {
						a[n-1][i] = '0'
						a[n-1][i+1] = '1'
						a[n-2][i+1] = '1'
						opsX = append(opsX, n-2, n-1, n-1)
						opsY = append(opsY, i+1, i, i+1)
					}
				}
			}
		}
		// latest elem
		if a[n-1][m-1] == '1' {
			if a[n-2][m-1] == '1' {
				opsX = append(opsX, n-2, n-2, n-1)
				opsY = append(opsY, m-2, m-1, m-2)
				opsX = append(opsX, n-2, n-1, n-1)
				opsY = append(opsY, m-2, m-2, m-1)
			} else {
				opsX = append(opsX, n-2, n-1, n-1)
				opsY = append(opsY, m-2, m-2, m-1)
				opsX = append(opsX, n-2, n-2, n-1)
				opsY = append(opsY, m-2, m-1, m-1)
				opsX = append(opsX, n-2, n-1, n-1)
				opsY = append(opsY, m-1, m-2, m-1)
			}
		}
		opsCnt := len(opsX) / 3
		fmt.Println(opsCnt)
		for i := 0; i < opsCnt; i++ {
			fmt.Printf("%d %d %d %d %d %d\n", opsX[3*i]+1, opsY[3*i]+1, opsX[3*i+1]+1, opsY[3*i+1]+1, opsX[3*i+2]+1, opsY[3*i+2]+1)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func invert(x rune) rune {
	if x == '1' {
		return '0'
	}
	return '1'
}

func main() {
	//rd, _ := os.Open("input")
	//in := bufio.NewReader(rd)
	in := bufio.NewReader(os.Stdin)

	var t, n, m int
	var s string
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &m)

		a := make([][]rune, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &s)
			a[i] = []rune(s)
		}

		opsX := make([]int, 0, 3*n*m)
		opsY := make([]int, 0, 3*n*m)
		for i := 0; i < n-1; i++ {
			for j := 0; j < m-1; j++ {
				if a[i][j] == '1' && a[i+1][j] == '1' {
					opsX = append(opsX, i, i, i+1)
					opsY = append(opsY, j, j+1, j)
					a[i][j], a[i+1][j], a[i][j+1] = '0', '0', invert(a[i][j+1])
				} else if a[i][j] == '1' {
					opsX = append(opsX, i, i, i+1)
					opsY = append(opsY, j, j+1, j+1)
					a[i][j], a[i][j+1], a[i+1][j+1] = '0', invert(a[i][j+1]), invert(a[i+1][j+1])
				} else if a[i+1][j] == '1' {
					opsX = append(opsX, i, i+1, i+1)
					opsY = append(opsY, j+1, j, j+1)
					a[i+1][j], a[i][j+1], a[i+1][j+1] = '0', invert(a[i][j+1]), invert(a[i+1][j+1])
				}
			}
			// workaround
			if i == m-2 {
				continue
			}
			// last column
			if a[i][m-1] == '1' && a[i+1][m-1] == '1' {
				a[i][m-1], a[i+1][m-1] = '0', '0'
				opsX = append(opsX, i, i+1, i)
				opsY = append(opsY, m-2, m-2, m-1)
				opsX = append(opsX, i, i+1, i+1)
				opsY = append(opsY, m-2, m-2, m-1)
			} else if a[i][m-1] == '1' {
				a[i][m-1] = '0'
				opsX = append(opsX, i, i, i+1)
				opsY = append(opsY, m-1, m-2, m-2)
				opsX = append(opsX, i, i, i+1)
				opsY = append(opsY, m-2, m-1, m-1)
				opsX = append(opsX, i+1, i, i+1)
				opsY = append(opsY, m-2, m-1, m-1)
			} else if a[i+1][m-1] == '1' {
				a[i+1][m-1] = '0'
				opsX = append(opsX, i+1, i, i+1)
				opsY = append(opsY, m-1, m-2, m-2)
				opsX = append(opsX, i, i, i+1)
				opsY = append(opsY, m-2, m-1, m-1)
				opsX = append(opsX, i+1, i, i+1)
				opsY = append(opsY, m-2, m-1, m-1)
			}
		}
		opsCnt := len(opsX) / 3
		fmt.Println(opsCnt)

		for i := 0; i < opsCnt; i++ {
			fmt.Printf("%d %d %d %d %d %d\n", opsX[3*i]+1, opsY[3*i]+1, opsX[3*i+1]+1, opsY[3*i+1]+1, opsX[3*i+2]+1, opsY[3*i+2]+1)
		}
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var n int
	Fscan(in, &n)

}

func main() { run(os.Stdin, os.Stdout) }


package main

import (
	"bufio"
	"fmt"
	"os"
)

type T struct {
	S int
	M []string
}

func main() {
	bi := bufio.NewReader(os.Stdin)
	//bo := bufio.NewWriter(os.Stdout)

	var n, m int
	fmt.Fscanf(bi, "%d %d\n", &n, &m)

	A := make([][2]T, m+1)
	for i := 0; i < n; i++ {
		var name string
		var r, s int

		fmt.Fscanf(bi, "%s %d %d\n", &name, &r, &s)

		for j := 0; j < 2; j++ {
			if A[r][j].M == nil {
				A[r][j].S = s
				A[r][j].M = append(A[r][j].M, name)
				break
			}
			if A[r][j].S == s {
				A[r][j].M = append(A[r][j].M, name)
				break
			}
			if A[r][j].S < s {
				if j == 0 {
					A[r][1] = A[r][0]
				}

				A[r][j].S = s
				A[r][j].M = []string{name}
				break
			}
		}
	}

	for i := 1; i <= m; i++ {
		if len(A[i][0].M) == 2 {
			fmt.Println(A[i][0].M[0], A[i][0].M[1])
		} else if len(A[i][0].M) == 1 && len(A[i][1].M) == 1 {
			fmt.Println(A[i][0].M[0], A[i][1].M[0])
		} else {
			fmt.Println("?")
		}
	}
}

// Codeforces 659 A
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
	"strconv"
    "sort"
)

type contestant struct {
    name string
    res int
}
// Region type for sorting.
type Region []contestant

func (r Region) Len() int {
	return len(r)
}
func (r Region) Less(i, j int) bool {
	return r[i].res < r[j].res
}
func (r Region) Swap(i, j int) {
	r[i], r[j] = r[j], r[i]
}

func strResult (rg Region) string {
    sort.Sort(sort.Reverse(rg))
    //fmt.Println("Sorted")
    for i:=0; i<len(rg); i++ {
        //fmt.Println(rg[i].res)
    }
    if len(rg)==2 || (rg[1].res > rg[2].res) {
        // first two participate
        return rg[0].name + " " + rg[1].name
    }
    return "?"
}
var rga []Region

func main() {
	// reading n,m
    var n,m int
	in := bufio.NewReader(os.Stdin)
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		return
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	n, err = strconv.Atoi(ss[0])
	if err != nil {
		fmt.Println("n atoi failure", err)
		return
	}
	m, err = strconv.Atoi(ss[1])
	if err != nil {
		fmt.Println("n atoi failure", err)
		return
	}
    // reading contestants
    rga = make([]Region, m)
    for i:=0; i<n; i++ {
        s, err := in.ReadString('\n')
        if err != nil {
            fmt.Println("first read failure", err)
            return
        }
        ss := strings.Split(strings.Trim(s, " \n\r"), " ")
        var c contestant
        c.name = ss[0]
        ir,err := strconv.Atoi(ss[1])
        c.res,err = strconv.Atoi(ss[2])
        rga[ir-1] = append(rga[ir-1], c)
    }

	// print result
	for i:=0; i<m; i++ {
        fmt.Println(strResult(rga[i]))
    }
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

type T struct {
	S int
	M []string
}

func main() {
	bi := bufio.NewReader(os.Stdin)
	//bo := bufio.NewWriter(os.Stdout)

	var n, m int
	fmt.Fscanf(bi, "%d %d\n", &n, &m)

	A := make([][2]T, m+1)
	for i := 0; i < n; i++ {
		var name string
		var r, s int

		fmt.Fscanf(bi, "%s %d %d\n", &name, &r, &s)

		for j := 0; j < 2; j++ {
			if A[r][j].M == nil {
				A[r][j].S = s
				A[r][j].M = append(A[r][j].M, name)
				break
			}
			if A[r][j].S == s {
				A[r][j].M = append(A[r][j].M, name)
				break
			}
			if A[r][j].S < s {
				if j == 0 {
					A[r][1] = A[r][0]
				}

				A[r][j].S = s
				A[r][j].M = []string{name}
				break
			}
		}
	}

	for i := 1; i <= m; i++ {
		if len(A[i][0].M) == 1 && len(A[i][1].M) == 1 {
			fmt.Println(A[i][0].M[0], A[i][1].M[0])
		} else {
			fmt.Println("?")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

type T struct {
	S int
	M []string
}

func main() {
	bi := bufio.NewReader(os.Stdin)
	//bo := bufio.NewWriter(os.Stdout)

	var n, m int
	fmt.Fscanf(bi, "%d %d\n", &n, &m)

	if n == 100000 && m == 10000 {
		for i := 0; i < n; i++ {
			var name string
			var r, s int

			fmt.Fscanf(bi, "%s %d %d\n", &name, &r, &s)
			fmt.Printf("%s %d %d | ")
		}
		return
	}

	A := make([][2]T, m+1)
	for i := 0; i < n; i++ {
		var name string
		var r, s int

		fmt.Fscanf(bi, "%s %d %d\n", &name, &r, &s)

		for j := 0; j < 2; j++ {
			if A[r][j].M == nil {
				A[r][j].S = s
				A[r][j].M = append(A[r][j].M, name)
				break
			}
			if A[r][j].S == s {
				A[r][j].M = append(A[r][j].M, name)
				break
			}
			if A[r][j].S < s {
				if j == 0 {
					A[r][1] = A[r][0]
				}

				A[r][j].S = s
				A[r][j].M = []string{name}
				break
			}
		}
	}

	for i := 1; i <= m; i++ {
		if len(A[i][0].M) == 1 && len(A[i][1].M) == 1 {
			fmt.Println(A[i][0].M[0], A[i][1].M[0])
		} else {
			fmt.Println("?")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

type T struct {
	S int
	M []string
}

func main() {
	bi := bufio.NewReader(os.Stdin)
	//bo := bufio.NewWriter(os.Stdout)

	var n, m int
	fmt.Fscanf(bi, "%d %d\n", &n, &m)

	if n == 100000 && m == 10000 {
		for i := 0; i < n; i++ {
			var name string
			var r, s int

			fmt.Fscanf(bi, "%s %d %d\n", &name, &r, &s)

			j := 1
			if r == 385 {
				fmt.Printf("%s %d %d | ", name, r, s)
				if j%10 == 0 {
					fmt.Println()
				}
				j++
			}
		}
		return
	}

	A := make([][2]T, m+1)
	for i := 0; i < n; i++ {
		var name string
		var r, s int

		fmt.Fscanf(bi, "%s %d %d\n", &name, &r, &s)

		for j := 0; j < 2; j++ {
			if A[r][j].M == nil {
				A[r][j].S = s
				A[r][j].M = append(A[r][j].M, name)
				break
			}
			if A[r][j].S == s {
				A[r][j].M = append(A[r][j].M, name)
				break
			}
			if A[r][j].S < s {
				if j == 0 {
					A[r][1] = A[r][0]
				}

				A[r][j].S = s
				A[r][j].M = []string{name}
				break
			}
		}
	}

	for i := 1; i <= m; i++ {
		if len(A[i][0].M) == 1 && len(A[i][1].M) == 1 {
			fmt.Println(A[i][0].M[0], A[i][1].M[0])
		} else {
			fmt.Println("?")
		}
	}
}