//https://onlinejudge.u-aizu.ac.jp/challenges/sources/UOA/PCKWU/1043

#include <bits/stdc++.h>

using namespace std;

struct Team {
    int id;
    int univ;
    int ac;
    int penalty;

    bool operator<(const Team inst) const {
        if (ac != inst.ac) {
            return ac > inst.ac;
        } else if (penalty != inst.penalty) {
            return penalty < inst.penalty;
        } else {
            return id < inst.id;
        }
    }
};

int main() {
    int n;

    while (true) {
        cin >> n;
        if (n == 0) return 0;

        vector<Team> team(n);
        for (int i = 0; i < n; ++i) {
            cin >> team[i].id >> team[i].univ >> team[i].ac >> team[i].penalty;
        }
        sort(team.begin(), team.end());

        int selected = 0;
        int same[1010] = {};
        for (int i = 0; i < n; ++i) {
            if ((selected < 10 and same[team[i].univ] < 3) or
                (selected < 20 and same[team[i].univ] < 2) or
                (selected < 26 and same[team[i].univ] == 0)) {
                cout << team[i].id << endl;
                selected++;
                same[team[i].univ]++;
            }
        }
    }
}

/*
 *
 */
