Problem: This is the easy version of the problem. The difference between the versions is in the number of possible operations that can be made. You can make hacks if and only if you solved both versions of the problem.

You are given a binary table of size n × m. This table consists of symbols 0 and 1.

You can make such operation: select 3 different cells that belong to one 2 × 2 square and change the symbols in these cells (change 0 to 1 and 1 to 0).

Your task is to make all symbols in the table equal to 0. You are allowed to make at most 3nm operations. You don't need to minimize the number of operations.

It can be proved that it is always possible.

Input

The first line contains a single integer t (1 ≤ t ≤ 5000) — the number of test cases. The next lines contain descriptions of test cases.

The first line of the description of each test case contains two integers n, m (2 ≤ n, m ≤ 100).

Each of the next n lines contains a binary string of length m, describing the symbols of the next row of the table.

It is guaranteed that the sum of nm for all test cases does not exceed 20000.

Output

For each test case print the integer k (0 ≤ k ≤ 3nm) — the number of operations.

In the each of the next k lines print 6 integers x_1, y_1, x_2, y_2, x_3, y_3 (1 ≤ x_1, x_2, x_3 ≤ n, 1 ≤ y_1, y_2, y_3 ≤ m) describing the next operation. This operation will be made with three cells (x_1, y_1), (x_2, y_2), (x_3, y_3). These three cells should be different. These three cells should belong into some 2 × 2 square.

Example

Input


5
2 2
10
11
3 3
011
101
110
4 4
1111
0110
0110
1111
5 5
01011
11001
00010
11011
10000
2 3
011
101


Output


1
1 1 2 1 2 2
2 
2 1 3 1 3 2
1 2 1 3 2 3
4
1 1 1 2 2 2 
1 3 1 4 2 3
3 2 4 1 4 2
3 3 4 3 4 4
4
1 2 2 1 2 2 
1 4 1 5 2 5 
4 1 4 2 5 1
4 4 4 5 3 4
2
1 3 2 2 2 3
1 2 2 1 2 2

Note

In the first test case, it is possible to make only one operation with cells (1, 1), (2, 1), (2, 2). After that, all symbols will be equal to 0.

In the second test case:

  * operation with cells (2, 1), (3, 1), (3, 2). After it the table will be: 
    
          
    011  
    001  
    000  
    

  * operation with cells (1, 2), (1, 3), (2, 3). After it the table will be: 
    
          
    000  
    000  
    000  
    




In the fifth test case:

  * operation with cells (1, 3), (2, 2), (2, 3). After it the table will be: 
    
          
    010  
    110  
    

  * operation with cells (1, 2), (2, 1), (2, 2). After it the table will be: 
    
          
    000  
    000  
    

Solution (in JAVA):

Solution:



import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

/**
 * @author b
 *
 */
public class C {

	private static Scanner scanner;
	private static PrintWriter writer;

	public static void main(String[] args) {
		scanner = new Scanner();
		writer = new PrintWriter(System.out);
		int tests = scanner.nextInt();
		for (int i = 0; i < tests; i++) {
			solve();
		}
		writer.close();
	}

	private static void solve() {
		int rows = scanner.nextInt(),
				cols = scanner.nextInt();

		boolean[][] matrix = new boolean[rows][cols];

		for (int r=0; r <rows; r++) {
			char[] rowStr = scanner.next().toCharArray();
			for (int c=0; c < cols; c++) {
				matrix[r][c] = rowStr[c] == '1';
			}
		}

		List<Transition> transitions = new ArrayList<>();

		for (int r=0; r < rows-1; r++) {
			for (int c=0; c < cols-1; c++) {
				boolean isLastCellInRowOrCol = r == rows -2 || c == cols-2;
				if (isLastCellInRowOrCol) {
					int countOnes = countOnesInCell(matrix, r,c);
					switch (countOnes) {
					case 4:
						switchVal(matrix, r, c);
						switchVal(matrix, r, c+1);
						switchVal(matrix, r+1, c);
						transitions.add(new Transition(r, c, r, c+1, r+1, c));
					case 1:
						processFor3And1Ones(matrix, transitions, r, c);
					case 2:
						processFor2Ones(matrix, transitions, r, c);
					case 3:
						processFor3And1Ones(matrix, transitions, r, c);
					default:
						break;
					}
				} else {
					if (matrix[r][c] && matrix[r][c+1]) {
						switchVal(matrix, r, c);
						switchVal(matrix, r, c+1);
						switchVal(matrix, r+1, c);
						transitions.add(new Transition(r, c, r, c+1, r+1, c));
					} else if (matrix[r][c]) {
						switchVal(matrix, r, c);
						switchVal(matrix, r+1, c);
						switchVal(matrix, r+1, c+1);
						transitions.add(new Transition(r, c, r+1, c, r+1, c+1));
					}else if (matrix[r][c+1]) {
						switchVal(matrix, r, c+1);
						switchVal(matrix, r+1, c);
						switchVal(matrix, r+1, c+1);
						transitions.add(new Transition(r, c+1, r+1, c, r+1, c+1));
					}
				}
			}
		}

		// print result
		writer.println(transitions.size());
		for (Transition t : transitions) {
			writer.println(t.toString());
		}

	}
	//
	//	private static void printBoard(boolean[][] matrix) {
	//
	//		for (int i=0; i < matrix.length; i++) {
	//			for (int j=0; j < matrix[0].length; j++) {
	//				System.out.print(matrix[i][j] ? '1' : '0');
	//			}
	//			System.out.println();
	//		}
	//		System.out.println();
	//
	//	}

