#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <vector>
#include <climits>
#include <string>
#include <algorithm>
#include <sstream>
#include <numeric>
using namespace std;

vector<string> split(string haystack, string needle) {
    vector<string> result;
    int startPos = 0;
    int foundPos = haystack.find(needle, startPos);
    while (foundPos != string::npos) {
        int count = foundPos - startPos;
        string token = haystack.substr(startPos, count);
        if (!token.empty()) {
            result.push_back(token);
        }
        startPos = foundPos + needle.length();
        foundPos = haystack.find(needle, startPos);
    }
    string token = haystack.substr(startPos, haystack.length() - startPos);
    if (!token.empty()) {
        result.push_back(token);
    }
    return result;
}

string nameConvert(const string& name) {
    const string DELIMITER = " ";
    stringstream builder;
    auto parts = split(name, DELIMITER);
    for (auto part : parts) {
        part[0] = toupper(part[0]);
        transform(part.begin() + 1, part.end(), part.begin() + 1, ::tolower);
        builder << part << DELIMITER;
    }
    return builder.str();
}

string dateConvert(const string& date) {
    const string DELIMITER = "/";
    stringstream builder;
    auto parts = split(date, DELIMITER);
    builder << setw(2) << setfill('0') << parts[0] << DELIMITER;
    builder << setw(2) << setfill('0') << parts[1] << DELIMITER;
    builder << parts[2];
    return builder.str();
}

class StudentIDGenerator {
private:
    inline static string const PREFIX = "SV";
    inline static int const MAX = 3;
    inline static int index = 1;

public:
    static string generate() {
        stringstream builder;
        builder << PREFIX << setw(MAX) << setfill('0') << index;
        index++;
        return builder.str();
    }
};

class Student {
private:
    string id, name, className, email;
public:

    Student() : id(""), name(""), className(""), email("") {};

    Student(string id, string name, string className, string email) :
        id(id), name(name), className(className), email(email) {
    };
public:
    void setName(string name) {
        this->name = name;
    }
    void setClass(string className) {
        this->className = className;
    }
    void setEmail(string email) {
        this->email = email;
    }
    void setID(string id) {
        this->id = id;
    }
public:
    string toString() {
        stringstream builder;
        builder << id << " " << name << " " << className << " " << email << endl;
        return builder.str();
    }

public:
    bool operator <(const Student& other) {
        if (this->className != other.className) {
            return this->className < other.className;
        }
        return this->id < other.id;
    }
};

class StudentFromKeyboardProvider {
public:
    static Student next() {
        string buffer;

        Student student;

        getline(cin, buffer);
        student.setID(buffer);

        getline(cin, buffer);
        student.setName(buffer);

        getline(cin, buffer);
        student.setClass(buffer);

        getline(cin, buffer);
        student.setEmail(buffer);

        return student;
    }
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n;cin >> n;
    cin.ignore();
    vector<Student> students;
    for (int i = 0;i < n;i++) {
        Student student = StudentFromKeyboardProvider::next();
        students.push_back(student);
    }

    sort(students.begin(), students.end());

    for (auto student : students) {
        cout << student.toString();
    }
    return 0;
}

