#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

struct T
{
    int i, u, a, p;
};

bool operator<( T const& lhs, T const& rhs )
{
    return ( lhs.a > rhs.a )
        || ( lhs.a == rhs.a && lhs.p < rhs.p )
        || ( lhs.a == rhs.a && lhs.p == rhs.p && lhs.i < rhs.i );
}
ostream& operator<<( ostream& os, T const& t )
{
    os << t.i << " " << t.u << " " << t.a << " " << t.p;
    return os;
}

int main()
{
    for(;;) {
        int n;
        cin >> n;

        if ( n == 0 )
            break;

        vector<T> v;
        for( int iii=0; iii<n; ++iii ) {
            T t;
            cin >> t.i >> t.u >> t.a >> t.p;
            v.push_back( t );
        }

        stable_sort( v.begin(), v.end() );

        

        map<int, int> teams;
        vector<T> selected;
        for( int i=0; i<v.size(); ++i ) {
            T const& t = v[i];

            if ( selected.size() < 10 ) {
                if ( teams[t.u] < 3 ) {
                    selected.push_back( t );
                    ++teams[t.u];
                }
            } else if ( selected.size() < 20 ) {
                if ( teams[t.u] < 2 ) {
                    selected.push_back( t );
                    ++teams[t.u];
                }
            } else if ( selected.size() < 26 ) {
                if ( teams[t.u] < 1 ) {
                    selected.push_back( t );
                    ++teams[t.u];
                }
            }
        }


        for( int i=0; i<selected.size(); ++i )
            cout << selected[i].i << endl;    
    }
}