#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
//	cut here before submit 
//	freopen ("testcase.sportmeet", "r", stdin );
	string str = "";
	int n;

	while (getline (cin, str ) ){
		stringstream ssn(str);
		ssn >> n;

		if (n == 0 ){
			break;
		} // end if

		int i,j;
		map <int, int> rank;

		for (i = 0; i < n; ++i){
			int c1;
			vector <int> m(4, 0), s(4, 0);
			int total = 0;
			getline (cin, str );
			stringstream ss(str);
			ss >> c1;
			for (j = 0; j < 4; ++j){
				ss >> m[j] >> s[j];
			} // end for
			total += accumulate (m.begin(), m.end(), 0 );
			total *= 60;
			total += accumulate (s.begin(), s.end(), 0 );
			rank[total] = c1;
		} // end for

		map<int,int>::iterator it = rank.begin();
		cout << (*it).second << endl;
		++it;
		cout << (*it).second << endl;
		map<int, int>::reverse_iterator itr = rank.rbegin();		
		++itr;
		cout << (*itr).second << endl;
	} // end loop
		
	return 0;
}