#include<iostream>
using namespace std;

int main()
{

	while(true){

		int n;
		int c1;
		int ma, sa;
		int mb, sb;
		int mc, sc;
		int md, sd;
		int t = 0;
		int min = 60*60*4;
		int semimin = 60*60*4;
		int max = -1;
		int max2 = -1;
		int minx = 0, semiminx = 0, maxx = 0, max2x = 0;

		cin >> n;

		if(n==0)
			break;

		for(int i=0 ;i<n ;i++){

			cin >> c1 >> ma >> sa >> mb >> sb >> mc >> sc >> md >> sd;

			int a ,b ,c ,d;
			a = ma*60 + sa;
			b = mb*60 + sb;
			c = mc*60 + sc;
			d = md*60 + sd;

			t = a + b + c + d;

			
			if(t < min){
				semimin = min;
				semiminx = minx;
				min = t;
				minx = c1;
			}
			else if(t < semimin){
				
				semimin = t;
				semiminx = c1;
				
			}
			if(t > max){
				max2 = max;
				max2x = maxx;
				max = t;
				maxx = c1;
			
			}
			else if(t > max2){
				max2 = t;
				max2x = c1;
			}

		}
		cout << minx << endl;
		cout << semiminx << endl;
		cout << max2x << endl;
	}

	return 0;
}