#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> dP;

const int INF = 100000000;
const double EPS = 1e-10;

int d[100001];
int dsum[100001];

struct team{
	int id;
	int univ;
	int solved;
	int pena;
	bool operator <(const team& other) const{
		if(solved == other.solved){
			if(pena == other.pena){
				return id > other.id;
			}else{
				return pena > other.pena;
			}
		}else{
			return solved < other.solved;
		}
	}
};

int main(){
	while(1){
		int n;
		cin >> n;
		if(!n)break;
		vector<team> v;
		rep(i, n){
			team t;
			cin >> t.id >> t.univ>> t.solved >> t.pena;
			v.push_back(t);
		}
		sort(all(v));
		reverse(all(v));

		int cnt = 0;
		map<int, int> univcnt;

		rep(i, n){
			if(cnt < 10){
				if(univcnt[v[i].univ] < 3){
					cout << v[i].id << endl;
					cnt++;
					univcnt[v[i].univ]++;
				}
			}
			else if(cnt < 20){
				if(univcnt[v[i].univ] < 2){
					cout << v[i].id << endl;
					cnt++;
					univcnt[v[i].univ]++;
				}
			}
			else if(cnt < 26){
				if(univcnt[v[i].univ] < 1){
					cout << v[i].id << endl;
					cnt++;
					univcnt[v[i].univ]++;
				}
			}
		}
	}

	return 0;
}