#include <stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
int n = 0, count = 1;
char country[2005][75];
char name[2005][75];
char temp[75] = { '\0' };
while (scanf("%d", &n) != EOF)
{
for (int i = 0; i < n; i++)
{
scanf("%s", country[i]);
gets(name[i]); //把後面get掉
}
for (int i = 0; i < n-1; i++)
{
for (int j = i+1; j < n; j++)
{
if (strcmp(country[i], country[j]) > 0)
{
strcpy(temp, country[j]);
strcpy(country[j],country[i]);
strcpy(country[i],temp);
}
}
}
printf("%s", country[0]);
for (int i = 1; i < n; i++)
{
if (strcmp(country[i],country[i-1])==0)
{
count++;
}
else {
printf(" %d\n", count);
count = 1;
printf("%s", country[i]);
}
}printf(" %d", count);
count = 1;
}
return 0;
}