#include<iostream>

using namespace std;

const int INF = (1<<20);

typedef struct{
  int ID;
  int sum;
}TEAM;

int main(){

  int in;
  while(cin >> in && in){
    TEAM data[in];
    for(int i = 0; i < in; i++){
      cin >> data[i].ID;
      data[i].sum = 0;
      for(int j = 0; j <4; j++){
	int min, sec;
	cin >> min >> sec;
	data[i].sum += min*60 + sec;
      }
    }

    TEAM max;
    int Tnum;
    max.sum = INF;
    for(int i = 0; i < in; i++){
      if(data[i].sum < max.sum){
	max = data[i];
	Tnum = i;
      }
    }
    cout << max.ID << endl;
    data[Tnum].sum = INF;

    max.sum = INF;
    for(int i = 0; i < in; i++){
      if(data[i].sum < max.sum){
	max = data[i];
	Tnum = i;
      }
    }

    cout << max.ID << endl;
    data[Tnum].sum = INF;

    max.sum = 0;
    for(int i = 0; i < in; i++){
      if(data[i].sum > max.sum && data[i].sum != INF){
	max = data[i];
	Tnum = i;
      }
    }
    data[Tnum].sum = INF;
    max.sum = 0;
    for(int i = 0; i < in; i++){
      if(data[i].sum > max.sum && data[i].sum != INF) max = data[i];
    }
    cout << max.ID << endl;
  }
  return 0;
}