until (num = gets.chomp.to_i) == 0 
team = Hash::new
list = Array.new
num.times do
   temp = gets.chomp.split.map &:to_i
   team.store(temp[0],temp[1]*60 + temp[2]+ temp[3]*60 + temp[4]+ temp[5]*60 + temp[6] + temp[7]*60 + temp[8])
end
list = team.sort {|a,b| a[1]<=>b[1]}  
p list[0][0],list[1][0],list[num-2][0]
end