#include<iostream>
using namespace std;
int main(){
  int n,c,m1,s1,m2,s2,m3,s3,m4,s4,time;
  while(cin>>n){
    if(n==0) break;
    int anst[4]={0};
    int ans[4];
    for(int i=0;i<2;i++) anst[i] = 1000000;
    for(int i=0;i<n;i++){
      cin >> c >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
      time=m1*60+s1+m2*60+s2+m3*60+s3+m4*60+s4;
      if(anst[0]>time){
	anst[1] = anst[0];
	ans[1] = ans[0]; 
	anst[0] = time;
	ans[0] = c; 
      }
      else if(anst[1]>time){
	anst[1] = time;
	ans[1] = c;
      }
      if(anst[3]<time){
	anst[2] = anst[3];
	ans[2] = ans[3];
	anst[3] = time;
	ans[3] = c;
      }
      else if(anst[2]<time){
	anst[2] = time;
	ans[2] = c;
      }
    }
    cout << ans[0] << endl << ans[1] << endl << ans[2] << endl;
  }
  return 0;
}