n=int(input())
dict={}
for i in range(n):
s=input().strip()
for w in s:
if w.isalpha():
w = w.upper()
if w in dict:
dict[w]+=1
else:
dict[w]=1
f=sorted(dict,key=lambda x:(-dict[x],x))
for i in f:
print(f"{i} {dict[i]}")