#include<iostream>
#include<map>
using namespace std;
int main() {
	int n;
	while (cin >> n&&n != 0) {
		map<int, int> p;
		for (int i = 0; i < n; i++) {
			int id, m[4], s[4], sum = 0;
			cin >> id >> m[0] >> s[0] >> m[1] >> s[1] >> m[2] >> s[2] >> m[3] >> s[3];
			for (int i = 0; i < 4; i++) 
				sum += (m[i]*60);
			for (int i = 0; i < 4; i++)
				sum += s[i];
			p.insert(map<int, int>::value_type(sum, id));
		}
		map<int, int>::iterator it = p.begin();
		cout << (*it).second << endl;
		it++;
		cout << (*it).second << endl;
		it = p.end();
		it--;
		it--;
		cout << (*it).second << endl;
	}
}