#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;
bool cmp(const pair<int, int>& p1, const pair<int, int>& p2) {
return p1.second < p2.second;
}
int main () {
int t;
scanf("%d", &t);
while (t--) {
map<int, int> m;
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
int ans;
scanf("%d", &ans);
m[ans]++;
}
int num, sum = 0;
map<int, int>::iterator it = max_element(m.begin(), m.end(), cmp);
printf("%d %d\n", it -> first, it -> second);
}
return 0;
}