#include <iostream>
#include <map>
#include <algorithm>

using namespace std;

class State{
public:
  int a, b, c, d;
  State(int a = 0, int b = 0, int c = 0, int d = 0)
    : a(a), b(b), c(c), d(d) {}
  bool operator < (const State& s) const {
    if(c == s.c){
      if(d == s.d) return a < s.a;
      return d < s.d;
    }
    return c > s.c;
  }
};

int n;
map<int, int> univ;
State data[300];

int main(){
  while(cin >> n && n){
    univ.clear();
    for(int i=0;i<n;i++){
      cin >> data[i].a >> data[i].b >> data[i].c >> data[i].d;
    }
    sort(data, data+n);
    int cnt = 0;
    for(int i=0;i<n&&cnt<26;i++){
      if(cnt < 10){
        if(univ[data[i].b] < 3){
          cout << data[i].a << endl;
          univ[data[i].b]++;
          cnt++;
        }
      }else if(cnt < 20){
        if(univ[data[i].b] < 2){
          cout << data[i].a << endl;
          univ[data[i].b]++;
          cnt++;
        }
      }else{
        if(univ[data[i].b] < 1){
          cout << data[i].a << endl;
          univ[data[i].b]++;
          cnt++;
        }
      }
    }
  }
}