/*
TASK:sms
LANG:C++
*/
#include<iostream>
#include<string.h>
using namespace std;
class part
{
      public:
      int from;
      int part;
      char text[100];
      
};
char who[10000][100];
int n,q,br=0;
char from[100],text[100];
int check()
{
    for(int i=0;i<br;i++)
    if(strcmp(who[i],from)==0)
    return i;
    strcpy(who[br++],from);
    return br-1;
}
int cmp(part a,part b)
{
if(a.from==b.from) return a.part<b.part;
else
if(a.from<b.from) return 1;
else return 0;
}
int main()
{
    part parts[120];
    cin>>n;
    cin.get();
    for(int i=0;i<n;i++)
    {
    cin.getline(from,100);
    cin>>q;
    cin.get();
    cin.getline(text,100);
    int w=check();
    parts[i].from=w;
    parts[i].part=q;
    strcpy(parts[i].text,text);
    }
    sort(parts,parts+n,cmp);
    char now[20]={"Metallica RLZ"};
    for(int i=0;i<n;i++)
    {
    if(strcmp(now,who[parts[i].from])) {if(strcmp(now,"Metallica RLZ")!=0)  cout<<endl;  strcpy(now,who[parts[i].from]) ;cout<<now<<endl;}
    cout<<parts[i].text<<endl;
    }
    
   system("pause");
    return 0;
}
/*
7
Luv4o
2
da byde6 vse taka
Zajo Bajo
1
4estit rojden Den, Puh !!
Luv4o
4
jivotnite ot na6ata gora
Luv4o
3
dobri4ak kam vsi4ki
Zajo Bajo
3
den, za da te pozdravia
Luv4o
1
4RD, Puh!!! Pojelavam ti
Zajo Bajo
2
Ciala godina 4akam tozi
*/
