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

int main() {
	int n;
	while (cin >> n, n) {
		map<int, string>m;
		for (int i = 0;i < n;i++) {
			string s;
			int a[8];
			cin >> s;
			for (int j = 0;j < 8;j++)cin >> a[j];
			int t = 0, se = 0;
			for (int j = 0;j < 8;j += 2)t += a[j];
			for (int j = 1;j < 8;j += 2)se += a[j];
			int b = t * 60 + se;
			m.insert(make_pair(b, s));
		}
		auto itr = m.begin();
		cout << itr->second << endl;
		itr++;
		cout << itr->second << endl;
		auto it= m.rbegin();
		it++;
		cout << it->second << endl;

	}
	return 0;
}