#include<cstdio>
#include<utility>
#include<algorithm>
#include<functional>
using namespace std;
typedef pair<int,int> PII;
PII t[1000000];
int main()
{
	int n,c,i,m1,m2,m3,m4,s1,s2,s3,s4;
	while(scanf("%d",&n),n)
	{
		for(i=0;i<n;++i)
		{
			scanf("%d%d%d%d%d%d%d%d%d",&c,&m1,&s1,&m2,&s2,&m3,&s3,&m4,&s4);
			t[i].first=(m1+m2+m3+m4)*60+s1+s2+s3+s4;
			t[i].second=c;
		}
		partial_sort(t,t+2,t+n);
		printf("%d\n%d\n",t[0].second,t[1].second);
		partial_sort(t,t+2,t+n,greater<PII>());
		printf("%d\n",t[1].second);
	}
	return 0;
}