#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  int n,id,m1,s1,m2,s2,m3,s3,m4,s4,sum;
  vector<pair<int,int>> v;
  pair<int,int> p;

  cin>>n;

  for(int i = 0;i<n;++i){
    cin>>id>>m1>>s1>>m2>>s2>>m3>>s3>>m4>>s4;
    sum = (m1+m2+m3+m4)*60+(s1+s2+s3+s4);
    v.push_back(make_pair(sum,id));
  }

  sort(v.begin(),v.end());

  p = v[0];

  cout<<p.second<<endl;

  p = v[1];

  cout<<p.second<<endl;

  p = v[n-2];

  cout<<p.second<<endl;

  return 0;
}