Identify the time complexity of the following code as constant, linear, quadratic, cubic, log(n), nlog(n) or NP-hard. import java.io.*;
import java.util.*;

public class E implements Runnable {
	FastReader scn;
	PrintWriter out;
	String INPUT = "";

	void solve() {
		int t = scn.nextInt();
		while(t-- > 0) {
			int n = scn.nextInt(), m = scn.nextInt();
			int[][] arr = scn.next2DInt(n, m);
			
			int[][] col = new int[m][2];
			for(int j = 0; j < m; j++) {
				int max = 0;
				for(int i = 0; i < n; i++) {
					max = Math.max(max, arr[i][j]);
				}
				col[j][0] = max;
				col[j][1] = j;
			}
			Arrays.parallelSort(col, (o1, o2) -> o2[0] - o1[0]);
			
			int take = Math.min(n, m);
			
			int[][] lol = new int[n][take];
			for(int j = 0; j < take; j++) {
				for(int i = 0; i < n; i++) {
					lol[i][j] = arr[i][col[j][1]];
				}
			}
			
			ans = 0;
			func(lol, 0);
			out.println(ans);
		}
	}
	
	int ans = 0;
	
	void func(int[][] arr, int col) {
		int n = arr.length, m = arr[0].length;
		if(col == m) {
			int rv = 0;
			for(int i = 0; i < n; i++) {
				int mx = 0;
				for(int j = 0; j < m; j++) {
					mx = Math.max(mx, arr[i][j]);
				}
				rv += mx; 
			}
			ans = Math.max(ans, rv);
			return;
		}
		
		for(int rot = 0; rot < n; rot++) {
			int f = arr[0][col];
			for(int j = 1; j < n; j++) {
				arr[j - 1][col] = arr[j][col];
			}
			arr[n - 1][col] = f;
			func(arr, col + 1);
		}
	}

	public void run() {
		long time = System.currentTimeMillis();
		boolean oj = System.getProperty("ONLINE_JUDGE") != null;
		out = new PrintWriter(System.out);
		scn = new FastReader(oj);
		solve();
		out.flush();
		if (!oj) {
			System.out.println(Arrays.deepToString(new Object[] { System.currentTimeMillis() - time + " ms" }));
		}
	}

	public static void main(String[] args) {
		new Thread(null, new E(), "Main", 1 << 26).start();
	}

	class FastReader {
		InputStream is;

		public FastReader(boolean onlineJudge) {
			is = onlineJudge ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		}

		byte[] inbuf = new byte[1024];
		public int lenbuf = 0, ptrbuf = 0;

		int readByte() {
			if (lenbuf == -1)
				throw new... Complexity: