#include <iostream>
#include <string>
#include <map>
using namespace std;
int main() {
map<string, int> Country_and_population;
int times = 0;
cin >> times;
while (times--) {
string country, name = "";
cin >> country;
getline(cin,name);
Country_and_population[country]++;
}
for (map<string, int>::iterator i = Country_and_population.begin(); i != Country_and_population.end(); i++) {
cout << i->first << " " << i->second << endl;
}
return 0;
}