wrong answer in maxcount problem

t=(int)(raw_input())
for i in range(t):
n=(int)(raw_input())
a=map(int,raw_input().split())
a.sort()
dic={}
i=0
for i in range(n):
p=a[i]
dic[p]=0
for i in range(n):
p=a[i]
dic[p]=dic[p]+1
max=1
r=a[0]
for key in dic:
if dic[key]>max:
max=dic[key]
r=key
print r,’ ',max

Here is my solution and I am getting a wrong answer though on my system it works perfectly well…please help!