#include <bits/stdc++.h>
#define ll long long
#define FOr(i, a, b) for (int i = a; i < b; i++)
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FOrd(i, a, b) for (int i = a; i > b; i--)
#define FORD(i, a, b) for (int i = a; i >= b; i--)
#define faster() \
ios_base ::sync_with_stdio(0); \
cin.tie(NULL); \
cout.tie(NULL);
using namespace std;
struct NhanVien
{
string ma;
string ten, gt, ns, dc, mst, hd;
};
int j = 1;
void nhap(NhanVien &a)
{
string tmp = to_string(j);
a.ma = string(5 - tmp.size(), '0') + tmp;
j++;
getline(cin >> ws, a.ten);
cin >> a.gt >> a.ns;
cin.ignore();
getline(cin >> ws, a.dc);
cin >> a.mst >> a.hd;
}
void inds(NhanVien ds[], int N)
{
FOr(i, 0, N)
{
cout << ds[i].ma << " " << ds[i].ten << " " << ds[i].gt << " " << ds[i].ns << " ";
cout << ds[i].dc << " " << ds[i].mst << " " << ds[i].hd << endl;
}
}
bool cmp(NhanVien &a, NhanVien &b)
{
int year1 = stoi(a.ns.substr(6, 4));
int year2 = stoi(b.ns.substr(6, 4));
if (year1 != year2)
{
return year1 < year2;
}
else
{
int month1 = stoi(a.ns.substr(3, 2));
int month2 = stoi(b.ns.substr(3, 2));
if (month1 != month2)
{
return month1 < month2;
}
else
{
int day1 = stoi(a.ns.substr(0, 2));
int day2 = stoi(b.ns.substr(0, 2));
return day1 < day2;
}
}
}
void sapxep(NhanVien ds[], int n)
{
sort(ds, ds + n, cmp);
}
int main()
{
struct NhanVien ds[50];
int N, i;
cin >> N;
for (i = 0; i < N; i++)
nhap(ds[i]);
sapxep(ds, N);
inds(ds, N);
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgRk9yKGksIGEsIGIpIGZvciAoaW50IGkgPSBhOyBpIDwgYjsgaSsrKQojZGVmaW5lIEZPUihpLCBhLCBiKSBmb3IgKGludCBpID0gYTsgaSA8PSBiOyBpKyspC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