#include <bits/stdc++.h>
using namespace std;
int main(){
int test;
cin >> test;
cin.ignore();
string sentence;
int *arr = new int[26];
for(int i=0; i<26; i++){
arr[i] = 0;
}
for(int i=0; i<test; i++){
while(cin >> sentence){
for(char ch : sentence){
int a=-1;
if(ch >= 'a' && ch <= 'z'){
a = ch - 'a';
arr[a] += 1;
}
else if(ch >= 'A' && ch <= 'Z'){
a = ch - 'A';
arr[a] += 1;
}
}
}
}
int feq[26] = {0};
for(int i=0; i<26; i++){
feq[i] = i;
}
for(int i=0; i<25; i++){
for(int j=0; j<25-1-i; j++){
if(arr[j] < arr[j+1]){
swap(feq[j], feq[j+1]);
swap(arr[j], arr[j+1]);
}
}
}
for(int i=0; i<26; i++){
if(arr[i] != 0){
cout << (char)(feq[i]+'A') << " " << arr[i] << endl;
}
}
delete[] arr;
}