You are given a matrix with n rows (numbered from 1 to n) and m columns (numbered from 1 to m). A number a_{i, j} is written in the cell belonging to the i-th row and the j-th column, each number is either 0 or 1.

A chip is initially in the cell (1, 1), and it will be moved to the cell (n, m). During each move, it either moves to the next cell in the current row, or in the current column (if the current cell is (x, y), then after the move it can be either (x + 1, y) or (x, y + 1)). The chip cannot leave the matrix.

Consider each path of the chip from (1, 1) to (n, m). A path is called palindromic if the number in the first cell is equal to the number in the last cell, the number in the second cell is equal to the number in the second-to-last cell, and so on.

Your goal is to change the values in the minimum number of cells so that every path is palindromic.

Input

The first line contains one integer t (1 ≤ t ≤ 200) — the number of test cases.

The first line of each test case contains two integers n and m (2 ≤ n, m ≤ 30) — the dimensions of the matrix.

Then n lines follow, the i-th line contains m integers a_{i, 1}, a_{i, 2}, ..., a_{i, m} (0 ≤ a_{i, j} ≤ 1).

Output

For each test case, print one integer — the minimum number of cells you have to change so that every path in the matrix is palindromic.

Example

Input


4
2 2
1 1
0 1
2 3
1 1 0
1 0 0
3 7
1 0 1 1 1 1 1
0 0 0 0 0 0 0
1 1 1 1 1 0 1
3 5
1 0 1 0 0
1 1 1 1 0
0 0 1 0 0


Output


0
3
4
4

Note

The resulting matrices in the first three test cases:

\begin{pmatrix} 1 & 1\\\ 0 & 1 \end{pmatrix}  \begin{pmatrix} 0 & 0 & 0\\\ 0 & 0 & 0 \end{pmatrix}  \begin{pmatrix} 1 & 0 & 1 & 1 & 1 & 1 & 1\\\ 0 & 1 & 1 & 0 & 1 & 1 & 0\\\ 1 & 1 & 1 & 1 & 1 & 0 & 1 \end{pmatrix} 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;

public class edu_89 {

	static class Reader {

		final private int BUFFER_SIZE = 1 << 12;
		boolean consume = false;
		private byte[] buffer;
		private int bufferPointer, bytesRead;
		private boolean reachedEnd = false;

		public Reader() {
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = 0;
			bytesRead = 0;
		}

		public boolean hasNext() {
			return !reachedEnd;
		}

		private void fillBuffer() throws IOException {
			bytesRead = System.in.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1) {
				buffer[0] = -1;
				reachedEnd = true;
			}
		}

		private void consumeSpaces() throws IOException {
			while (read() <= ' ' && reachedEnd == false)
				;
			bufferPointer--;
		}

		private byte read() throws IOException {
			if (bufferPointer == bytesRead) {
				fillBuffer();
			}
			return buffer[bufferPointer++];
		}

		public String next() throws IOException {
			StringBuilder sb = new StringBuilder();
			consumeSpaces();
			byte c = read();
			do {
				sb.append((char) c);
			} while ((c = read()) > ' ');
			if (consume) {
				consumeSpaces();
			}
			;
			if (sb.length() == 0) {
				return null;
			}
			return sb.toString();
		}

		public String nextLine() throws IOException {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String str = br.readLine();
			return str;
		}

		public int nextInt() throws IOException {
			consumeSpaces();
			int ret = 0;
			byte c = read();
			boolean neg = (c == '-');
			if (neg) {
				c = read();
			}
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (consume) {
				consumeSpaces();
			}
			if (neg) {
				return -ret;
			}
			return ret;
		}

		public long nextLong() throws IOException {
			consumeSpaces();
			long ret = 0;
			byte c = read();
			boolean neg = (c == '-');
			if (neg) {
				c = read();
			}
			do {
				ret = ret * 10L + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (consume) {
				consumeSpaces();
			}
			if (neg) {
				return -ret;
			}
			return ret;
		}

		public double nextDouble() throws IOException {
			consumeSpaces();
			double ret = 0;
			double div = 1;
			byte c = read();
			boolean neg = (c == '-');
			if (neg) {
				c = read();
			}
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (c == '.') {
				while ((c = read()) >= '0' && c <= '9') {
					ret += (c - '0') / (div *= 10);
				}
			}
			if (consume) {
				consumeSpaces();
			}
			if (neg) {
				return -ret;
			}
			return ret;
		}

		public int[] nextIntArray(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextInt();
			}
			return a;
		}

