#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

struct stuff
{
    int ID, age;
    string name;
};

bool my_greater(const stuff &a, const stuff &b)
{
    if(a.age != b.age) return a.age < b.age;
    else return a.ID < b.ID;
}

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    while(cin >> N)
    {
        vector<stuff> vec(N);
        for(int i = 0; i < N; i++)
        {
            cin >> vec[i].ID >> vec[i].name >> vec[i].age;
        }
        sort(vec.begin(), vec.end(), my_greater);
        for(int i = 0; i < 3; i++)
        {
            cout << vec[i].ID << " ";
            cout << vec[i].name << " ";
            cout << vec[i].age << " ";
            cout << "\n";
        }
    }
    return 0;
}