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.lang.reflect.Array;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.Collection;
  import java.util.Collections;
  import java.util.Deque;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.LinkedList;
  import java.util.PriorityQueue;
  import java.util.Scanner;
  import java.util.Set;
  
  import javax.print.DocFlavor.STRING;
  import javax.swing.plaf.synth.SynthStyleFactory;
  
  public class Simple{  
  
      public static Deque<Integer> possible(int a[],int n){
          boolean bool = true;
          Deque<Integer> deq = new LinkedList<>();
          int i=0;
          int j=n-1;
          int max = n;
          int min = 1;
          while(i<=j){
              
              
              if(a[i]== min){
                  deq.addFirst(a[i]);
                  i++;min++;
                  continue;
              }
              if(a[j]== min){
                  deq.addLast(a[j]);
                  j--;
                  min++;
                  continue;
              }
              if(a[i]==max){
                  deq.addFirst(a[i]);
                  i++;
                  max--;
                  continue;
              }
              if(a[j]==max){
                  deq.addLast(a[j]);
                  j--;
                  max--;
                  continue;
              }
              Deque<Integer> d = new LinkedList<>();
              d.add(-1);
              return d;
  
          }
  
          
          return deq;
  
      }
  
      public static class Pair implements Comparable<Pair>{
          int val;
          int freq = 0;
  
          public Pair(int val,int freq){
              this.val = val;
              this.freq= freq;
          }
  
          public int compareTo(Pair p){
              if(p.freq == this.freq)return 0;
              if(this.freq > p.freq)return -1;
              return 1;
          }
  
  
      }
      public static long factorial(long n)
      {
      
        // single line to find factorial
        return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
      
      }
  
  
      static long m  = 998244353;
   
  // Function to return the GCD of given numbers
   static long gcd(long a, long b)
  {
      if (a == 0)
          return b;
      return gcd(b % a, a);
  }
   
  // Recursive function to return (x ^ n) % m
  static long modexp(long x, long n)
  {
      if (n == 0) {
          return 1;
      }
      else if (n % 2 == 0) {
          return modexp((x * x) % m, n / 2);
      }
      else {
          return (x * modexp((x * x) % m, (n - 1) / 2) % m);
      }
  }
   
  // Function to return the fraction modulo mod
   static long getFractionModulo(long a, long b)
  {
      long c = gcd(a, b);
   
      a = a / c;
      b = b / c;
   
      // (b ^ m-2) % m
      long  d = modexp(b, m - 2);
   
      // Final answer
      long ans = ((a % m) * (d % m)) % m;
   
      return ans;
  }
      // public static long bs(long lo,long hi,long fact,long num){
      //     long help = num/fact;
      //     long ans = hi;
      //     while(lo<=hi){
      //         long mid = (lo+hi)/2;
  
      //         if(mid/)
      //     }
      // }
      public static boolean isPrime(int n)
      {
   
          // Check if number is less than
          // equal to 1
          if (n <= 1)
              return false;
   
          // Check if number is 2
          else if (n == 2)
              return true;
   
          // Check if n is a multiple of 2
          else if (n % 2 == 0)
              return false;
   
          // If not, then just check the odds
          for (int i = 3; i <= Math.sqrt(n); i += 2)
          {
              if (n % i == 0)
                  return false;
          }
          return true;
      }
      public static int countDigit(long n)
      {
          int count = 0;
          while (n != 0) {
              n = n / 10;
              ++count;
          }
          return count;
      }
      static ArrayList<Long> al ;
      public static void main(String args[]){  
          //System.out.println("Hello Java");
          Scanner s = new Scanner(System.in);
          int t = s.nextInt();
          // if(al==null){
          //     Set<Long> set = new HashSet<>();
          //     for(long i=1;i<=100000;i++){
          //         if(i*i > 1000000000){
          //             break;
          //         }
          //         set.add(i*i);
          //     }
          //     for(long i=1;i<=100000;i++){
          //         if(i*i*i > 1000000000){
          //             break;
          //         }
          //         set.add(i*i*i);
          //     }
          //     al = new ArrayList<>();
          //     for(long x : set){
          //         al.add(x);
          //         Collections.sort(al);
          //     }
          //}
          
          //System.out.println(al.size());
          for(int t1 = 1;t1<=t;t1++){
              
              
          //     long a11 = s.nextLong();
          //     long b11 = s.nextLong();
  
          //     String a = String.valueOf(a11);
          //     String b = String.valueOf(b11);
  
          //    // String ans = a - b;
  
          //     if(a.length()>b.length()){
          //         System.out.println(-1);
          //         continue;
          //     }
          //     // while(a.length()!=b.length()){
          //     //     a='0'+a;
          //     // }
  
          //     int i= a.length()-1;
          //     int j = b.length()-1;
  
          //     String ans = "";
          //     while(i>0 && j>0){
          //         if(a.charAt(i) > b.charAt(j)){
          //             if(j==0){
          //                 break;
          //             }
          //             String o = ""+b.charAt(j-1)+b.charAt(j);
          //             int a1 = Integer.valueOf(o);
          //             int a2 = a.charAt(i)-'a';
          //             char c = (char)(a1 - a2 + 'a');
          //             ans= ans + c;
          //             j=j-2;
          //             i--;
          //         }
          //         else{
          //             int a1 = (char)(b.charAt(j) - a.charAt(i)+ 'a');
          //             // int a2 = Integer.valueOf(a.charAt(i));
          //             // String ui = String.valueOf(a2 - a1);
          //             ans=ans + a1;
          //             j--;
          //             i--;
          //         }
          //     }
          //     // if(i!=0 || j!=0){
          //         if(false){
          //         System.out.println(-1);
          //     }
          //     else{
          //         System.out.println(ans);
          //     }
              int m,n;
              m = s.nextInt();
              n=s.nextInt();
              ArrayList<PriorityQueue<Integer>> pq = new ArrayList<>();
              for(int i=0;i<m;i++){
                  pq.add(new PriorityQueue<>(Collections.reverseOrder()));
              }
              int dp[][]= new int[m][n];
              for(int i=0;i<m;i++){
                  for(int j=0;j<n;j++){
                      dp[i][j] = s.nextInt();
                      pq.get(i).add(dp[i][j]);
                  }
              }
              int minj=Integer.MAX_VALUE;
              HashSet<Integer> set = new HashSet();
              for(int j=0;j<n;j++){
                  int min = Integer.MIN_VALUE;
                  int shopNo = 0;
                  for(int i=0;i<m;i++){
                      if(dp[i][j] > min){
                          shopNo = i;
                          min = Math.max(dp[i][j], min);
                      }
                      
                  }
                  set.add(shopNo);
                  minj = Math.min(min,minj);
              }
              int somethingmin = Integer.MIN_VALUE;
              for(int i=0;i<m;i++){
                  pq.get(i).poll();
                  int x = pq.get(i).poll();
                  somethingmin = Math.max(x, somethingmin);
              }
              if(set.size() < n || somethingmin>=minj){
                  System.out.println(minj);
              }
              else{
                  System.out.println(somethingmin);
              }
  
              
          }
              
      }
      //5
      // 2 4 6 8 10  
      
  
      
  
      
      
  }  
  
  /*abstractSys
  
  1 3 5 7 9
  1 2 3 4 5
  5 6 7 8 9
  
  
  
  
   
  
  
  
  
  
  */