#include <iostream>
using namespace std;

int main(void){
	int i,sum;
	int n,c,m,s;

	while(cin>>n && n){
		int name[4],time[4]={999999999,999999999,-1,-1};

		while(n--){
			cin>>c;
			for(i=sum=0;i<4;i++){
				cin>>m>>s;
				sum += m*60 + s;
			}
			if(time[0]>sum){
				name[1] = name[0];
				time[1] = time[0];
				name[0] = c;
				time[0] = sum;
			}
			else if(time[1]>sum){
				name[1] = c;
				time[1] = sum;
			}

			if(time[3]<sum){
				name[2] = name[3];
				time[2] = time[3];
				name[3] = c;
				time[3] = sum;
			}
			else if(time[2]<sum){
				name[2] = c;
				time[2] = sum;
			}
		}

		for(i=0;i<3;i++) cout<<name[i]<<endl;
	}

	return 0;
}