/*
TASK:sms
LANG:C++
*/
#include <iostream.h>
#include <string.h>

int main()
{
    char n[100][16],p[100][100][26],name[16],post[26];
    int num[100][100],e[100],m,i,j,g,b,numb;
    cin>>m;
    for(i=0,b=-1;i<m;i++)
    {
                    cin.getline(name,15);
                    cin>>numb;
                    cin.getline(post,25);
                    g=1;
                    for(j=0;j<i;j++)
                    {
                     if(!strcmp(name,n[j]))
                     {
                                           strcpy(p[j][e[j]],post);
                                           e[j]++;
                                           num[j][e[j]]=numb;
                                           break;g=0;
                     }}
                     if(g)
                     {
                          b++;
                          strcpy(p[b][0],post);
                          strcpy(n[b],name);
                          num[b][0]=numb;
                          e[b]=1;
                      }
    }
    for(i=0;i<=b;i++)
    {
                     for(g=0;n[i][g];g++)
                                         cout<<n[i][g];
                     cout<<"\n";
                     for(j=0;j<e[i];j++)
                     {
                                         for(g=0;p[i][j][g];g++)
                                                              cout<<n[i][g];
                                           cout<<"\n";
                     }
                     cout<<"\n";
    }
    return 0;
}
