#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

struct team{int id;int data;};

int main(){
	int n;
	while(cin >> n){
		if(n==0){
			break;
		}
		int *data=new int[n];
		team *t=new team[n];
		for(int i=0;i<n;i++){
			data[i]= 0;
			cin >> t[i].id;
			for(int j=0;j<4;j++){
				int m,s;
				cin >> m >> s;
				data[i] += (m*60+s);
			}
			t[i].data=data[i];
		}
		sort(data,data+n);
		int i=0;
		while(t[i].data!=data[0]){
			i++;
		}
		cout<<t[i].id<<endl;
		i=0;
		while(t[i].data!=data[1]){
			i++;
		}
		cout<<t[i].id<<endl;
		i=0;
		while(t[i].data!=data[n-2]){
			i++;
		}
		cout<<t[i].id<<endl;
		delete[] data;
		delete[] t;
	}
	return 0;
}
