#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 100000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int n,id,m1,m2,m3,m4,s1,s2,s3,s4;
  pi score[100005];
  while(cin>>n){
    if(n==0)break;
    rep(i,n){
      cin>>score[i].second>>m1>>s1>>m2>>s2>>m3>>s3>>m4>>s4;
      score[i].first=(m1+m2+m3+m4)*60+(s1+s2+s3+s4);
    }
    sort(score,score+n);
    cout<<score[0].second<<endl<<score[1].second<<endl<<score[n-2].second<<endl;
  }
  return 0;
}