#include<iostream>
#include<unordered_map>
using namespace std;
unordered_map<string ,int> mp;
int main()
{
int m,n;
cin>>m;
while(m--)
{
string s;
cin>>s;
mp[s]++;
}
for(auto[k,v]:mp)
{
cout<<k<<" "<<v<<endl;
}
return 0;
}