### subroutines

def t_cmp(a, b)
  c0 = b[2] - a[2]
  c1 = a[3] - b[3]
  (c0 != 0) ? c0 : ((c1 != 0) ? c1 : a[0] - b[0])
end

### main

loop do
  n = gets.to_i
  break if n == 0

  ts = []
  n.times do
    t = gets.split.map(&:to_i)
    ts << t
  end

  ts.sort!{|a, b| t_cmp(a, b)}
  #p ts

  sels = {}
  scount = 0

  for t in ts
    id, af = t

    sels[af] = [] if sels[af].nil?
    slen = sels[af].length
    sok = false

    case scount
    when 0...10
      sok = true if slen < 3
    when 10...20
      sok = true if slen < 2
    when 20...26
      sok = true if slen < 1
    end

    if sok
      scount += 1
      sels[af] << id
      puts id
    end
  end
end