#include <stdio.h>
#define MAXNAM 100
#define MAXLOC 100
#define MAXCHR 40
struct index
  {
   char name [MAXCHR];
   int line [MAXLOC];
  };

main()
{
 void alphsort();
 char *ptstr [MAXNAM];
 char tempname;
 int templine, counter, nument, state, tempcount, lineent, count;
 int temp, cnt, ct;
 struct index entry[MAXNAM];


 counter = 0;
 nument = 0;
 lineent = 0;
 templine = 0;
 temp = 0;
 tempcount = 0;
 state = 0;

 while (nument <= MAXNAM)
 {
  scanf ("%s", &tempname);
  scanf ("%d", &templine);
  while (counter <= nument)
  {
   if (strcmp (tempname, entry[counter].name) == 0)
     {
      state = 1;
      tempcount = counter;
     }
  }
 switch (state)
 {
  case 0:
	  strcpy (entry[nument].name, tempname);
	  entry[nument].line[lineent] = templine;
	  ptstr[nument] = entry[nument].name;
	  nument = nument + 1;
	  lineent = lineent + 1;
  case 1:
	  entry[tempcount].line[lineent] = templine;
	  for (count = lineent - 1; count >= 0; count--)
	    {
	     if (entry[tempcount].line[lineent] < entry[tempcount].line[count])
	       {
		temp = entry[tempcount].line[count];
		entry[tempcount].line[count] = entry[tempcount].line[lineent];
		entry[tempcount].line[lineent] = temp;
	       }
	    }
	  lineent = lineent + 1;
 }
alphsort (ptstr, nument);
for (cnt = 0; cnt <= nument; cnt++)
  {printf ("%s", entry[cnt].name);
   for (ct = 0; ct <= lineent; ct++)
     {
      if (ct == lineent)
	printf (" %d\n", entry[cnt].line[ct]);
      else printf (" %d,", entry[cnt].line[ct]);
     }
  }
}
}

void alphsort(string, num)
char *string[];
int num;
{
 char *tem;
 int top, seek;

 for (top = 0; top < num - 1; top++)
   for (seek = top + 1; seek < num; seek++)
     if (strcmp (string[top], string[seek]) > 0)
       {
	tem = string[top];
	string[top] = string[seek];
	string[seek] = tem;
       }
}

