#include <stdio.h>
struct worker{
    int number;
    char name[10];
    int age;
};

int min(int x,int y)
{
    if(x>y)
    return y;
    else return x;
}
void fun(struct worker * p,int len)
{
    struct worker tmp;
   for(int i=0;i<len-1;i++)
   {
      for(int j=0;j<len-i-1;j++)
      {
        if(p[j].age>p[j+1].age)
        {
           tmp=p[j];
           p[j]=p[j+1];
           p[j+1]=tmp;
        }
        if(p[j].age==p[j+1].age)
        {
            if(p[j].number>p[j+1].number)
            {
           tmp=p[j];
           p[j]=p[j+1];
           p[j+1]=tmp;
            }
        }
      }
   }
}
int main() {
   
   int n;
   while(~scanf("%d",&n))
   {
   struct worker worker[n];
    for(int i=0;i<n;i++)
    {
        scanf("%d %s %d",&worker[i].number,worker[i].name,&worker[i].age);
    }
    fun(worker,sizeof(worker)/sizeof(worker[0]));
    int x=min(n,3);
    for(int i=0;i<x;i++)
    printf("%d %s %d\n",worker[i].number,worker[i].name,worker[i].age);
   }
    return 0;
}