#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
struct birth {
int y, m, d;
};
struct stu {
int num;
string name;
birth birth1;
};
bool compare(const stu &a, const stu &b) {
if (a.birth1.y != b.birth1.y) {
return a.birth1.y < b.birth1.y;
} else if (a.birth1.m != b.birth1.m) {
return a.birth1.m < b.birth1.m;
} else {
return a.birth1.d < b.birth1.d;
}
}
int main() {
int n;
cin >> n;
vector<stu> stus(n);
for (int i = 0; i < n; i++) {
cin >> stus[ i].num >> stus[ i].name >> stus[ i].birth1.y >> stus[ i].birth1.m >> stus[ i].birth1.d;
}
sort(stus.begin(), stus.end(), compare);
for (int i = 0; i < n; i++) {
cout << stus[ i].num << " " << stus[ i].name << " " << stus[ i].birth1.y << "." << stus[ i].birth1.m << "." << stus[ i].birth1.d << endl;
}
return 0;
}