#include<stdio.h>
#include<string.h>
struct color
{
char color[15];
int num;
}balloon[1000];
int main()
{
int n,i,j,k,l,num,max;char new[15];
while(scanf("%d",&n)&&n!=0)
{
scanf("%s",balloon[0].color);
balloon[0].num=1;
num=1;
for(i=1;i<n;i++)
{
scanf("%s",new);
for(k=0;k<num;k++)
{
if(!strcmp(balloon[k].color,new))
{
balloon[k].num++;
break;
}
else if(k+1==num)
{
strcpy(balloon[k+1].color,new);
balloon[k+1].num=1;
num++;****num++了要再循环一次
break;***
}
}
}
max=0;
for(l=0;l<num;l++)
{
printf("%s %d\n",balloon[l].color,balloon[l].num);
if(balloon[l].num>balloon[max].num)
{
max=l;
}
}
printf("%s\n",balloon[max].color);
}
}