#include<iostream>
#include<string.h>

using namespace std;

typedef struct student {
    string name;
    int age;
    int score;
} student;

int main() {
    //输入
    int n;
    cin >> n;
    student* s = new student[n];
    for (int i = 0; i < n; i++)
        cin >> s[i].name >> s[i].age >> s[i].score;

    //一、按照年龄进行排序
    for (int i = 0; i < n - 1; i++)
        for (int j = 0; j < n - i - 1; j++)
            if (s[j].age > s[j + 1].age)swap(s[j], s[j + 1]);
    //二、按照姓名进行排序
    for (int i = 0; i < n - 1; i++)
        for (int j = 0; j < n - i - 1; j++)
            if (s[j].name > s[j + 1].name)swap(s[j], s[j + 1]);
    //三、按照分数进行排序  由低到高
    for (int i = 0; i < n - 1; i++)
        for (int j = 0; j < n - i - 1; j++)
            if (s[j].score > s[j + 1].score)swap(s[j], s[j + 1]);

    //输出
    for (int i = 0; i < n; i++)
        cout << s[i].name << " " << s[i].age << " " << s[i].score << endl;

    return 0;
}