#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int main(){
  int n;
  P team[1000010];
  while(cin >> n , n){
    for(int i=0;i<n;i++){
      cin >> team[i].second;
      team[i].first = 0;
      for(int j=0;j<8;j++){
	int a; cin >> a;
	if(j % 2 == 0) team[i].first += a*60;
	else team[i].first += a;
      }
    }
    sort(team,team+n);
    cout << team[0].second << endl;
    cout << team[1].second << endl;
    cout << team[n-2].second << endl;
  }  
}