#include <bits/stdc++.h>
using namespace std;
const double eps=1e-9;
typedef vector<int> vi;
typedef long long ll;
int A[5],B[5];
string rule[5][5];
#define pb push_back
string s;
int main(void)
{
  int n;
  while(cin >> n && n)
    {
      vector<pair<int,int>> teams;
      for(int i=0;i<n;i++)
	{
	  int id,m1,s1,m2,s2,m3,s3,m4,s4;
	  cin >> id >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
	  teams.push_back(make_pair(60*(m1+m2+m3+m4)+(s1+s2+s3+s4),id));
	}
      sort(teams.begin(),teams.end());
      for(int i=0;i<n;i++)
	{
	  if(i==0 || i==1 || i==n-2)
	    {
	      cout << teams[i].second << endl;
	    }
	}
    }
  return 0;
}

