
import scala.annotation.tailrec

object Main extends App {

  import scala.io.StdIn._

  solve
  @tailrec
  def solve: Unit = {
    val n = readLine.trim.toInt
    if (n == 0) return
    val teams = Array.tabulate(n){_ ⇒
      readLine.trim.split(' ').map(_.toInt)
    }.sortBy(l ⇒ (1 until 8).by(2).map(i ⇒ l(i) * 60 + l(i + 1)).sum)
    println(teams(0).head)
    println(teams(1).head)
    println(teams(n - 2).head)
    solve
  }
  implicit class Extension[T](value :T){
    @inline
    def let[A](@inline func: T ⇒ A): A = func(value)
    @inline
    def also(@inline func: T ⇒ Unit): T = {func(value); value}
  }
}
