#include <iostream>
using namespace std;
struct student {
char name[21];
char surname[21];
char letter;
int Class;
char date[9];
};
bool operator > (const student & a,
const student & b) {
bool res = false;
bool tmp = true;
if (a.Class > b.Class) res = true;
else if (a.Class == b.Class) {
if (a.letter > b.letter) res = true;
else if (a.letter == b.letter) {
for (int i = 0; i < 21; i++) {
if (a.surname[i] < b.surname[i]) {
tmp = false;
break;
} else if (a.surname[i] > b.surname[i]) {
tmp = true;
break;
}
}
if (tmp) res = true;
}
}
return res;
};
int main() {
int n;
cin >> n;
student *a = new student[n];
for (int i = 0; i < n; i++) {
cin >> a[i].surname >> a[i].name >> a[i].Class >> a[i].letter >> a[i].date;
}
for (int k = 2; k <= n; k++) {
for (int i = 0; i <= n - k; i++) {
if (a[i] > a[i + 1]) {
swap(a[i], a[i + 1]);
}
}
}
for (int i = 0; i < n; i++) {
cout << a[i].Class << a[i].letter << " " << a[i].surname << " " << a[i].name << " " << a[i].date << endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwogCnN0cnVjdCBzdHVkZW50IHsKICBjaGFyIG5hbWVbMjFdOwogIGNoYXIgc3VybmFtZVsyMV07CiAgY2hhciBsZXR0ZXI7CiAgaW50IENsYXNzOwogIGNoYXIgZGF0ZVs5XTsKfTsKIApib29sIG9wZXJhdG9yID4gKGNvbnN0IHN0dWRlbnQgJiBhLAogIGNvbnN0IHN0dWRlbnQgJiBiKSB7CiAgYm9vbCByZXMgPSBmYWxzZTsKICBib29sIHRtcCA9IHRydWU7CiAgaWYgKGEuQ2xhc3MgPiBiLkNsYXNzKSByZXMgPSB0cnVlOwogIGVsc2UgaWYgKGEuQ2xhc3MgPT0gYi5DbGFzcykgewogICAgaWYgKGEubGV0dGVyID4gYi5sZXR0ZXIpIHJlcyA9IHRydWU7CiAgICBlbHNlIGlmIChhLmxldHRlciA9PSBiLmxldHRlcikgewogICAgICBmb3IgKGludCBpID0gMDsgaSA8IDIxOyBpKysp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