#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

class Team{
public:
  int n,m,s;
  bool operator < (const Team &t)const{
    if(m == t.m) return s < t.s;
    else return m < t.m;
  }
};

int main(){
  int i,j,n;
  while(1){
    cin >> n;
    if(n == 0) break;
    Team t[1000000];

    for(i=0;i<n;i++){
      cin >> t[i].n;
      t[i].m = t[i].s = 0;

      for(j=0;j<4;j++){
	int m,s;
	cin >> m >> s;
	t[i].m += m;
	t[i].s += s;
      }

      while(t[i].s >= 60){
	t[i].m++;
	t[i].s -= 60;
      }
    }

    sort(t,t+n);
    cout << t[0].n << endl;
    cout << t[1].n << endl;
    cout << t[n-2].n << endl;
  }  
  return 0;
}