		public int[][] nextIntMatrix(int n, int m) throws IOException {
			int[][] grid = new int[n][m];
			for (int i = 0; i < n; i++) {
				grid[i] = nextIntArray(m);
			}
			return grid;
		}

		public char[][] nextCharacterMatrix(int n) throws IOException {
			char[][] a = new char[n][];
			for (int i = 0; i < n; i++) {
				a[i] = next().toCharArray();
			}
			return a;
		}

		public void close() throws IOException {
			if (System.in == null) {
				return;
			} else {
				System.in.close();
			}
		}
	}

	static Reader r = new Reader();
	static PrintWriter out = new PrintWriter(System.out);

	private static void solve1() throws IOException {

		int t = r.nextInt();
		StringBuilder res = new StringBuilder();

		while (t-- > 0) {

			int a = r.nextInt();
			int b = r.nextInt();

			int ans = 0;

			int temp = a;
			a = Math.max(a, b);
			b = Math.min(temp, b);

			if (a > 0 && b > 0) {
				ans = (a + b) / 3;
				ans = Math.min(ans, b);
			}

			res.append(ans).append("\n");

		}

		out.print(res);
		out.close();
	}

	private static void solve2() throws IOException {

		int t = r.nextInt();
		StringBuilder res = new StringBuilder();

		while (t-- > 0) {

			int n = r.nextInt();
			int x = r.nextInt();
			int m = r.nextInt();

			int lt = x, rt = x;

			while (m-- > 0) {

				int i = r.nextInt();
				int j = r.nextInt();

				if (lt <= i && rt >= i || lt <= j && rt >= j || i <= lt && j >= lt || i <= rt && j >= rt) {
					lt = Math.min(lt, i);
					rt = Math.max(rt, j);
				}

			}

			res.append(rt - lt + 1).append("\n");

		}

		out.print(res);
		out.close();
	}

	private static void solve3() throws IOException {

		int t = r.nextInt();
		StringBuilder res = new StringBuilder();

		while (t-- > 0) {

			int n = r.nextInt();
			int m = r.nextInt();

			ArrayList<Integer> pal[] = new ArrayList[n + m];
			for (int i = 0; i < n + m; i++) {
				pal[i] = new ArrayList<Integer>();
			}

			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					int ele = r.nextInt();
					int pal_idx_start = i + j;
					int pal_idx_end = (n - 1 - i) + (m - 1 - j);
					if (pal_idx_start != pal_idx_end) {
						pal[Math.min(pal_idx_start, pal_idx_end)].add(ele);
					}
				}
			}

			int ans = 0;
			for (int i = 0; i < n + m; i++) {
				int zero = 0, one = 0;
				for (int ele : pal[i]) {
					if (ele == 0)
						zero++;
					else
						one++;
				}
				ans += Math.min(zero, one);
			}

			res.append(ans).append("\n");

		}

		out.print(res);
		out.close();

	}

	static int MAXN = (int) 1e7 + 1;
	static int spf[] = new int[MAXN];

	private static void modifiedSeive() {
		spf[1] = 1;
		for (int i = 2; i < MAXN; i++) {
			if ((i & 1) == 0 && i > 2) {
				spf[i] = 2;
			} else {
				spf[i] = i;
			}
		}
		for (int i = 3; i * i < MAXN; i++) {
			if (spf[i] == i) {
				for (int j = i * i; j < MAXN; j += i)
					if (spf[j] == j)
						spf[j] = i;
			}
		}
	}

	private static void solve4() throws IOException {

		int n = r.nextInt();

		StringBuilder res1 = new StringBuilder();
		StringBuilder res2 = new StringBuilder();

		modifiedSeive();

		for (int i = 0; i < n; i++) {
			int ele = r.nextInt();
			int d1 = -1, d2 = -1;
			if (spf[ele] != ele) {
				d1 = spf[ele];
				while (ele % d1 == 0) {
					ele /= d1;
				}
				if (ele == 1) {
					d1 = -1;
				} else {
					d2 = ele;
				}
			}
			res1.append(d1).append(" ");
			res2.append(d2).append(" ");
		}

		out.print(res1 + "\n" + res2);
		out.close();

	}

	public static void main(String[] args) throws IOException {

//		solve1();

//		solve2();

		solve3();

//		solve4();
	}

}