#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;


int main () {

const int cnum = 10;
int **p_teams;        /* teamの配列を入れるポインタのポインタ */
int *p_t;
int *p_t2;

int team_num;

	while (1) {
		cin >> team_num;      /* チームの数を取り込む */

		if (team_num < 2) {
			break;
		}

		p_teams = new int*[team_num]; /* チームのデータを保存する領域を確保　*/

		for (int i = 0;i < team_num;i++)
		{
			p_teams[i] = new int[cnum];      /* チームごとのデータ領域を確保 */
		}

		for (int i = 0; i < team_num; i++) {
			p_t = p_teams[i];

			cin >> p_t[0] >> p_t[1] >> p_t[2] >> p_t[3] >> p_t[4] >> 
			p_t[5] >> p_t[6] >> p_t[7] >> p_t[8];

			int m = p_t[1] + p_t[3] + p_t[5] + p_t[7];
			int s = p_t[2] + p_t[4] + p_t[6] + p_t[8];
			p_t[9] = m * 60 + s;

			p_t++;
		}

		for (int i = 0; i < team_num - 1;i++)
		{
			p_t = p_teams[i];
			for (int j = i + 1;j < team_num;j++)
			{
				p_t2 = p_teams[j];
				// cout << p_t[0] << " " << p_t[9] << " " << p_t2[0] << " " << p_t2[9] << "\n";
				if (p_t[9] > p_t2[9]) {
					int *x = p_teams[i];
					p_teams[i] = p_teams[j];
					p_teams[j] = x;
				}
			}
		}

		cout << p_teams[0][0] << "\n" << p_teams[1][0] << "\n" << p_teams[team_num - 2][0]<< endl;
		
		for (int i = 0;i < team_num;i++)
		{
			delete[] p_teams[i];      /* チームごとのデータ領域を解放 */
			p_t++;
		}

		delete[] p_teams;
	} 
	
  return 0;
}