#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cctype>
using namespace std;
int main(){
int n;
string in;
int array[26] = {};
priority_queue<pair<int,int> > pq;
cin >> n;
getline(cin, in);
for(int i = 0; i < n; i++){
getline(cin, in);
transform(in.begin(), in.end(), in.begin(), ::toupper);
// cout << in << endl;
for(int j = 0; j < in.length(); j++){
if(in[j] >= 'A' && in[j] <= 'Z'){
int c = (int)in[j];
array[c - 65]++;
}
}
}
for(int i = 0; i < 26; i++){
if(array[i] > 0){
pq.push(make_pair(array[i], -(i + 'A')));
}
}
while(!pq.empty()){
char letter = (char)-pq.top().second;
int freq = pq.top().first;
cout << letter << " " << freq << endl;
pq.pop();
}
return 0;
}