#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main()
{
  int n;
  for(;cin>>n,n;)
    {
      vector<pair<int,int> > list;
      for(int i=0;i<n;i++)
	{
	  int c,m[4],s[4];
	  cin>>c>>m[0]>>s[0]>>m[1]>>s[1]>>m[2]>>s[2]>>m[3]>>s[3];
	  list.push_back(pair<int,int>(m[0]*60+m[1]*60+m[2]*60+m[3]*60+s[0]+s[1]+s[2]+s[3],c));
	}
      sort(list.begin(),list.end());
      cout<<list[0].second<<endl;
      cout<<list[1].second<<endl;
      cout<<list[list.size()-2].second<<endl;
    }
}