#include <cstdio>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
vector<pair<int,int> > v;
int main(void){
  int n;
  while(cin >> n){
    if(!n) break;
    v.clear();
    for(int j = 0; j < n; j++){
      int c = 0;
      int id;
      cin >> id;
      for(int i = 0; i < 4; i++){
	int m,s;
	cin >> m >> s;
	c += m*60 + s;
      }
      v.push_back(make_pair(c,id));
    }
    sort(v.begin(),v.end());
    cout << v[0].second << endl;
    cout << v[1].second << endl;
    cout << v[v.size()-2].second << endl;
  }
}