import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.typecons;

alias Tuple!(int, "id", int, "af", int, "ac", int, "pn") Team;

void main(){
	
    while(true){
        int n = readln.chomp.to!int;
        if(n == 0) break;

        Team[] teams;
		int selected;
		int[1001] selectedAf;
        foreach(i; 0..n){
            auto input = readln.split.map!(to!int);
            teams ~= Team(input[0], input[1], input[2], input[3]);
        }

        teams.sort!("a.id < b.id", SwapStrategy.stable)();
        teams.sort!("a.pn < b.pn", SwapStrategy.stable)();
        teams.sort!("a.ac > b.ac", SwapStrategy.stable)();

        
        foreach(team; teams){
            if((selected < 10 && selectedAf[team.af] < 3) || (selected < 20 && selectedAf[team.af] < 2) || (selected < 26 && selectedAf[team.af] == 0)){
                team.id.writeln;
                ++selected;
                ++selectedAf[team.af];
            }
        }
    }
}