#include<bits/stdc++.h>
using namespace std;
int main () {
int k;
cin>>k;
for(int j=0;j<k;j++){
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
int maxCount=0;
int number;
int index=0;
for(int i=0;i<n;i++){
int count=0;
for(int l=0;l<n;l++){
if(a[i]==a[l]){
count++;
if(count>maxCount){
maxCount=count;
index=i;
}
if(count==maxCount){
(a[i]>a[index])?number=a[index]:number=a[i];
}
}
}
}
cout<<number<<" "<<maxCount<<endl;
}
}