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: from __future__ import division, print_function
  
  import os,sys
  from io import BytesIO, IOBase
  
  if sys.version_info[0] < 3:
      from __builtin__ import xrange as range
      from future_builtins import ascii, filter, hex, map, oct, zip
  
  from bisect import bisect_left as lower_bound, bisect_right as upper_bound 
  def so():  return int(input())
  def st():  return input()
  def mj():  return map(int,input().strip().split(" "))
  def msj(): return list(map(str,input().strip().split(" ")))
  def le():  return list(map(int,input().split()))
  def rc():  return map(float,input().split())
  def lebe():return list(map(int, input()))
  
  def dmain():
      sys.setrecursionlimit(1000000)
      threading.stack_size(1024000)
      thread = threading.Thread(target=main)
      thread.start()
  def joro(L):
      return(''.join(map(str, L)))
  
  
  def decimalToBinary(n): return bin(n).replace("0b","")
  
  
  def isprime(n):
      for i in range(2,int(n**0.5)+1):
          if n%i==0:
              return False
      return True
  def npr(n, r):
      return factorial(n) // factorial(n - r) if n >= r else 0
   
   
  def ncr(n, r):
      return factorial(n) // (factorial(r) * factorial(n - r)) if n >= r else 0
   
   
  def lower_bound(li, num):
      answer = -1
      start = 0
      end = len(li) - 1
   
      while (start <= end):
          middle = (end + start) // 2
          if li[middle] >= num:
              answer = middle
              end = middle - 1
          else:
              start = middle + 1
      return answer  # min index where x is not less than num
   
   
  def upper_bound(li, num):
      answer = -1
      start = 0
      end = len(li) - 1
   
      while (start <= end):
          middle = (end + start) // 2
   
          if li[middle] <= num:
              answer = middle
              start = middle + 1
   
          else:
              end = middle - 1
      return answer  # max index where x is not greater than num
  def tir(a,b,c):
      if(0==c):
          return 1
      if(len(a)<=b):
          return 0
      
      if(c!=-1):
          return (tir(a,1+b,c+a[b]) or tir(a,b+1,c-a[b]) or tir(a,1+b,c)) 
          
          
      else:
          return (tir(a,1+b,a[b]) or tir(a,b+1,-a[b]) or tir(a,1+b,-1))
  hoi=int(2**20)        
   
  def abs(x):
      return x if x >= 0 else -x
   
   
  def binary_search(li, val, lb, ub):
      # print(lb, ub, li)
      ans = -1
      while (lb <= ub):
          mid = (lb + ub) // 2
          # print('mid is',mid, li[mid])
          if li[mid] > val:
              ub = mid - 1
          elif val > li[mid]:
              lb = mid + 1
          else:
              ans = mid  # return index
              break
      return ans
   
   
  def kadane(x):  # maximum sum contiguous subarray
      sum_so_far = 0
      current_sum = 0
      for i in x:
          current_sum += i
          if current_sum < 0:
              current_sum = 0
          else:
              sum_so_far = max(sum_so_far, current_sum)
      return sum_so_far
  
                      
  def pref(li):
      pref_sum = [0]
      for i in li:
          pref_sum.append(pref_sum[-1] + i)
      return pref_sum
   
  
          
          
  def SieveOfEratosthenes(n):
      prime = [True for i in range(n + 1)]
      p = 2
      li = []
      while (p * p <= n):
          if (prime[p] == True):
              for i in range(p * p, n + 1, p):
                  prime[i] = False
          p += 1
   
      for p in range(2, len(prime)):
          if prime[p]:
              li.append(p)
      return li
   
   
  def primefactors(n):
      factors = []
      while (n % 2 == 0):
          factors.append(2)
          n //= 2
      for i in range(3, int(sqrt(n)) + 1, 2):  # only odd factors left
          while n % i == 0:
              factors.append(i)
              n //= i
      if n > 2:  # incase of prime
          factors.append(n)
      return factors
           
      
  def read():
      sys.stdin  = open('input.txt', 'r')  
      sys.stdout = open('output.txt', 'w') 
  def tr(n):
      return n*(n+1)//2
  boi=int(1e9-7)
  doi=int(1e9+7)
  
      
      
  def iu():
      import sys
      import math as my
      input=sys.stdin.readline
      y="Yes"
      n="No"
      t=st()
      a,b=mj()
      L=[0]*a
      d=[]
      for i in range(b):
          H=[]
          #for j in range(b):
              #H.append([])
          d.append(H)
      for i in range(a):
          M=le()
          for j in range(b):
              d[j].append(M[j])
          L[i]=sorted(M)[-1-1]
      bec=sys.maxsize
      for i in range(b):
          bec=min(max(d[i]),bec)
      beca=-sys.maxsize
      for i in range(a):
          beca=max(min(L[i],bec),beca)
      print(beca)
   
              
              
      
              
              
          
          
      
              
          
              
          
      
  def main():
      for i in range(so()):
          iu()
          
      
      
      
      
      
      
      
      
      
      
  
      
  
      
          
          
              
      
      
                  
              
                  
                  
                  
                  
              
      
              
              
      
      
      
      
          
              
      
             
              
              
          
      
          
      
      
          
          
          
  
              
                      
                  
                      
                      
                      
                      
                      
                      
          
                  
          
          
         
      
             
            
            
                  
              
          
                  
      
          
          
          
         
              
                  
          
  
  
  
  
  # region fastio
  # template taken from https://github.com/cheran-senthil/PyRival/blob/master/templates/template.py
  
  BUFSIZE = 8192
  
  
  class FastIO(IOBase):
      newlines = 0
  
      def __init__(self, file):
          self._fd = file.fileno()
          self.buffer = BytesIO()
          self.writable = "x" in file.mode or "r" not in file.mode
          self.write = self.buffer.write if self.writable else None
  
      def read(self):
          while True:
              b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
              if not b:
                  break
              ptr = self.buffer.tell()
              self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
          self.newlines = 0
          return self.buffer.read()
  
      def readline(self):
          while self.newlines == 0:
              b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
              self.newlines = b.count(b"\n") + (not b)
              ptr = self.buffer.tell()
              self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
          self.newlines -= 1
          return self.buffer.readline()
  
      def flush(self):
          if self.writable:
              os.write(self._fd, self.buffer.getvalue())
              self.buffer.truncate(0), self.buffer.seek(0)
  
  
  class IOWrapper(IOBase):
      def __init__(self, file):
          self.buffer = FastIO(file)
          self.flush = self.buffer.flush
          self.writable = self.buffer.writable
          self.write = lambda s: self.buffer.write(s.encode("ascii"))
          self.read = lambda: self.buffer.read().decode("ascii")
          self.readline = lambda: self.buffer.readline().decode("ascii")
  
  
  def print(*args, **kwargs):
      """Prints the values to a stream, or to sys.stdout by default."""
      sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
      at_start = True
      for x in args:
          if not at_start:
              file.write(sep)
          file.write(str(x))
          at_start = False
      file.write(kwargs.pop("end", "\n"))
      if kwargs.pop("flush", False):
          file.flush()
  
  
  if sys.version_info[0] < 3:
      sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
  else:
      sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
  
  input = lambda: sys.stdin.readline().rstrip("\r\n")
  
  # endregion
  
  
  if __name__ == "__main__":
      #read()
      main()
      #dmain()
  
  # Comment Read()