while true
    n = gets.to_i
    break if n == 0
    teams = {}
    n.times{
        name, m1, s1, m2 ,s2, m3, s3, m4, s4 = gets.chomp.split.map(&:to_i)
        teams[name] = (m1 + m2 + m3 + m4) * 60 + (s1 + s2 + s3 + s4)
    }
    arr = teams.to_a.sort_by{|n, t| t}    
    puts arr[0][0]
    puts arr[1][0]
    puts arr[-2][0]
end
