while n = gets.to_i
  break if n.zero?
  teams = {}
  n.times do
    id, m1, s1, m2, s2, m3, s3, m4, s4 = gets.split.map(&:to_i)
    teams[id] = 60*(m1+m2+m3+m4) + (s1+s2+s3+s4)
  end
  result = teams.sort_by{|k,v| v}.map{|kv| kv.first}
  puts result[0]
  puts result[1]
  puts result[-2]
end