#include<bits/stdc++.h>
using namespace std;
main(){
  int n;
  while(cin>>n,n){
    pair<int,int>a[n];
    for(int i=0;i<n;i++){
      int q,w,e,r,t,y,u,o,p;
      cin>>q>>w>>e>>r>>t>>y>>u>>o>>p;
      a[i].second=q;
      a[i].first=(w+r+y+o)*60+e+t+u+p;
    }
    sort(a,a+n);
    cout<<a[0].second<<endl<<a[1].second<<endl<<a[n-1].second<<endl;
  }
}