/*
	0161:Spoot Meet
*/
#include	<iostream>
#include	<vector>
#include	<algorithm>

using namespace std;

int main(void) {
	int n;
	while(1) {
		cin >> n;
		if(n == 0) { break; }
		vector< pair<int, int> > total(n);
		for(int i = 0; i < n; i++) {
			int c, m1, s1, m2, s2, m3, s3, m4, s4, ts1, ts2, ts3, ts4;
			cin >> c >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			ts1 = 60 * m1 + s1;
			ts2 = 60 * m2 + s2;
			ts3 = 60 * m3 + s3;
			ts4 = 60 * m4 + s4;
			total[i] = make_pair(ts1 + ts2 + ts3 + ts4, c);
		}
		sort( total.begin(), total.end() );
		cout << total[0].second << endl << total[1].second << endl << total[n-2].second << endl;
	}
}