import scala.io.StdIn.{readInt,readLine}
import scala.collection.mutable.ArrayBuffer

object Main {

  def main(args:Array[String]) = {
    val b = new ArrayBuffer[Int]
    var n = 0
    while({n=readInt;n}!=0) {
      val list = {
        for(i<-1 to n) yield {
          val n = readLine.split(" ").map(_.toInt)
          val id = n(0)
          val sec = n(1)*60+n(2)+n(3)*60+n(4)+n(5)*60+n(6)+n(7)*60+n(8)
          (id,sec)
        }
      }.toList.sortWith(_._2<_._2)
      b += list(0)._1
      b += list(1)._1
      b += list(list.length-2)._1
    }
    println(b.mkString("\n"))
  }
}