#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;

struct team{
	long number;
	int time;
};

int main(){
	while(1){
		int n, num;
		cin>>n;
		if(n==0) break;
		
		vector<struct team> a;
		a.resize(n);

		for(int i=0;i<n;i++){
			cin>>a[i].number;
			a[i].time = 0;

			for(int j=0;j<8;j++){
				cin>>num;
				if(j%2 == 0)
					a[i].time += num * 60;
				else
					a[i].time += num;
			}
		}

		int win, pre, boo, los;
		if(a[0].time < a[1].time){
			win = 0;
			pre = 1;
			boo = 0;
			los = 1;
		}else{
			win = 1; 
			pre = 0;
			boo = 1;
			los = 0;
		}
		
		for(int i=2;i<n;i++){
			if(a[i].time < a[win].time){
				pre = win;
				win = i;
			}else if(a[i].time < a[pre].time){
				pre = i;
			}
			

			if(a[i].time > a[los].time){
				boo = los;
				los = i;
			}else if(a[i].time > a[boo].time){
				boo = i;
			}
		}

		cout<<a[win].number<<endl<<a[pre].number<<endl<<a[boo].number<<endl;
	}

	return 0;
}