#include <iostream>
#include <algorithm>
using namespace std;

class Team {
public:
  int time;
  int id;
  bool operator <(const Team &t) const {
    return time < t.time;
  }
};

int main() {
  while(1) {
    int n;
    cin >> n;
    if(n == 0) break;
    Team t[n];
    for(int i = 0; i < n; i++) { 
      int c;
      cin >> c;
      t[i].id = c;
      t[i].time = 0;
      for(int j = 0; j < 4; j++) {
	int s, m;
	cin >> m >> s;
	t[i].time += s + m * 60;
      }
    }
    sort(&t[0], &t[n]);
    cout << t[0].id << endl;
    cout << t[1].id << endl;
    cout << t[n-2].id << endl;
  }
  return 0;
}