while input = $stdin.gets do
  n = input.to_i
  break if n == 0

  result = Array.new
  n.times do
    data = $stdin.gets.chomp.split(" ").map(&:to_i)
    result << [data[0],(data[1] + data[3] + data[5] + data[7]) * 60 + data[2] + data[4] + data[6] + data[8]]
  end
  rank = result.select{|d| d != nil}
  rank.sort!{|d1, d2| d1[1] <=> d2[1]}
  printf "%d\n", rank[0][0]
  printf "%d\n", rank[1][0]
  printf "%d\n", rank[rank.size - 2][0]
end