#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

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

int main(void){
  int n,id,u,a,p;
  while(cin>>n){
    if(n==0) break;
    vector<pair<PII,int> > data;
    map<int,int> t;
    int team[1001]={0};
    REP(i,n){
      cin>>id>>u>>a>>p;
      t[id] = u;
      data.push_back(pair<PII,int>(PII(-a,p),id));
    }
    sort(data.begin(),data.end());
    int select=0;
    REP(i,data.size()){
      pair<PII,int> d = data[i];
      int id = d.second;
      int univ = t[id];
      int count = team[univ]; 
      if((select<10&&count<3)
          ||(select<20&&count<2)
          ||(select<26&&count<1)){
        team[univ]++;
        select++;
        cout<<id<<endl;
      }
    }
  }
  return 0;
}