	private static void processFor3And1Ones(boolean[][] matrix, List<Transition> transitions, int r, int c) {
		List<Cell> cellWithOneInIt = getCellsWith1(matrix,r,c);
		List<Cell> cellsToSwitch = findCells(cellWithOneInIt, r, c);
		addTransitions(matrix, transitions, cellsToSwitch);
	}

	private static void processFor2Ones(boolean[][] matrix, List<Transition> transitions, int r, int c) {
		List<Cell> cellWithOneInIt = getCellsWith1(matrix,r,c);
		List<Cell> cellsToKeep = findCellsBut(cellWithOneInIt, r, c);
		cellsToKeep.add(cellWithOneInIt.get(0));
		addTransitions(matrix, transitions, cellsToKeep);
	}

	private static void addTransitions(boolean[][] matrix, List<Transition> transitions, List<Cell> cellsToSwitch) {

		if (cellsToSwitch.size() != 3) {
			throw new RuntimeException();
		}

		Transition t = new Transition();
		for (Cell ce : cellsToSwitch) {
			switchVal(matrix, ce.r, ce.c);
			t.addNext(ce.r, ce.c);
		}
		transitions.add(t);
	}




	private static List<Cell> getCellsWith1(boolean[][] matrix, int r, int c) {
		List<Cell> cells = new ArrayList<>();
		if (matrix[r][c]) cells.add(new Cell(r,c));
		if (matrix[r+1][c])  cells.add(new Cell(r+1,c));
		if (matrix[r][c+1])  cells.add(new Cell(r,c+1));
		if (matrix[r+1][c+1]) cells.add(new Cell(r+1,c+1));
		return cells;
	}



	private static List<Cell> findCellsBut(List<Cell> excludeThese, int r, int c) {

		List<Cell> possibleCells = new ArrayList<>();
		possibleCells.add(new Cell(r, c));
		possibleCells.add(new Cell(r+1, c));
		possibleCells.add(new Cell(r, c+1));
		possibleCells.add(new Cell(r+1, c+1));

		possibleCells.removeAll(excludeThese);

		return possibleCells;
	}


	private static List<Cell> findCells(List<Cell> alreadySetCells, int r, int c) {

		List<Cell> possibleCells = new ArrayList<>();
		possibleCells.add(new Cell(r, c));
		possibleCells.add(new Cell(r+1, c));
		possibleCells.add(new Cell(r, c+1));
		possibleCells.add(new Cell(r+1, c+1));

		possibleCells.removeAll(alreadySetCells);

		int i = 0;
		while (alreadySetCells.size() < 3) {
			alreadySetCells.add(possibleCells.get(i++));
		}
		return alreadySetCells;
	}


	private static int countOnesInCell(boolean[][] matrix, int r, int c) {
		return toInt(matrix[r][c]) +
				toInt(matrix[r][c+1]) +
				toInt(matrix[r+1][c]) +
				toInt(matrix[r+1][c+1]);
	}

	private static int toInt(boolean b) {
		return b ? 1 : 0;
	}

	private static void switchVal(boolean[][] matrix, int r, int c) {
		matrix[r][c] = !matrix[r][c];
	}

	private static class Cell {
		int r,c;

		public Cell(int r, int c) {
			this.r = r;
			this.c = c;
		}

		@Override
		public String toString() {
			return "Cell [r=" + r + ", c=" + c + "]";
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + c;
			result = prime * result + r;
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			Cell other = (Cell) obj;
			if (c != other.c)
				return false;
			if (r != other.r)
				return false;
			return true;
		}


	}

	private static class Transition {

		int r1, c1, r2, c2, r3, c3;
		int pos = 0;

		public Transition(int r1, int c1, int r2, int c2, int r3, int c3) {
			this.r1 = r1 +1;
			this.c1 = c1+1;
			this.r2 = r2+1;
			this.c2 = c2+1;
			this.r3 = r3+1;
			this.c3 = c3+1;
		}

		public void addNext(int r, int c) {
			if (pos == 0) {
				r1 =r+1;
				c1 = c+1;
			} else if (pos == 1) {
				r2 = r+1;
				c2 = c+1;
			} else if (pos == 2) {
				r3 = r+1;
				c3 = c+1;
			} else {
				throw new RuntimeException();
			}

			pos++;
		}

		public Transition() {
			// TODO Auto-generated constructor stub
		}

		@Override
		public String toString() {
			return r1 + " " + c1 + " " +r2 + " " + c2 + " "+r3 + " " + c3;
		}



	}

	@SuppressWarnings("unused")
	private static void print(String... args) {

		for (String arg : args) {

			writer.print(arg + " ");
		}
		writer.println();
	}

	// Props to SecondThread
	static class Scanner {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer tokenizer = new StringTokenizer("");

		String next() {
			while (!tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return tokenizer.nextToken();
		}

		long[] nextLongArr(int num) {
			long[] vals = new long[num];
			for (int i = 0; i < num; i++)
				vals[i] = nextLong();
			return vals;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] nextIntArr(int numberOfElements) {
			int[] values = new int[numberOfElements];
			for (int i = 0; i < numberOfElements; i++)
				values[i] = nextInt();
			return values;
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}

}