import scala.annotation.tailrec

object Main extends App {

  import scala.io.StdIn._
  import scala.math._
  solve
  def solve: Unit ={
    val n = readLine.trim.toInt
    if (n == 0) return
    val teams = Array.tabulate(n){_ ⇒
      val Array(i, u, a, p) = readLine.trim.split(' ').map(_.toInt)
      Team(i, u, a, p)
    }.sortBy(it ⇒ it.ac * 1000000 - it.wa * 1000 - it.id).reverse
    val group = Array.tabulate(1001){_ ⇒ 0}
    var sum = 0
    for (t ← teams){
      if (sum < 10 && group(t.associate) < 3){
        println(t.id)
        sum += 1
        group(t.associate) += 1
      }else if (sum < 20 && group(t.associate) < 2){
        println(t.id)
        sum += 1
        group(t.associate) += 1
      }else if (sum < 26 && group(t.associate) < 1){
        println(t.id)
        sum += 1
        group(t.associate) += 1
      }
    }


    solve
  }
  case class Team(id: Int, associate: Int, ac: Int, wa: Int)
  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}
