#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
//#define int long long
using namespace std;

int n;
int c1, m1, s1, m2, s2, m3, s3, m4, s4;
pair<int, int> ttt[1000000];

signed main()
{
	while (true)
	{
		cin >> n;
		if (n == 0) break;
		rep(i,n)
		{
			cin >> c1 >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			int sec = m1 * 60 + s1 + m2 * 60 + s2 + m3 * 60 + s3 + m4 * 60 + s4;
			ttt[i] = pair<int, int>(sec, c1);
		}
		sort(ttt, ttt + n);
		cout << ttt[0].second << endl;
		cout << ttt[1].second << endl;
		cout << ttt[n - 2].second << endl;
	}
}