#include <iostream>
#include <algorithm>

using namespace std;

struct staff{
	int id;
	string name;
	int age;
};
staff s[31];

bool cmp(staff x, staff y){
	if (x.age != y.age){
		return x.age < y.age;
	}
	if (x.age == y.age){
		return x.id < y.id;
	}
	if (x.age == y.age && x.id == y.id){
		return x.name < y.name;
	}
	return false;
}

int main (){
	int n;
	while (cin >> n){
		for (int i = 0; i < n; i++){
			cin >> s[i].id >> s[i].name >> s[i].age;
		}
		sort (s, s + n, cmp);
		for (int i = 0; i < 3; i++){
			cout << s[i].id << " " <<s[i].name << " " << s[i].age << endl;
		}
	}
	return 0;
}