#include <iostream>
#include <algorithm>
using namespace std;
struct team{
	int n;
	long long int t;
};
team a[1000000];
bool comp(const team &t1,const team &t2){
	return t1.t < t2.t;
}
int main(){
	int n,i,c,m1,s1,m2,s2,m3,s3,m4,s4,t;
	team x;
	while(cin >> n && n){
		for(i = 0;i < n;i++){
			cin >> c >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			t = (m1 * 60 + s1) + (m2 * 60 + s2) + (m3 * 60 + s3) + (m4 * 60 + s4);
			x.n = c;
			x.t = t;
			a[i] = x;
		}
		sort(a,a+n,comp);
		cout << a[0].n << "\n" << a[1].n << "\n" << a[n - 2].n << endl;
	}
	return 0;
}