// Aizu Vol-10 1043: Selecting Teams Advanced to Regional
// 2017.8.18 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct { int id, u, a, p; } TEAM;
TEAM team[302];
int affi[1002], total;

int cmp(TEAM *a, TEAM *b)
{
	int d;
	if ((d = b->a - a->a) != 0) return d;
	if ((d = a->p - b->p) != 0) return d;
	return a->id - b->id;
}

int main()
{
	int n, i, u;

	while (scanf("%d", &n) && n) {
		for (i = 0; i < n; i++)
			scanf("%d%d%d%d", &(team[i].id), &(team[i].u), &(team[i].a), &(team[i].p));
		qsort(team, n, sizeof(TEAM), cmp);
		total = 0; memset(affi, 0, sizeof(affi));
		for (i = 0; i < n; i++) {
			u = team[i].u;
			if (total < 10 && affi[u] < 3) goto Fin;
			if (total < 20 && affi[u] < 2) goto Fin;
			if (total < 26 && affi[u] < 1) goto Fin;
			continue;
Fin:		printf("%d\n", team[i].id);
			total++, affi[u]++;
		}
	}
	return 0;
}