#include <bits/stdc++.h>
using namespace std;
int n;
map<string, int> ch;
int main() {
ios_base::sync_with_stdio(false);
freopen("input.txt", "rt", stdin);
cin >> n;
for(int i=1; i<=n; i++) {
string temp;
cin >> temp;
ch[temp]++;
}
for(auto it : ch) {
cout << it.first << " " << it.second << "\n";
}
return 0;
}
ex)
7
book
dog
cat
dog
cat
book
cat