#include <iostream>
using namespace std;
#include <stdlib.h>
#include "String.h"

struct Date {
  int day;    // 1 .. 31
  int month;  // 1 .. 12
  int year;   // YYYY
};

struct Person {
  String name;
  String first;
  Date birth;
};

struct List {
  Person *data;
  List *next;
};

/* -- read on input record and return success/error -- */

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;

  /* -- read persons from stdin -- */
  while ( getrecord(nbuf, fbuf, y, m, d) ) {
    /* -- construct new person record -- */
    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;

    /* -- add to list (and sort them already at insertion time) -- */
    if ( first == 0 ) {
      /* -- first record -- */
      first = add;
    } else {
      /* -- there are already records -- */
      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;
      }

      /* -- insert at right place -- */
      add->next = curr;
      if ( last) {
        last->next = add;
      } else {
        first = add;
      }
    }
  }

  /* -- print out sorted list and delete list -- */
  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;
}