loop do
  n = gets.to_i
  break if n==0
  hash = Hash.new
  n.times do
    c,*ms = gets.split.map(&:to_i)
    sum = 0
    ms.each_with_index do |m,i|
      sum+= (i.even? ? 60 : 1) *m
    end
    hash[c] = sum
  end
  r = hash.keys.sort{|a,b| hash[a]-hash[b]}
  puts r[0]
  puts r[1]
  puts r[-2]
end