#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
typedef pair<int,int> P;
vector<P> sc;

int main(void){
	while(1){
		sc.clear();
		int n;
		scanf("%d",&n);
		if(n==0)break;
		for(int i=0;i<n;i++){
			int res=0;
			int t=0;
			scanf("%d",&t);
			for(int j=0;j<4;j++){
				int m,s;
				scanf("%d%d",&m,&s);
				res+=m*60+s;
			}
			sc.push_back(P(res,t));
		}
		sort(sc.begin(),sc.end());
		cout << sc[0].second << endl;
		cout << sc[1].second << endl;
		cout << sc[n-2].second << endl;
	}
    return 0;
}