This is an easier version of the next problem. The difference is only in constraints.

You are given a rectangular n × m matrix a. In one move you can choose any column and cyclically shift elements in this column. You can perform this operation as many times as you want (possibly zero). You can perform this operation to a column multiple times.

After you are done with cyclical shifts, you compute for every row the maximal value in it. Suppose that for i-th row it is equal r_i. What is the maximal possible value of r_1+r_2+…+r_n?

Input

The first line contains an integer t (1 ≤ t ≤ 40), the number of test cases in the input.

The first line of each test case contains integers n and m (1 ≤ n ≤ 4, 1 ≤ m ≤ 100) — the number of rows and the number of columns in the given matrix a. 

Each of the following n lines contains m integers, the elements of a (1 ≤ a_{i, j} ≤ 10^5).

Output

Print t integers: answers for all test cases in the order they are given in the input.

Example

Input


2
2 3
2 5 7
4 2 4
3 6
4 1 5 2 10 4
8 6 6 4 9 10
5 4 9 5 8 7


Output


12
29

Note

In the first test case, you can shift the third column down by one, this way there will be r_1 = 5 and r_2 = 7.

In the second case you can don't rotate anything at all, this way there will be r_1 = r_2 = 10 and r_3 = 9.
import java.util.*;
import java.io.*;

public class CFA {
  BufferedReader br;
  PrintWriter out;
  StringTokenizer st;
  boolean eof;
  private static final long MOD = 1000L * 1000L * 1000L + 7;
  private static final int[] dx = {0, -1, 0, 1};
  private static final int[] dy = {1, 0, -1, 0};
  private static final String yes = "Yes";
  private static final String no = "No";

  void solve() {
    int T = nextInt();
//    int T = 1;
    for (int i = 0; i < T; i++) {
      helper();
    }
  }

  void helper() {
    int n = nextInt();
    int m = nextInt();
    int[][] mat = new int[n][m];
    List<Integer> all = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      mat[i] = nextIntArr(m);
      for (int v : mat[i]) {
        all.add(v);
      }
    }
    Collections.sort(all);
    Collections.reverse(all);
    if (n < 4) {
      int res = 0;
      for (int i = 0; i < n; i++) {
        res += all.get(i);
      }
      outln(res);
      return;
    }
    int res = 0;
    int[] maxCol = new int[m];
    for (int j = 0; j < m; j++) {
      int tmp = 0;
      for (int i = 0; i < n; i++) {
        tmp = Math.max(tmp, mat[i][j]);
      }
      maxCol[j] = tmp;
    }
    for (int j1 = 0; j1 < m; j1++) {
      List<Integer> col = new ArrayList<>();
      for (int i = 0; i < n; i++) {
        col.add(mat[i][j1]);
      }
      Collections.sort(col);
      Collections.reverse(col);

      List<Integer> others = new ArrayList<>();
      for (int j2 = 0; j2 < m; j2++) {
        if (j2 != j1) {
          others.add(maxCol[j2]);
        }
      }

      Collections.sort(others);
      Collections.reverse(others);

      // Take one from col, three from others
      if (others.size() >= 3) {
        int tmp = col.get(0);
        for (int i = 0; i < 3; i++) {
          tmp+= others.get(i);
        }
        res = Math.max(res, tmp);
      }
      // Take two from col, two from others
      if (others.size() >= 2) {
        int tmp = col.get(0) + col.get(1);
        tmp += others.get(0) + others.get(1);
        res = Math.max(res, tmp);
      }
      // Take three from col, one from others
      if (others.size() >= 1) {
        int tmp = col.get(0) + col.get(1) + col.get(2);
        tmp += others.get(0);
        res = Math.max(res, tmp);
      }
      // Take all from col
      res = Math.max(res, col.get(0) + col.get(1) + col.get(2) + col.get(3));
    }

    for (int j1 = 0; j1 < m; j1++) {
      for (int j2 = 0; j2 < m; j2++) {
        if (j2 != j1) {
          for (int i1 = 0; i1 <= 3; i1++) {
            for (int i = 0; i <= 3; i++) {
              int tmp = mat[i1][j1] + mat[(i1 + 1) % 4][j1];
              tmp += mat[i][j2] + mat[(i + 1) % 4][j2];
              res = Math.max(res, tmp);
            }
          }

          int m1 = mat[0][j1] + mat[2][j1];
          m1 = Math.max(m1, mat[1][j1] + mat[3][j1]);
          int m2 = mat[0][j2] + mat[2][j2];
          m2 = Math.max(m2, mat[1][j2] + mat[3][j2]);
          res = Math.max(res, m1 + m2);
        }
      }
    }

    outln(res);
  }

  void shuffle(long[] a) {
    int n = a.length;
    for(int i = 0; i < n; i++) {
      int r = i + (int) (Math.random() * (n - i));
      long tmp = a[i];
      a[i] = a[r];
      a[r] = tmp;
    }
  }

  int gcd(int a, int b) {
    while(a != 0 && b != 0) {
      int c = b;
      b = a % b;
      a = c;
    }
    return a + b;
  }
  private void outln(Object o) {
    out.println(o);
  }
  private void out(Object o) {
    out.print(o);
  }
  private void formatPrint(double val) {
    outln(String.format("%.9f%n", val));
  }
  public CFA() {
    br = new BufferedReader(new InputStreamReader(System.in));
    out = new PrintWriter(System.out);
    solve();
    out.close();
  }
  public static void main(String[] args) {
    new CFA();
  }

  public long[] nextLongArr(int n) {
    long[] res = new long[n];
    for(int i = 0; i < n; i++)
      res[i] = nextLong();
    return res;
  }
  public int[] nextIntArr(int n) {
    int[] res = new int[n];
    for(int i = 0; i < n; i++)
      res[i] = nextInt();
    return res;
  }
  public String nextToken() {
    while (st == null || !st.hasMoreTokens()) {
      try {
        st = new StringTokenizer(br.readLine());
      } catch (Exception e) {
        eof = true;
        return null;
      }
    }
    return st.nextToken();
  }
  public String nextString() {
    try {
      return br.readLine();
    } catch (IOException e) {
      eof = true;
      return null;
    }
  }
  public int nextInt() {
    return Integer.parseInt(nextToken());
  }
  public long nextLong() {
    return Long.parseLong(nextToken());
  }
  public double nextDouble() {
    return Double.parseDouble(nextToken());
  }
}
