#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
map <string, int> mp;
string temp;
while (n--) {
string contry;
cin >> contry >> temp >> temp;
mp[contry]++;
}
for (auto i : mp)
cout << i.first << ' ' << i.second << endl;
return 0;
}