typedef struct{int I,U,A,P;}Team;
M(Team*a,Team*b){
	if(a->A!=b->A)return b->A-a->A;
	if(a->P!=b->P)return a->P-b->P;
	return a->I-b->I;
}
Team t[300];
w[1001],W;
main(n){
	int i;
	for(;scanf("%d",&n)*n;){
		for(i=n;i--;)
			scanf("%d%d%d%d",&t[i].I,&t[i].U,&t[i].A,&t[i].P);
		qsort(t,n,sizeof(*t),M);
		memset(w,0,sizeof(w));
		W=0;
		for(i=0;i<n;i++){
			if(W<10&&w[t[i].U]<3||W<20&&w[t[i].U]<2||W<26&&w[t[i].U]<1){
				printf("%d\n",t[i].I);
				w[t[i].U]++;
				W++;
			}
		}
	}
}