#include <iostream>
using namespace std;
#include <stdlib.h>
#include <string.h>
const int NAMLEN=80;
struct Date {
int day;
int month;
int year;
};
struct Person {
char name[NAMLEN];
char first[NAMLEN];
Date birth;
};
struct List {
Person *data;
List *next;
};
bool getrecord(char *nbuf, char *fbuf, int& y, int& m, int& d)
{
char sep;
return (cin >> nbuf >> fbuf >> y >> sep >> m >> sep >> d);
}
int main() {
char nbuf[NAMLEN];
char fbuf[NAMLEN];
int y, m, d;
List* first = 0;
List* curr = 0;
List* last = 0;
Person* p;
while ( getrecord(nbuf, fbuf, y, m, d) ) {
List* add = new List;
add->data = p = new Person;
add->next = 0;
strcpy(p->name, nbuf);
strcpy(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 ) {
Person *old = curr->data;
if ((strcmp(p->name, old->name) < 0) ||
((strcmp(p->name, old->name) == 0) &&
(strcmp(p->first, old->first) <= 0))) {
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;
}