while n = gets.to_i
  break if n == 0
  team = Array.new
  univ = Array.new(1001, 0)
  sum = 0
  n.times do
    i, u, a, p = gets.split.map(&:to_i)
    team << [10-a,p,i,u]
  end
  team.sort!
  team.each do |item|
    u = item[3]
    if (sum < 10 && univ[u] < 3) || (sum < 20 && univ[u] < 2) ||
       (sum < 26 && univ[u] < 1)
      p item[2]
      univ[u] += 1
      sum += 1
    end
  end
end