#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
    
int max=0;int p;
    int n;int  temp;int test;
   scanf("%d",&test);
    scanf("%d",&n);
   int a[n];
   for(p=0;p<test;p++)
{
for(int i=0;i<n;i++)
{
 scanf("%d",&a[i]);
 }
for(int j=0;j<n;j++)
{
        int times=0;
for(int k=0;k<n;k++)
{        
        if(k!=j)
        {
          if(a[j]==a[k])
          {
                        times=times+1;
          }      
          if(times>max)
          {
                        max=times;
                        temp=a[j];
                        } 
             else if(times==max)
             {
                  
                  if(a[j]>temp)
                  {
continue;
}
                  else{
temp=a[j];
}
                  }     
        }           
              }
        }
        
printf("%d ",temp);
printf("%d ",max+1);
}
return 0;

}
