#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>

using namespace std;

int num_of_selected[1001],total;

struct Info{
	Info(){
		id = group = ans = penalty = 0;
	}
	int id,group,ans,penalty;
};

void func(int N){

	Info info[N];

	for(int i = 0; i < N; i++){
		scanf("%d %d %d %d",&info[i].id,&info[i].group,&info[i].ans,&info[i].penalty);
	}

	for(int i = 1; i <= N-1; i++){
		for(int k = N-1; k >= i; k--){
			if((info[k].ans > info[k-1].ans) || (info[k].ans == info[k-1].ans && info[k].penalty < info[k-1].penalty) ||
					(info[k].ans == info[k-1].ans && info[k].penalty == info[k-1].penalty && info[k].id < info[k-1].id))swap(info[k],info[k-1]);
		}
	}

	total = 0;
	for(int i = 0; i < N && total < 26; i++){
		if(total < 10 && num_of_selected[info[i].group] < 3){
			num_of_selected[info[i].group]++;
			total++;
			printf("%d\n",info[i].id);
		}else if(total < 20 && num_of_selected[info[i].group] < 2){
			num_of_selected[info[i].group]++;
			total++;
			printf("%d\n",info[i].id);
		}else if(total < 26 && num_of_selected[info[i].group] == 0){
			num_of_selected[info[i].group]++;
			total++;
			printf("%d\n",info[i].id);
		}
	}
}

int main(){

	int N;

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		for(int i = 1; i<= 1000; i++)num_of_selected[i] = 0;

		func(N);
	}

	return 0;
}