#include <iostream>
#include <queue>
using namespace std;
struct Staff {
    int id;
    string name;
    int age;
    bool operator<(const Staff& other) const {
        if (age != other.age) return age > other.age;
        else if (id != other.id) return id > other.id;
        return name > other.name;
    }
};
int main() {
    int n;
    cin >> n;
    priority_queue<Staff> pq;
    while (n--) {
        Staff staff;
        cin >> staff.id >> staff.name >> staff.age;
        pq.push(staff);
    }
    for (int i = 0; i < 3 && !pq.empty(); i++) {
        cout << pq.top().id << " " << pq.top().name << " " << pq.top().age << endl;
        pq.pop();
    }
    return 0;
}