#include <iostream>
using namespace std;
#include <stdlib.h>
#include "String.h"
struct Date {
int day;
int month;
int year;
};
struct Person {
String name;
String first;
Date birth;
};
struct List {
Person *data;
List *next;
};
bool getrecord(String& nbuf, String& fbuf, int& y, int& m, int& d)
{
char sep;
return (cin >> nbuf >> fbuf >> y >> sep >> m >> sep >> d);
}
int main() {
String nbuf;
String fbuf;
int y, m, d;
List* first = 0;
List* curr = 0;
List* last = 0;
List* add = 0;
Person* p, *old;
while ( getrecord(nbuf, fbuf, y, m, d) ) {
add = new List;
add->data = p = new Person;
add->next = 0;
p->name = nbuf;
p->first = fbuf;
p->birth.year = y;
p->birth.month = m;
p->birth.day = d;
if ( first == 0 ) {
first = add;
} else {
curr = first;
last = 0;
while ( curr ) {
old = curr->data;
if ((p->name < old->name) ||
((p->name == old->name) && (p->first <= old->first))) {
break;
}
last = curr;
curr = curr->next;
}
add->next = curr;
if ( last) {
last->next = add;
} else {
first = add;
}
}
}
curr = first;
while ( curr ) {
p = curr->data;
cout << p->name << ' ' << p->first << ' ' <<
p->birth.year << '.' << p->birth.month << '.' <<
p->birth.day << endl;
last = curr;
curr = curr->next;
delete p;
delete last;
}
return 0;
}