
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<complex>
using namespace std ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<string> vs ;
typedef pair<int, int> pii; 
typedef long long ll ;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()

int main(void){
  int n;
  int const teamname = 0;
  int const point = 1;
  while(cin>>n,n){
    vector < vector<int > > team(n+1,vector<int>(2));
    rep(i,n){
		
      int m,s;
      cin>>team[i][teamname];
      rep(h,4){
				cin>>m>>s;
				team[i][point]+=m*60+s;
			}
	
    }
    
    rep(i,n-1){
			loop(j,i,n){
	  		if(team[i][point]>team[j][point]){
	    		team[n][teamname]=team[i][teamname];
	    		team[i][teamname]=team[j][teamname];
	    		team[j][teamname]=team[n][teamname];
	    		team[n][teamname]=0;
				
	  		  team[n][point]=team[i][point];
	 		   team[i][point]=team[j][point];
	   		 team[j][point]=team[n][point];
	   		 team[n][point]=0;
				
			  }
			}
    }
    
/*    rep(i,n){
    	cout<<team[i][teamname]<<" "<<team[i][point]<<endl;
    }
    */
		rep(i,2){
	
	 	 cout<<team[i][teamname]<<endl;		

		}
		cout<<team[n-2][teamname]<<endl;
  }

}