#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

int main(){
  int h,n,i,j,sum[100000],xmax=0,num1[100000],num2[100000];

  while(1){
    xmax=0;
    for(i=0;i<100000;i++)sum[i]=0;
    

    cin >> n;
    if(n == 0)break;

    for(i=0;i<n;i++){
	cin >> num1[i];
      for(j=1;j<9;j++){

	cin >> num2[j];

	if(j>0 && j%2 == 0){
	  sum[i]+=num2[j];
	}
	else if(j>0 && j%2 != 0){
	  sum[i]+=(num2[j]*60);
	}

      }


    }


    for(i=0;i<n;i++){
      xmax=i;
      for(j=i;j<n;j++){
	if(sum[xmax]<sum[j])xmax=j;
      }
      h=sum[xmax];
      sum[xmax]=sum[i];
      sum[i]=h;

      h=num1[xmax];
      num1[xmax]=num1[i];
      num1[i]=h;
    }
    /*
       
    for(i=0;i<n;i++){
	cout << "num1["<<i<<"]="<<num1[i];
	cout << "  sum["<<i<<"]="<<sum[i];
      cout << endl;
    }
      
    */  


    cout<< num1[n-1] << endl;
    cout << num1[n-2] << endl;
    cout<< num1[1] << endl;






  }







}