#include <iostream>
#include <string>
using namespace std;
struct student {
string name, surname;
char letter;
int Class;
string date;
};
bool operator > (const student &a, const student &b) {
bool res = false;
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) {
if (a.surname > b.surname) 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;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RydWN0IHN0dWRlbnQgewoJc3RyaW5nIG5hbWUsIHN1cm5hbWU7CgljaGFyIGxldHRlcjsKCWludCBDbGFzczsKCXN0cmluZyBkYXRlOwp9OwoKYm9vbCBvcGVyYXRvciA+IChjb25zdCBzdHVkZW50ICZhLCBjb25zdCBzdHVkZW50ICZiKSB7Cglib29sIHJlcyA9IGZhbHNlOwoJaWYgKGEuQ2xhc3MgPiBiLkNsYXNzKSByZXMgPSB0cnVlOwoJZWxzZSBpZiAoYS5DbGFzcyA9PSBiLkNsYXNzKSB7CgkJaWYgKGEubGV0dGVyID4gYi5sZXR0ZXIpIHJlcyA9IHRydWU7CgkJZWxzZSBpZiAoYS5sZXR0ZXIgPT0gYi5sZXR0ZXIpIHsKCQkJaWYgKGEuc3VybmFtZSA+IGIuc3VybmFtZSkgcmVzID0gdHJ1ZTsKCQl9Cgl9CglyZXR1cm4gcmVzOwp9OwoKaW50IG1haW4oKSB7CglpbnQgbjsKCWNpbiA+PiBuOwoJc3R1ZGVudCAqYSA9IG5ldyBzdHVkZ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