#include <iostream>
#include <vector>
using namespace std;
struct po{
  int I,U,A,P,sum;
};

int main (){
  int n;

  while(1) {
  cin >> n;
  if (n == 0) break;
  vector <po> D;
  D.resize(n);
  for(int i=0;i<n;i++) cin >> D[i].I >> D[i].U >> D[i].A >> D[i].P;

  po t;
  for(int i=0;i<n;i++) {
    for(int j=n-1;j>i;j--){
      if(D[j].A > D[j-1].A){
	t = D[j];
	D[j] = D[j-1];
	D[j-1] = t;
      }
      if(D[j].A == D[j-1].A) {
	if(D[j].P < D[j-1].P) {
	  t = D[j];
	  D[j] = D[j-1];
	  D[j-1] = t;
	}
	if(D[j].P == D[j-1].P && D[j].U <= D[j-1].U) {
	  t  = D[j];
	  D[j] = D[j-1];
	  D[j-1] = t;
	}
      }
    }
  }

  int goukei = 0;
  int flg[1001] = {};

  for(int i=0;i<n;i++) {
    if(goukei < 10 && flg[D[i].U] < 3) {
      cout << D[i].I << endl;
      flg[D[i].U]++;
      goukei++;
    }
    else if(goukei < 20 && flg[D[i].U]< 2) {
      cout << D[i].I << endl;
      flg[D[i].U]++;
      goukei++;
    }
    else if(goukei < 26 && flg[D[i].U] == 0) {
      cout << D[i].I << endl;
      flg[D[i].U]++;
      goukei++;
    }
  }

  }

  return 0;
}