import sys
# 處理輸入
times = int(input())
all_text = ""
for i in range(times):
text = sys.stdin.readline().strip()
all_text += text
clean_text = "".join(x for x in all_text if x.isalpha()).upper()
# 用字典計數
dic = {}
for j in clean_text:
if j not in dic:
dic[j] = 1
else:
dic[j] += 1
# 排序 次數由大到小 相同次數者則以字母順序排序
dic = dict(sorted(dic.items(), key=lambda x : (-x[1], x[0])))
for key, value in dic.items():
print(f"{key} {value}")