#include<bits/stdc++.h>
using namespace std;

typedef long long ll;


struct hoge{
    ll id, solved, penalty, team;
    hoge(ll id, ll solved, ll penalty, ll team) : id(id), solved(solved), penalty(penalty), team(team) { }
};
bool operator < (const hoge &a, const hoge &b){
    return a.solved == b.solved ? (a.penalty == b.penalty ? a.id < b.id : a.penalty < b.penalty) : a.solved > b.solved;
}

int main(void){
    while(true){
        ll n;
        cin >> n;
        if(n==0) break;
        vector<hoge> v;
        for(ll i=0; i<n; i++){
            ll id, u, a, p;
            cin >> id >> u >> a >> p;
            v.push_back(hoge(id, a, p, u));
        }
        sort(v.begin(), v.end());
        
        ll unity[1010];
        ll count=0;
        fill(unity, unity+1010, 0);
        for(ll i=0; i<v.size(); i++){
            unity[v[i].team]++;
            //cout << "i="<<i<<" unity[" <<v[i].team << "]=" << unity[v[i].team] << "\n";
            if(count<10){
                if(unity[v[i].team]<=3){
                    cout << v[i].id << "\n";
                    count++;
                }
            }else if(count<20){
                if(unity[v[i].team]<=2){
                    cout << v[i].id << "\n";
                    count++;
                }
            }else if(count<26){
                //cout << "here" << "\n";
                if(unity[v[i].team]<=1){
                    cout << v[i].id << "\n";
                    count++;
                }
            }
            
        }
        
    }
     
     
    return 0;
}
