description: Vlad has n friends, for each of whom he wants to buy one gift for the New Year.
  
  There are m shops in the city, in each of which he can buy a gift for any of his friends. If the j-th friend (1 ≤ j ≤ n) receives a gift bought in the shop with the number i (1 ≤ i ≤ m), then the friend receives p_{ij} units of joy. The rectangular table p_{ij} is given in the input.
  
  Vlad has time to visit at most n-1 shops (where n is the number of friends). He chooses which shops he will visit and for which friends he will buy gifts in each of them.
  
  Let the j-th friend receive a_j units of joy from Vlad's gift. Let's find the value α=min\\{a_1, a_2, ..., a_n\}. Vlad's goal is to buy gifts so that the value of α is as large as possible. In other words, Vlad wants to maximize the minimum of the joys of his friends.
  
  For example, let m = 2, n = 2. Let the joy from the gifts that we can buy in the first shop: p_{11} = 1, p_{12}=2, in the second shop: p_{21} = 3, p_{22}=4.
  
  Then it is enough for Vlad to go only to the second shop and buy a gift for the first friend, bringing joy 3, and for the second — bringing joy 4. In this case, the value α will be equal to min\{3, 4\} = 3
  
  Help Vlad choose gifts for his friends so that the value of α is as high as possible. Please note that each friend must receive one gift. Vlad can visit at most n-1 shops (where n is the number of friends). In the shop, he can buy any number of gifts.
  
  Input
  
  The first line of the input contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input.
  
  An empty line is written before each test case. Then there is a line containing integers m and n (2 ≤ n, 2 ≤ n ⋅ m ≤ 10^5) separated by a space — the number of shops and the number of friends, where n ⋅ m is the product of n and m.
  
  Then m lines follow, each containing n numbers. The number in the i-th row of the j-th column p_{ij} (1 ≤ p_{ij} ≤ 10^9) is the joy of the product intended for friend number j in shop number i.
  
  It is guaranteed that the sum of the values n ⋅ m over all test cases in the test does not exceed 10^5.
  
  Output
  
  Print t lines, each line must contain the answer to the corresponding test case — the maximum possible value of α, where α is the minimum of the joys from a gift for all of Vlad's friends.
  
  Example
  
  Input
  
  
  5
  
  2 2
  1 2
  3 4
  
  4 3
  1 3 1
  3 1 1
  1 2 2
  1 1 3
  
  2 3
  5 3 4
  2 5 1
  
  4 2
  7 9
  8 1
  9 6
  10 8
  
  2 4
  6 5 2 1
  7 9 7 2
  
  
  Output
  
  
  3
  2
  4
  8
  2
