T = int(input())
for i in range(T):
n = int(input())
scores = list(map(int, input().split()))
max = 0
for score in range(101):
if scores.count(score) == 0:
continue
elif scores.count(score) > scores.count(max):
max = score
elif scores.count(score) == scores.count(max):
if score>max:
max = score
print(f"#{n} {max}")