#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<utility>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
 
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+9
#define EPS 1e-9
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < (k); i++)
typedef long long ll;
int main(){
    int n;
    while(scanf("%d",&n),n){
	map<int,int>data;
	rep(i,n){
	    int c1,m1,s1,m2,s2,m3,s3,m4,s4;
	    int sum = 0;
	    scanf("%d%d%d%d%d%d%d%d%d",&c1,&m1,&s1,&m2,&s2,&m3,&s3,&m4,&s4);
	    sum = (m1+m2+m3+m4)*60+(s1+s2+s3+s4);
	    data[sum] = c1;
	}
	int cnt = 0;
	map<int,int>::iterator it = data.begin();
	while(cnt < 2){
	    cout << (*it).second << endl;
	    it++;
	    cnt++;
	}
	it = data.end();
	it--;
	it--;
	cout << (*it).second << endl;
    }
    return 0;
}