#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

struct DATA{
  int ID;
  int Time;
};

bool compare(const DATA&, const DATA&);

int main(){
  int i, n;
  int c1, m1, s1, m2, s2, m3, s3, m4, s4;
  DATA _data;
  vector<DATA> data;

  while(1){
    cin >> n;
    if(n == 0) break;

    for(i=0; i<n; i++){
      cin >> c1 >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
      _data.ID = c1;
      _data.Time = 60*(m1+m2+m3+m4) + s1+s2+s3+s4;
      data.push_back(_data);
    }

    sort(data.begin(), data.end(), compare);

    cout << data[0].ID << endl;
    cout << data[1].ID << endl;
    cout << data[data.size()-2].ID << endl;

    data.clear();
  }

  return 0;
}

bool compare(const DATA& x, const DATA& y){
  return (x.Time < y.Time);
}