#include <iostream>
#include <set>
using namespace std;
#define P pair<int,int>
int main()
{
  int n,i;
  for(;;){
    cin >> n;
    if(n==0)break;
    set< P > se;
    while(n--){
      int c,m,s,j=0;
      cin >> c;
      for(i=0;i<4;i++){
	cin >> m >> s;
	j += m*60+s;
      }
      se.insert( P(j,c) );
    }
    set< P >::iterator it = se.begin();
    for(i=0;i<2;i++){
      cout << (*it).second << endl;
      it++;
    }
    set< P >::reverse_iterator r = se.rbegin();
    r++;
    cout << (*r).second << endl;
  }
  return 0;
}