#include<bits/stdc++.h>
using namespace std;

struct worker {
    int num;
    string name;
    int age;
} er[100];

bool cmp(worker a, worker b) {
    if (a.age == b.age) {
        if (a.num == b.num) {
            return a.name < b.name;
        } else {
            return a.num < b.num;
        }
    } else {
        return a.age < b.age;
    }
}

int main() {
    int n;
    while (cin >> n) {
        if (n < 3) {
            break;
        }
        for (int i = 0; i < n; i++) {
            cin >> er[i].num >> er[i].name >> er[i].age;
        }
        sort(er, er + n, cmp);
        for (int i = 0; i < (n < 3 ? n : 3); i++) {
            cout << er[i].num << " " << er[i].name << " " << er[i].age << endl;
        }
    }
    return 0;
}