#include<iostream>
#include<map>
using namespace std;

int main()
{
	map<int, int> m;
	map<int, int>::iterator it;
	int n, i, j;
	int a, b, c;
	int t;
	while (cin>>n, n) {
		m.clear();
		for (i = 0; i < n; i++) {
			cin>>c;
			t = 0;
			for (j = 0; j < 4; j++) {
				cin>>a>>b;
				t += a*60 + b;
			}
			m[t] = c;
		}
		it = m.begin();
		cout<<(*it).second<<endl;
		cout<<(*++it).second<<endl;
		cout<<(*----m.end()).second<<endl;
	}
	return 0;
}