복사하여 sort를 한 리스트를 set처리(중복제거)하여 해결했다.
for tc in range(1,int(input())+1):
t=int(input())
arr=list(map(int, input().split()))
chk=set(sorted(arr))
maxx=0
res=0
for i in chk:
if arr.count(i)>=maxx:
maxx=arr.count(i)
res=i
print(f'#{t} {res}')