#include<bits/stdc++.h>
/*
計算全部字串裡個個字母出現的多寡
*/
/*
輸出流會有白癡問題 要在讀取完字串後接 cout.flush(); (好像可以不用) ,腦逼邊義氣真的有腦幹問題
要處理第一個數字輸入後會有空白緊接在後 用 cin.peak()來看是否可開始讀取字串 或是要繼續ignore
*/
using namespace std;
int main(){
int line, len=0;
cin >> line;
int count[26]={0};
cin.ignore();
// peak 偷窺
while (cin.peek() == ' ' || cin.peek() == '\n') { // 糙你嗎,不用這個就不會過
//cin.get();
cin.ignore();
}
while(line>0){
char str[10000];
cin.getline(str, 1000, '\n');
for(int i=0;str[i]!='\0'; i++){
if( isalpha(str[i]) ){
str[i] = toupper(str[i]);
count[ str[i]-'A' ]++;
}
}
line--;
//cout.flush(); 可有可無
}
//可有可無
int max_fre = 0;
for(int i=0;i<26;i++){
if(count[i]>max_fre) max_fre=count[i];
}//cout << max_fre<<endl;
for(int i=max_fre;i>=1;i--){
for(int k=0;k<26;k++){
if(count[k] == i){
cout << (char)(k+'A') << " "<<count[k]<<endl;
}
}
}
return 0;
}