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


//DATA構造体
typedef struct struct_data
{
	int time;
	int number;
}S_data;


//入力構造体
typedef struct struct_input
{
	int m1 , n1;
	int m2 , n2;
	int m3 , n3;
	int m4 , n4;
}S_input;


int main(void)
{
	//最大値
	int n = 0;
	//構造体変数宣言
	S_data s_data[1000000] = {0};
	//入力変数
	S_input s_input;
	//交換構造体
	S_data s_tmp1 , s_tmp2;
	//交換構造体ポインタ
	S_data *ptr_tmp1 = &s_tmp1;
	S_data *ptr_tmp2 = &s_tmp2;

	while (cin >> n)
	{
		if (n == 0)
		{
			return 0;
		}
		for (int i = 0; i < n; i++)
		{
			cin >> s_data[i].number;

			//長い
			cin >> s_input.m1 >> s_input.n1 >> s_input.m2 >> s_input.n2;
			cin >> s_input.m3 >> s_input.n3 >> s_input.m4 >> s_input.n4;

			//時間の計測
			s_data[i].time = (s_input.m1 + s_input.m2 + s_input.m3 + s_input.m4) * 60 + s_input.n1 + s_input.n2 + s_input.n3 + s_input.n4;
		}

		//ソート
		for (int i = 0; i < n - 1; i++)
		{
			for (int j = i + 1; j < n; j++)
			{
				if (s_data[i].time > s_data[j].time)
				{
					*ptr_tmp1 = s_data[i];
					*ptr_tmp2 = s_data[j];
					s_data[i] = *ptr_tmp2;
					s_data[j] = *ptr_tmp1;
				}
			}
		}

		//出力
		cout << s_data[0].number << endl;
		cout << s_data[1].number << endl;
		cout << s_data[n - 2].number << endl;

	}

	return 0;
}