Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"sort"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

type Team struct {
	Id int
	Time int
}

type ByTime []Team
func (a ByTime) Len() int {
	return len(a)
}
func (a ByTime) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}
func (a ByTime) Less(i, j int) bool {
	return a[i].Time < a[j].Time
}

func main() {
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		teams := make([]Team, n)
		for i := 0; i < n; i++ {
			scanner.Scan()
			buf := strings.Split(scanner.Text(), " ")
			id, _ := strconv.Atoi(buf[0])
			m1, _ := strconv.Atoi(buf[1])
			s1, _ := strconv.Atoi(buf[2])
			m2, _ := strconv.Atoi(buf[3])
			s2, _ := strconv.Atoi(buf[4])
			m3, _ := strconv.Atoi(buf[5])
			s3, _ := strconv.Atoi(buf[6])
			m4, _ := strconv.Atoi(buf[7])
			s4, _ := strconv.Atoi(buf[8])
			team := Team{id, m1*60+s1+m2*60+s2+m3*60+s3+m4*60+s4}
			teams[i] = team
		}
		sort.Sort(ByTime(teams))
		fmt.Println(teams[0].Id)
		fmt.Println(teams[1].Id)
		fmt.Println(teams[len(teams)-2].Id)
	}
}

C++: #include<bits/stdc++.h>
using namespace std;

typedef long long ll;

struct hoge{
    ll s, n;
    hoge(ll s, ll n) : s(s), n(n) { }
};
bool operator < (const hoge &a, const hoge &b){
    return a.n != b.n ? a.n < b.n : a.s < b.s;
}

int main(void){
    while(true){
        ll n;
        cin >> n;
        if(n==0) break;
        vector<hoge> v;
        ll id, m1, s1, m2, s2, m3, s3, m4, s4;
        
        for(ll i=0; i<n; i++){
            cin >> id >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
            ll sum=60*m1+s1+60*m2+s2+60*m3+s3+60*m4+s4;
            v.push_back(hoge(id, sum));
        }
        sort(v.begin(), v.end());
        
        cout << v[0].s << "\n";
        cout << v[1].s << "\n";
        cout << v[n-2].s << "\n";
         
    }
     
     
    return 0;
}

C++: #include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;

void mainmain(){
	int n;
	while(cin>>n,n){
		vector<pii> v(n);
		rep(i,n){
			int id;
			cin>>id;
			int t=0;
			rep(j,4){
				int a,b;
				cin>>a>>b;
				t+=a*60+b;
			}
			v[i]=mkp(t,id);
		}
		sort(ALL(v));
		cout<<v[0].S<<endl;
		cout<<v[1].S<<endl;
		cout<<v[v.size()-2].S<<endl;
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>

typedef struct {
	int id;
	int time;
} Team;

using namespace std;

bool operator < (const Team &a, const Team &b)
{
	return (a.time < b.time);
}

int main()
{
	int n;
	
	while (scanf("%d", &n) && n){
		vector<Team> in(n);
		
		for (int i = 0; i < n; i++){
			int m, s;
			scanf("%d", &in[i].id);
			in[i].time = 0;
			for (int j = 0; j < 4; j++){
				scanf("%d %d", &m, &s);
				in[i].time += m * 60 + s;
			}
		}
		
		sort(in.begin(), in.end());
		
		printf("%d\n%d\n%d\n", in[0].id, in[1].id, in[n - 2].id);
	}
	
	return (0);
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

bool pairCompare(const std::pair<int, int>& firstElem, const std::pair<int, int>& secondElem) {
    return firstElem.second < secondElem.second;
}

int main(){
    int n;
    while(cin >> n, n){
        vector<pair<int ,int> > v;
        rep(i,n){
            int id;
            cin >> id;
            int t = 0;
            rep(j, 4){
                int m, s;
                cin >> m >> s;
                t += m*60+s;
            }
            v.pb(mp(id, t));
        }
        sort(all(v), pairCompare);

        rep(i, 3){
            cout << v[i].first << endl;
        }
    }
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

class Time{
public:
	int id,score;
	Time(int _id,int _score){
		id = _id;
		score = _score;
	}
	bool operator<(const Time &t)const{
		return score < t.score;
	}
};

int main(void){
	int n;
	while(cin>>n,n){
			vector<Time> v;
		for(int i=0;i<n;i++){
			int id;
			cin>>id;
			int sum = 0;
			for(int j=0;j<4;j++){
				int x,y;
				cin>>x>>y;
				sum += x * 60 + y;
			}
			v.push_back(Time(id,sum));
		}
		sort(v.begin(),v.end());
		cout<<v[0].id<<endl;
		cout<<v[1].id<<endl;
		cout<<v[v.size()-2].id<<endl;
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

bool pairCompare(const std::pair<int, int>& firstElem, const std::pair<int, int>& secondElem) {
  return firstElem.second < secondElem.second;
}

int main(){
    int n;
    while(cin >> n, n){
        typedef pair<int, int> value_type;
        vector<value_type> team;
        int c, m, s;
        for(int j=0; j < n; j++){
            cin >> c;
            team.push_back(pair<int, int>(c, 0));
            for(int i=0; i < 4; i++){
                cin>> m >> s;
                team[j].second += 60*m + s;
            }
        }
        sort(team.begin(), team.end(), pairCompare);

        cout << team[0].first << endl;
        cout << team[1].first << endl;
        cout << team[team.size()-2].first << endl;
        team.clear();
    }
}