solution: import java.io.*;
  import java.util.*;
  
  import static java.lang.Math.abs;
  
  
  public class Main {
      long M = 1000000007;
      boolean multiCase = true;
  
      private void preparation() {
  
      }
  
      private void solve() throws Exception {
          rf();rf();
          int m = ri();
          int n = ri();
          int [][] p = new int[m][n];
          for(int i = 0; i < m; i++){
              rf();
              for(int j = 0; j < n; j++){
                  p[i][j] = ri();
              }
          }
          int [] ans = Arrays.copyOf(p[0], n);
          for(int i = 1; i < m; i++){
              for(int j = 0; j < n; j++){
                  ans[j] = max(ans[j], p[i][j]);
              }
          }
          if(m <= n - 1){
              addAns(min(ans));
              return ;
          }else{
              int res = 0;
              for(int i = 0; i < n; i++){
                  for(int j = i + 1; j < n; j++){
                      if(i == j){
                          continue;
                      }
                      int x = 0;
                      for(int k = 0; k < m; k++){
                          x = max(x, min(p[k][i], p[k][j]));
                      }
                      for(int k = 0; k < n; k++){
                          if(k == i || k == j){
                              continue;
                          }
                          x = min(ans[k], x);
                      }
                      res = max(x, res);
                  }
              }
              addAns(res);
          }
      }
  
      private void clear() {
  
      }
  
      private void run() throws Exception {
  
          int T = 1;
          if (multiCase) {
              rf();
              T = ri();
          }
  
          preparation();
          while (T-- > 0) {
              solve();
              if (T != 0) {
                  clear();
              }
          }
          printAns();
      }
  
      public static void main(String[] args) throws Exception {
          new Main().run();
      }
  
      StringBuilder sb = new StringBuilder();
      BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
      StringTokenizer strT;
  
      private void addAns(int a) {
          sb.append(a).append("\n");
      }
  
      private void addAns(long a) {
          sb.append(a).append("\n");
      }
  
      private void addAns(String s) {
          sb.append(s).append("\n");
      }
  
      private void rf() throws IOException {
          strT = new StringTokenizer(infile.readLine());
      }
  
      private int ri() {
          return Integer.parseInt(strT.nextToken());
      }
  
      private long rl() {
          return Long.parseLong(strT.nextToken());
      }
  
      private char[] rs2c() {
          return strT.nextToken().toCharArray();
      }
  
      private String rs() {
          return strT.nextToken();
      }
  
  
      private int[] readArr(int N) {
          int[] arr = new int[N];
          for (int i = 0; i < N; i++) {
              arr[i] = Integer.parseInt(strT.nextToken());
          }
          return arr;
      }
  
      private long[] readArr2(int N) {
          long[] arr = new long[N];
          for (int i = 0; i < N; i++) {
              arr[i] = Long.parseLong(strT.nextToken());
          }
          return arr;
      }
  
      public boolean PRINT_FUNCTION;
  
      private void print(String format, Object... args) {
          System.out.printf((format), args);
      }
  
      // for interactive problem. flush output after print. need with tail %n if print Line Separator
      private void iprint(String format, Object... args) {
          System.out.printf((format), args);
          System.out.flush();
      }
  
      private void print(int[] arr, int x) {
          //for debugging only
          for (int i = 0; i < min(arr.length, x); i++) {
              System.out.print(arr[i] + " ");
          }
          System.out.println();
      }
  
      private void print(long[] arr, int x) {
          //for debugging only
          for (int i = 0; i < min(arr.length, x); i++) {
              System.out.print(arr[i] + " ");
          }
          System.out.println();
      }
  
      private void printAns() {
          System.out.print(sb);
      }
  
      public boolean ADD_WITH_MOD_FUNCTION;
  
      public int add(int a, int b) {
          return (int) add((long) a, (long) b);
      }
  
      public int add(int a, int b, int c) {
          return (int) add((long) a, (long) b, (long) c);
      }
  
      public int add(int a, int b, int c, int d) {
          return (int) add((long) a, (long) b, (long) c, (long) d);
      }
  
      public long add(long a, long b) {
          return (a % M + b % M) % M;
      }
  
      public long add(long a, long b, long c) {
          return (a % M + add(b, c)) % M;
      }
  
      public long add(long a, long b, long c, long d) {
          return (a % M + add(b, c, d)) % M;
      }
  
      private long mod(long x) {
          return (x % M + M) % M;
      }
  
      private int mod(int x) {
          return (int) (((x % M) + M) % M);
      }
  
      public boolean ELEMENT_COUNT_TO_MAP_FUNCTION;
  
      private HashMap<Integer, Integer> hash(int[] A) {
          HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
          for (int i : A) {
              if (map.containsKey(i)) {
                  map.put(i, map.get(i) + 1);
              } else {
                  map.put(i, 1);
              }
          }
          return map;
      }
  
      private HashMap<Long, Integer> hash(long[] A) {
          HashMap<Long, Integer> map = new HashMap<Long, Integer>();
          for (long i : A) {
              if (map.containsKey(i)) {
                  map.put(i, map.get(i) + 1);
              } else {
                  map.put(i, 1);
              }
          }
          return map;
      }
  
      private TreeMap<Integer, Integer> tree(int[] A) {
          TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
          for (int i : A) {
              if (map.containsKey(i)) {
                  map.put(i, map.get(i) + 1);
              } else {
                  map.put(i, 1);
              }
          }
          return map;
      }
  
      private TreeMap<Long, Integer> tree(long[] A) {
          TreeMap<Long, Integer> map = new TreeMap<Long, Integer>();
          for (long i : A) {
              if (map.containsKey(i)) {
                  map.put(i, map.get(i) + 1);
              } else {
                  map.put(i, 1);
              }
          }
          return map;
      }
  
      public boolean SORT_FUNCTION;
  
      private void sort(int[] A) {
          int n = A.length;
          Random rnd = new Random();
          for (int i = 0; i < n; ++i) {
              int tmp = A[i];
              int randomPos = i + rnd.nextInt(n - i);
              A[i] = A[randomPos];
              A[randomPos] = tmp;
          }
          Arrays.sort(A);
      }
  
      private void sort(long[] A) {
          int n = A.length;
          Random rnd = new Random();
          for (int i = 0; i < n; ++i) {
              long tmp = A[i];
              int randomPos = i + rnd.nextInt(n - i);
              A[i] = A[randomPos];
              A[randomPos] = tmp;
          }
          Arrays.sort(A);
      }
  
      private String sort(String s) {
          Character[] ch = new Character[s.length()];
          for (int i = 0; i < s.length(); i++) {
              ch[i] = s.charAt(i);
          }
          Arrays.sort(ch);
          StringBuilder st = new StringBuilder();
          for (int i = 0; i < s.length(); i++) {
              st.append(ch[i]);
          }
          return st.toString();
      }
  
      public boolean REVERSE_FUNCTION;
  
      private String reverse(String s) {
          StringBuilder p = new StringBuilder(s);
          p.reverse();
          return p.toString();
      }
  
      private long sum(int[] A) {
          long sum = 0;
          for (int i : A) {
              sum += i;
          }
          return sum;
      }
  
      private long sum(long[] A) {
          long sum = 0;
          for (long i : A) {
              sum += i;
          }
          return sum;
      }
  
      private void reverse(long[] A) {
          int n = A.length;
          long[] B = new long[n];
          for (int i = 0; i < n; i++) {
              B[i] = A[n - i - 1];
          }
          System.arraycopy(B, 0, A, 0, n);
  
      }
  
      private void reverse(int[] A) {
          int n = A.length;
          int[] B = new int[n];
          for (int i = 0; i < n; i++) {
              B[i] = A[n - i - 1];
          }
          System.arraycopy(B, 0, A, 0, n);
  
      }
  
  
      private int nextPowerOf2(int n) {
          n--;
          n |= n >> 1;
          n |= n >> 2;
          n |= n >> 4;
          n |= n >> 8;
          n |= n >> 16;
          n++;
  
          return n;
      }
  
      private int highestPowerOf2(int x) {
  
          x |= x >> 1;
          x |= x >> 2;
          x |= x >> 4;
          x |= x >> 8;
          x |= x >> 16;
  
          return x ^ (x >> 1);
  
      }
  
      private long highestPowerOf2(long x) {
  
          x |= x >> 1;
          x |= x >> 2;
          x |= x >> 4;
          x |= x >> 8;
          x |= x >> 16;
          return x ^ (x >> 1);
  
      }
  
      public boolean ARRAY_MAX_MIN_FUNCTION;
  
      private int max(int[] A) {
          int max = Integer.MIN_VALUE;
          for (int j : A) {
              max = Math.max(max, j);
          }
          return max;
      }
  
      private int min(int[] A) {
          int min = Integer.MAX_VALUE;
          for (int j : A) {
              min = Math.min(min, j);
          }
          return min;
      }
  
      private long max(long[] A) {
          long max = Long.MIN_VALUE;
          for (long l : A) {
              max = Math.max(max, l);
          }
          return max;
      }
  
      private long min(long[] A) {
          long min = Long.MAX_VALUE;
          for (long l : A) {
              min = Math.min(min, l);
          }
          return min;
      }
  
      public boolean PREFIX_SUFFIX_FUNCTION;
  
      private long[] prefix(long[] A) {
          long[] p = new long[A.length];
          p[0] = A[0];
          for (int i = 1; i < A.length; i++)
              p[i] = p[i - 1] + A[i];
          return p;
      }
  
      private long[] prefix(int[] A) {
          long[] p = new long[A.length];
          p[0] = A[0];
          for (int i = 1; i < A.length; i++)
              p[i] = p[i - 1] + A[i];
          return p;
      }
  
      private long[] suffix(long[] A) {
          long[] p = new long[A.length];
          p[A.length - 1] = A[A.length - 1];
          for (int i = A.length - 2; i >= 0; i--)
              p[i] = p[i + 1] + A[i];
          return p;
      }
  
      private long[] suffix(int[] A) {
          long[] p = new long[A.length];
          p[A.length - 1] = A[A.length - 1];
          for (int i = A.length - 2; i >= 0; i--)
              p[i] = p[i + 1] + A[i];
          return p;
      }
  
      public boolean FILL_ARRAY_FUNCTION;
  
      private void fill(int[] dp, int v) {
          Arrays.fill(dp, v);
      }
  
      private void fill(int[][] dp, int v) {
          for (int[] ints : dp) {
              Arrays.fill(ints, v);
          }
      }
  
      private void fill(int[][][] dp, int v) {
          for (int i = 0; i < dp.length; i++) {
              for (int j = 0; j < dp[0].length; j++) {
                  Arrays.fill(dp[i][j], v);
              }
          }
      }
  
      private void fill(int[][][][] dp, int v) {
          for (int i = 0; i < dp.length; i++) {
              for (int j = 0; j < dp[0].length; j++) {
                  for (int k = 0; k < dp[0][0].length; k++) {
                      Arrays.fill(dp[i][j][k], v);
                  }
              }
          }
      }
  
      private void fill(long[] dp, long v) {
          Arrays.fill(dp, v);
      }
  
      private void fill(long[][] dp, long v) {
          for (long[] longs : dp) Arrays.fill(longs, v);
      }
  
      private void fill(long[][][] dp, long v) {
          for (long[][] ones : dp) {
              for (long[] two : ones) {
                  Arrays.fill(two, v);
              }
          }
      }
  
      private void fill(long[][][][] dp, long v) {
          for (int i = 0; i < dp.length; i++) {
              for (int j = 0; j < dp[0].length; j++) {
                  for (int k = 0; k < dp[0][0].length; k++) {
                      Arrays.fill(dp[i][j][k], v);
                  }
              }
          }
      }
  
      public boolean MAX_AND_MIN_FUNCTION;
      // max and min for 2 ~ 4 arguments, argument Type int long float double
  
      private int min(int a, int b) {
          return Math.min(a, b);
      }
  
      private long min(long a, long b) {
          return Math.min(a, b);
      }
  
      private float min(float a, float b) {
          return Math.min(a, b);
      }
  
      private double min(double a, double b) {
          return Math.min(a, b);
      }
  
  
      private int min(int a, int b, int c) {
          return Math.min(a, Math.min(b, c));
      }
  
      private float min(float a, float b, float c) {
          return Math.min(a, Math.min(b, c));
      }
  
      private double min(double a, double b, double c) {
          return Math.min(a, Math.min(b, c));
      }
  
      private long min(long a, long b, long c) {
          return Math.min(a, Math.min(b, c));
      }
  
      private int min(int a, int b, int c, int d) {
          return Math.min(Math.min(a, b), Math.min(c, d));
      }
  
      private long min(long a, long b, long c, long d) {
          return Math.min(Math.min(a, b), Math.min(c, d));
      }
  
      private float min(float a, float b, float c, float d) {
          return Math.min(Math.min(a, b), Math.min(c, d));
      }
  
      private double min(double a, double b, double c, double d) {
          return Math.min(Math.min(a, b), Math.min(c, d));
      }
  
      private int max(int a, int b) {
          return Math.max(a, b);
      }
  
      private long max(long a, long b) {
          return Math.max(a, b);
      }
  
      private float max(float a, float b) {
          return Math.max(a, b);
      }
  
      private double max(double a, double b) {
          return Math.max(a, b);
      }
  
      private int max(int a, int b, int c) {
          return Math.max(a, Math.max(b, c));
      }
  
      private float max(float a, float b, float c) {
          return Math.max(a, Math.max(b, c));
      }
  
      private double max(double a, double b, double c) {
          return Math.max(a, Math.max(b, c));
      }
  
      private long max(long a, long b, long c) {
          return Math.max(a, Math.max(b, c));
      }
  
      private int max(int a, int b, int c, int d) {
          return Math.max(Math.max(a, b), Math.max(c, d));
      }
  
      private long max(long a, long b, long c, long d) {
          return Math.max(Math.max(a, b), Math.max(c, d));
      }
  
      private float max(float a, float b, float c, float d) {
          return Math.max(Math.max(a, b), Math.max(c, d));
      }
  
      private double max(double a, double b, double c, double d) {
          return Math.max(Math.max(a, b), Math.max(c, d));
      }
  
  }
  