#include<iostream>

using namespace std;



int main(){
	int win[2]={},semiwin[2]={},dobe[2]={},semidobe[2]={},jointeams,team,i,j,total,firstteam[4]={},firsttotal[4]={};



	cin >> jointeams;


	

	for(i=0;i<=3;i++){
		cin >> firstteam[i];

		for(j=1;j<=4;j++){
			cin >> temp;
			firsttotal[i] += temp*60;
			cin >> temp;
			firsttotal[i] += temp;
		}
	}

	for(i=2;i!=0;i--){
		for(j=0;j<=i;j++){
			if(firsttotal[j] > firsttotal[j+1]){
				temp = firsttotal[j];
				firsttotal[j] = firsttotal[j+1];
				firsttotal[j+1] = temp;
				temp = firstteam[j];
				firstteam[j] = firstteam[j+1];
				firstteam[j+1] = temp;
			}
		}
	}

		













	for(i=5;i<=jointeams;i++){
		total = 0;
		cin >> team
		for(j=1;j<=4;j++){
			cin >> temp;
			total = total + temp*60;
			cin >> temp;
			total = total + temp;
		}
		if(total>win[1]){
			semiwin[0] = win[0];
			semiwin[1] = win[1];
			win[0] = team;
			win[1] = total;

		}else(total>semiwin[1]){
			semiwin[0] = team;
			semiwin[1] = total;

		}else(total<dobe[1]){
			semidobe[0] = dobe[0];
			semidobe[1] = dobe[1];
			dobe[0] = team;
			dobe[1] = total;

		}else(total<semidobe[1]){
			semidobe[0] = team;
			semidobe[1] = total;
		}


	}

	cout << win[0] << endl;

	cout << semiwin[0] << endl;
	
	cout << dobe[0] << endl;
}