#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (int)(a); v < (int)(b); ++v)
#define FORE(v, a, b) for(int v = (int)(a); v <= (int)(b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define RS resize
#define CLR clear
#define PB push_back
#define ALL(x) (x).begin(), (x).end()
using namespace std;

void split(string str, char chr, vector< string > *res){
	stringstream ss(str);
	string itm;
	while(getline(ss, itm, chr)){
		(*res).PB(itm);
	}
}

class Score{
public:
	int i, u, a, p;
	Score() : i(0), u(0), a(0), p(0) {}
};

bool comp(Score a, Score b){
	if(a.a != b.a){
		return a.a > b.a;
	}
	if(a.p != b.p){
		return a.p < b.p;
	}
	return a.i < b.i;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, i, u, p, a;
	vector< Score > s;
	queue< int > q;
	vector< int > univ;
	
	
	while(cin >> n, n){
		s.RS(n);
		univ.CLR();
		univ.RS(1000);
		
		REP(j, n){
			cin >> i >> u >> a >> p;
			s[j].i = i;
			s[j].u = u;
			s[j].a = a;
			s[j].p = p;
		}
		
		sort(ALL(s), comp);
		
		REP(j, n){
			if(q.size() < 10 && univ[s[j].u - 1] < 3){
				q.push(s[j].i);
				++univ[s[j].u - 1];
			}else if(q.size() < 20 && univ[s[j].u - 1] < 2){
				q.push(s[j].i);
				++univ[s[j].u - 1];
			}else if(q.size() < 26 && univ[s[j].u - 1] == 0){
				q.push(s[j].i);
				++univ[s[j].u - 1];
			}
		}
		
		while(!q.empty()){
			cout << q.front() << endl;
			q.pop();
		}
	}
	
	return 0;
}