#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    pair<int,int>pii[n];
    for(int i=0;i<n;i++){
      int a,b,c,d,e,f,g,h;
      cin>>pii[i].S;
      cin>>a>>b>>c>>d>>e>>f>>g>>h;
      pii[i].F=100*((a+c+e+g)+(b+d+f+h)/60)+(b+d+f+h)%60;
    }
    sort(pii,pii+n);

    cout<<pii[0].S<<endl;
    cout<<pii[1].S<<endl;
    cout<<pii[n-2].S<<endl;
  }
  return 0;
}