#include<iostream>
#include<algorithm>
#include<map>
#define F first
#define S second
using namespace std;

pair < int, int > p[1000010];

int main(){

  int n;
  int c1,m1,s1,m2,s2,m3,s3,m4,s4;

  while(cin >> n, n){

    for(int i=0;i<n;i++){
      cin >> c1 >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
      p[i].S = c1;
      p[i].F = (m1+m2+m3+m4)*60 + s1+s2+s3+s4;
    }

    sort(p, p+n);

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