// 2011/02/07 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		int p1 = 0;
		int p2 = 0;
		int p3 = 0;
		int p4 = 0;
		int t1 = 60*60*4;
		int t2 = 60*60*4;
		int t3 = -1;
		int t4 = -1;

		for(int i=0; i<n; i++){
			int c1, m1, s1, m2, s2, m3, s3, m4, s4;
			cin >> c1 >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			int t = (m1+m2+m3+m4)*60+s1+s2+s3+s4;

			if(t<t1){
				p2 = p1;
				t2 = t1;
				p1 = c1;
				t1 = t;
			}
			else if(t<t2){
				p2 = c1;
				t2 = t;
			}

			if(t>t4){
				p3 = p4;
				t3 = t4;
				p4 = c1;
				t4 = t;
			}
			else if(t>t3){
				p3 = c1;
				t3 = t;
			}
		}

		cout << p1 << endl;
		cout << p2 << endl;
		cout << p3 << endl;
	}

	return 0;
}