#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main(void)
{
	int n;
	while (cin >> n, n){
		int c1, m1, s1, m2, s2, m3, s3, m4, s4;
		vector < pair < pair <int, int>, int> > data;
		for (int i = 0; i < n; i++){
			cin >> c1 >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			int minute = m1 + m2 + m3 + m4;
			int sec = s1 + s2 + s3 + s4;
			minute += (sec / 60);
			sec %= 60;
			data.push_back(make_pair(make_pair(minute, sec), c1));
		}
		sort(data.begin(), data.end());
		cout << data[0].second << endl;
		cout << data[1].second << endl;
		cout << data[data.size() - 2].second << endl;
	}

	return 0;
}