#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;

vector<P> a;

int main() {
  int n,m,s,c1,m1,s1,m2,s2,m3,s3,m4,s4;
  while(cin >> n) {
    a.clear();
    if(n==0) break;
    for(int i=0;i<n;i++) {
      cin >> c1 >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
      m = m1+m2+m3+m4;
      s = s1+s2+s3+s4+m*60;
      P temp;
      temp.first = s;
      temp.second = c1;
      a.push_back(temp);
    }
    sort(a.begin(),a.end());
    cout << a[0].second << endl;
    cout << a[1].second << endl;
    cout << a[n-2].second << endl;
  }
}