source_code: 
  
  import java.io.FileInputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.lang.reflect.Array;
  import java.math.BigInteger;
  import java.nio.charset.Charset;
  import java.util.*;
  
  
  public class CFContest {
      public static void main(String[] args) throws Exception {
          boolean local = System.getProperty("ONLINE_JUDGE") == null;
          boolean async = true;
  
          Charset charset = Charset.forName("ascii");
  
          FastIO io = local ? new FastIO(new FileInputStream("D:\\DATABASE\\TESTCASE\\Code.in"), System.out, charset) : new FastIO(System.in, System.out, charset);
          Task task = new Task(io, new Debug(local));
  
          if (async) {
              Thread t = new Thread(null, task, "dalt", 1 << 27);
              t.setPriority(Thread.MAX_PRIORITY);
              t.start();
              t.join();
          } else {
              task.run();
          }
  
          if (local) {
              io.cache.append("\n\n--memory -- \n" + ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) >> 20) + "M");
          }
  
          io.flush();
      }
  
      public static class Task implements Runnable {
          final FastIO io;
          final Debug debug;
          int inf = (int) 1e8;
          long lInf = (long) 1e18;
  
          public Task(FastIO io, Debug debug) {
              this.io = io;
              this.debug = debug;
          }
  
          @Override
          public void run() {
              int t = io.readInt();
              while (t-- > 0)
                  solve1();
          }
  
  
          public void solve1() {
              cache.clear();
              int n = io.readInt();
              int m = io.readInt();
              Col[] mat = new Col[m];
              for (int i = 0; i < m; i++) {
                  mat[i] = new Col();
                  mat[i].data = new int[n];
              }
  
              for (int i = 0; i < n; i++) {
                  for (int j = 0; j < m; j++) {
                      int v = io.readInt();
                      mat[j].data[i] = v;
                      mat[j].max = Math.max(mat[j].max, v);
                  }
              }
  
              Arrays.sort(mat, (a, b) -> -(a.max - b.max));
              mat = Arrays.copyOf(mat, Math.min(n, m));
              io.cache.append(bf(mat, getCol(n), n, 0)).append('\n');
          }
  
          public void enhance(Col mask, Col c, Col ans, int n) {
              for (int i = 0; i < n; i++) {
                  ans.data[i] = Math.max(mask.get(i), c.get(i));
              }
          }
  
          Deque<Col> cache = new ArrayDeque<>();
  
          public Col getCol(int n) {
              if (cache.isEmpty()) {
                  Col col = new Col();
                  col.data = new int[n];
                  return col;
              }
              return cache.removeFirst();
          }
  
          public void destroy(Col c) {
              c.offset = 0;
              c.max = 0;
              cache.addLast(c);
          }
  
          public int bf(Col[] cols, Col mask, int n, int k) {
              if (k >= cols.length) {
                  int sum = 0;
                  for (int i = 0; i < n; i++) {
                      sum += mask.data[i];
                  }
                  return sum;
              }
  
              int max = 0;
              cols[k].offset = 0;
  
              for (int i = 0; i < n; i++) {
                  Col c = getCol(n);
                  enhance(mask, cols[k], c, n);
                  max = Math.max(max, bf(cols, c, n, k + 1));
                  destroy(c);
                  cols[k].turn();
              }
  
              return max;
          }
  
      }
  
      public static class Col {
          int[] data;
          int offset;
  
          public int get(int i) {
              return data[(i + offset) % data.length];
          }
  
          public void turn() {
              offset++;
          }
  
          int max;
      }
  
  
      public static class FastIO {
          public final StringBuilder cache = new StringBuilder(20 << 20);
          private final InputStream is;
          private final OutputStream os;
          private final Charset charset;
          private StringBuilder defaultStringBuf = new StringBuilder(1 << 8);
          private byte[] buf = new byte[1 << 20];
          private int bufLen;
          private int bufOffset;
          private int next;
  
          public FastIO(InputStream is, OutputStream os, Charset charset) {
              this.is = is;
              this.os = os;
              this.charset = charset;
          }
  
          public FastIO(InputStream is, OutputStream os) {
              this(is, os, Charset.forName("ascii"));
          }
  
          private int read() {
              while (bufLen == bufOffset) {
                  bufOffset = 0;
                  try {
                      bufLen = is.read(buf);
                  } catch (IOException e) {
                      throw new RuntimeException(e);
                  }
                  if (bufLen == -1) {
                      return -1;
                  }
              }
              return buf[bufOffset++];
          }
  
          public void skipBlank() {
              while (next >= 0 && next <= 32) {
                  next = read();
              }
          }
  
          public int readInt() {
              int sign = 1;
  
              skipBlank();
              if (next == '+' || next == '-') {
                  sign = next == '+' ? 1 : -1;
                  next = read();
              }
  
              int val = 0;
              if (sign == 1) {
                  while (next >= '0' && next <= '9') {
                      val = val * 10 + next - '0';
                      next = read();
                  }
              } else {
                  while (next >= '0' && next <= '9') {
                      val = val * 10 - next + '0';
                      next = read();
                  }
              }
  
              return val;
          }
  
          public long readLong() {
              int sign = 1;
  
              skipBlank();
              if (next == '+' || next == '-') {
                  sign = next == '+' ? 1 : -1;
                  next = read();
              }
  
              long val = 0;
              if (sign == 1) {
                  while (next >= '0' && next <= '9') {
                      val = val * 10 + next - '0';
                      next = read();
                  }
              } else {
                  while (next >= '0' && next <= '9') {
                      val = val * 10 - next + '0';
                      next = read();
                  }
              }
  
              return val;
          }
  
          public double readDouble() {
              boolean sign = true;
              skipBlank();
              if (next == '+' || next == '-') {
                  sign = next == '+';
                  next = read();
              }
  
              long val = 0;
              while (next >= '0' && next <= '9') {
                  val = val * 10 + next - '0';
                  next = read();
              }
              if (next != '.') {
                  return sign ? val : -val;
              }
              next = read();
              long radix = 1;
              long point = 0;
              while (next >= '0' && next <= '9') {
                  point = point * 10 + next - '0';
                  radix = radix * 10;
                  next = read();
              }
              double result = val + (double) point / radix;
              return sign ? result : -result;
          }
  
          public String readString(StringBuilder builder) {
              skipBlank();
  
              while (next > 32) {
                  builder.append((char) next);
                  next = read();
              }
  
              return builder.toString();
          }
  
          public String readString() {
              defaultStringBuf.setLength(0);
              return readString(defaultStringBuf);
          }
  
          public int readLine(char[] data, int offset) {
              int originalOffset = offset;
              while (next != -1 && next != '\n') {
                  data[offset++] = (char) next;
                  next = read();
              }
              return offset - originalOffset;
          }
  
          public int readString(char[] data, int offset) {
              skipBlank();
  
              int originalOffset = offset;
              while (next > 32) {
                  data[offset++] = (char) next;
                  next = read();
              }
  
              return offset - originalOffset;
          }
  
          public int readString(byte[] data, int offset) {
              skipBlank();
  
              int originalOffset = offset;
              while (next > 32) {
                  data[offset++] = (byte) next;
                  next = read();
              }
  
              return offset - originalOffset;
          }
  
          public char readChar() {
              skipBlank();
              char c = (char) next;
              next = read();
              return c;
          }
  
          public void flush() {
              try {
                  os.write(cache.toString().getBytes(charset));
                  os.flush();
                  cache.setLength(0);
              } catch (IOException e) {
                  throw new RuntimeException(e);
              }
          }
  
          public boolean hasMore() {
              skipBlank();
              return next != -1;
          }
      }
  
      public static class Debug {
          private boolean allowDebug;
  
          public Debug(boolean allowDebug) {
              this.allowDebug = allowDebug;
          }
  
          public void assertTrue(boolean flag) {
              if (!allowDebug) {
                  return;
              }
              if (!flag) {
                  fail();
              }
          }
  
          public void fail() {
              throw new RuntimeException();
          }
  
          public void assertFalse(boolean flag) {
              if (!allowDebug) {
                  return;
              }
              if (flag) {
                  fail();
              }
          }
  
          private void outputName(String name) {
              System.out.print(name + " = ");
          }
  
          public void debug(String name, int x) {
              if (!allowDebug) {
                  return;
              }
  
              outputName(name);
              System.out.println("" + x);
          }
  
          public void debug(String name, long x) {
              if (!allowDebug) {
                  return;
              }
              outputName(name);
              System.out.println("" + x);
          }
  
          public void debug(String name, double x) {
              if (!allowDebug) {
                  return;
              }
              outputName(name);
              System.out.println("" + x);
          }
  
          public void debug(String name, int[] x) {
              if (!allowDebug) {
                  return;
              }
              outputName(name);
              System.out.println(Arrays.toString(x));
          }
  
          public void debug(String name, long[] x) {
              if (!allowDebug) {
                  return;
              }
              outputName(name);
              System.out.println(Arrays.toString(x));
          }
  
          public void debug(String name, double[] x) {
              if (!allowDebug) {
                  return;
              }
              outputName(name);
              System.out.println(Arrays.toString(x));
          }
  
          public void debug(String name, Object x) {
              if (!allowDebug) {
                  return;
              }
              outputName(name);
              System.out.println("" + x);
          }
  
          public void debug(String name, Object... x) {
              if (!allowDebug) {
                  return;
              }
              outputName(name);
              System.out.println(Arrays.deepToString(x));
          }
      }
  }