n=int(input());d={}for _ in range(n): s=input().split() if s[0] not in d: d[s[0]]=1 else: d[s[0]]+=1for i in sorted(d): print(f"{i} {d[i]}")