#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cstdio>

using namespace std;

typedef pair<int, pair<int, pair<int, int> > > data;

#define f first
#define s second
#define ID s.s.f
#define AF s.s.s
#define SL f
#define PN s.f

#define REP(i,n) for(int i=0; i<(int)(n); i++)


int getInt(){
  int ret; scanf("%d", &ret);
  return ret;
}

int main(){
  while(int n = getInt()){
    vector<data> v(n);

    REP(i, n){
      v[i].ID = -getInt();
      v[i].AF = getInt();
      v[i].SL = getInt();
      v[i].PN = -getInt();
    }

    sort(v.rbegin(), v.rend());

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

    for(int i = 0; i < n; i++){
      int id = -v[i].ID;
      int af = v[i].AF;

      if(all < 10){
	if(cnt[af] < 3){
	  cnt[af]++;
	  cout << id << endl;
	  all++;
	}
      }else if(all < 20){
	if(cnt[af] < 2){
	  cnt[af]++;
	  cout << id << endl;
	  all++;
	}
      }else if(all < 26){
	if(cnt[af] < 1){
	  cnt[af]++;
	  cout << id << endl;
	  all++;
	}
      }
    }
  }
  return 0;
}