import java.util.*;
import java.io.*;
class Solution
{
public static void main(String args[]) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T;
T=Integer.parseInt(br.readLine());
StringBuilder sb = new StringBuilder();
for(int test_case = 1; test_case <= T; test_case++)
{
int test = Integer.parseInt(br.readLine());
int[] scores = new int[101];
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
for (int i = 0; i < 1000; i++) {
scores[Integer.parseInt(st.nextToken())]++;
}
int max = 0;
for (int i = 1; i < scores.length; i++) {
if(scores[max] <= scores[i]) {
max = i;
}
}
sb.append("#").append(test).append(" ").append(max).append("\n");
System.out.println(sb.toString());
sb.setLength(0);
}
}
}