#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

struct team_t {
	int id, univ, accept, penalty;
	team_t(int id, int univ, int accept, int penalty)
		: id(id), univ(univ), accept(accept), penalty(penalty) {}
	bool operator<(const team_t &o) const {
		return 
			accept != o.accept ? 
			    accept > o.accept : 
			    penalty != o.penalty ? 
				    penalty < o.penalty : id < o.id;
	}
};

int main() {
	int n;
	while (cin >> n, n != 0) {
		vector<team_t> teams;
		for (int x = 0; x < n; x++) {
			int i, u, a, p;
			cin >> i >> u >> a >> p;
			teams.push_back(team_t(i, u, a, p));
		}
		sort(teams.begin(), teams.end());
		vector<team_t> selected;
		map<int, int> univ;
		for (int i = 0; i < teams.size(); i++) {
			if (selected.size() < 10 && univ[teams[i].univ] < 3) {
				selected.push_back(teams[i]);
				univ[teams[i].univ]++;
			} else if (selected.size() < 20 && univ[teams[i].univ] < 2) {
				selected.push_back(teams[i]);
				univ[teams[i].univ]++;
			} else if (selected.size() < 26 && univ[teams[i].univ] < 1) {
				selected.push_back(teams[i]);
				univ[teams[i].univ]++;
			}
		}
		for (int i = 0; i < selected.size(); i++) {
			cout << selected[i].id << endl;
		}
	}
	return 0;
}
	