#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
struct worker{
int id;
char name[11];
int age;
};
bool comp(worker lhs,worker rhs){
if(lhs.age<rhs.age){
return true;
}
else if(lhs.age==rhs.age&&lhs.id<rhs.id){
return true;
}
else if(lhs.age==rhs.age&&lhs.id==rhs.id&&strcmp(lhs.name,rhs.name)<0){
return true;
}
else
return false;
}
int main()
{
int n;
worker w[1000];
while(scanf("%d",&n)!=EOF){
int i;
for(i=0;i<n;i++){
scanf("%d%s%d",&w[i].id,w[i].name,&w[i].age);
}
sort(w,w+n,comp);
for(i=0;i<3;i++){
printf("%d %s %d\n",w[i].id,w[i].name,w[i].age);
}
}
}