#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
class SinhVien {
private:
string id, name, id_class, mail;
public:
SinhVien() {}
string getId() { return id; }
string getIdClass() { return id_class; }
friend istream& operator>>(istream& in, SinhVien& sv);
friend ostream& operator<<(ostream& out, SinhVien sv);
};
bool cmp(SinhVien a, SinhVien b) {
if (a.getIdClass() == b.getIdClass()) {
return a.getId() < b.getId();
}
return a.getIdClass() < b.getIdClass();
}
istream& operator>>(istream& in, SinhVien& sv) {
getline(in, sv.id);
getline(in, sv.name);
getline(in, sv.id_class);
getline(in, sv.mail);
return in;
}
ostream& operator<<(ostream& out, SinhVien sv) {
out << sv.id << " " << sv.name << " " << sv.id_class << " " << sv.mail;
return out;
}
int main() {
cin.tie(NULL);
cout.tie(NULL);
ios_base::sync_with_stdio(false);
int N;
cin >> N;
cin.ignore();
SinhVien ds[N];
for (int i = 0; i < N; i++) {
cin >> ds[i];
}
sort(ds, ds + N, cmp);
for (int i = 0; i < N; i++) {
cout << ds[i] << endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnR5cGVkZWYgbG9uZyBsb25nIGxsOwoKY2xhc3MgU2luaFZpZW4gewpwcml2YXRlOgogICAgc3RyaW5nIGlkLCBuYW1lLCBpZF9jbGFzcywgbWFpbDsKCnB1YmxpYzoKICAgIFNpbmhWaWVuKCkge30KICAgIHN0cmluZyBnZXRJZCgpIHsgcmV0dXJuIGlkOyB9CiAgICBzdHJpbmcgZ2V0SWRDbGFzcygpIHsgcmV0dXJuIGlkX2NsYXNzOyB9CiAgICBmcmllbmQgaXN0cmVhbSYgb3BlcmF0b3I+Pihpc3RyZWFtJiBpbiwgU2luaFZpZW4mIHN2KTsKICAgIGZyaWVuZCBvc3RyZWFtJiBvcGVyYXRvcjw8KG9zdHJlYW0mIG91dCwgU2luaFZpZW4gc3YpOwp9OwoKYm9vbCBjbXAoU2luaFZpZW4gYSwgU2luaFZpZW4g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