#include <stdio.h>
#include <stack>
#include <math.h>

using namespace std;

struct Info{
	int id,sum;
};

int main(){

   int n,m1,m2,m3,m4,s1,s2,s3,s4,tmp_id,tmp_sum;
   Info table[4];

   while(true){
	   scanf("%d",&n);
	   if(n == 0)break;

	   for(int i=0; i < 4; i++){
		     scanf("%d %d %d %d %d %d %d %d %d",&table[i].id,&m1,&s1,&m2,&s2,&m3,&s3,&m4,&s4);
		     table[i].sum = (60*(m1+m2+m3+m4)+(s1+s2+s3+s4));
	   }

	   for(int i = 1; i <= 3; i++){
		   for(int k=3; k >= 1; k--){
			   if(table[k].sum < table[k-1].sum)swap(table[k],table[k-1]);
		   }
	   }
	   n -= 4;

	   for(int i=0; i < n; i++){
		   scanf("%d %d %d %d %d %d %d %d %d",&tmp_id,&m1,&s1,&m2,&s2,&m3,&s3,&m4,&s4);
		   tmp_sum = (60*(m1+m2+m3+m4)+(s1+s2+s3+s4));

		   if(tmp_sum > table[3].sum){ //??????????°?

			   table[2].id = table[3].id; //?????????????????????
			   table[2].sum = table[3].sum;
			   table[3].id = tmp_id;
			   table[3].sum = tmp_sum;

		   }else if(tmp_sum > table[2].sum){ //tmp???????????????
			   table[2].id = tmp_id;
			   table[2].sum = tmp_sum;

		   }else if(tmp_sum < table[0].sum){

				   table[1].id = table[0].id;
				   table[1].sum = table[0].sum;
				   table[0].id = tmp_id;
				   table[0].sum = tmp_sum;

		   }else if(tmp_sum < table[1].sum){

			   table[2].id = tmp_id;
			   table[2].sum = tmp_sum;
		   }

	   }

	   printf("%d\n",table[0].id);
	   printf("%d\n",table[1].id);
	   printf("%d\n",table[2].id);
   }
    return 0;
}