#include<cstdio>
#include<cstring>
#include<map>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define F first
#define S second
typedef pair<int,int> P;
typedef pair<P,int> PP;
vector<PP> U[301]; 
vector<int> ans;
int N;
int m;
int ID[301];
int id_check(int id){
  for(int i=0;i<m;i++){
    if(ID[i]==id) return i;
  }
  ID[m]=id;
  m++;
  return m-1;
}
int main(){
  while(1){
    scanf("%d",&N);
    if(!N) break;
    m=0;
    memset(ID,0,sizeof(ID));
    ans.clear();
    for(int i=0;i<N;i++){
      int I,u,a,p;
      scanf("%d %d %d %d",&I,&u,&a,&p);
      U[id_check(u)].push_back(PP(P(a,-p),-I));
    }
    for(int i=0;i<m;i++){
      sort(U[i].rbegin(),U[i].rend());
    }
    int id[301]={};
    for(int i=0;i<26;i++){
      int ind=-1;
      for(int j=0;j<m;j++){
	if(id[j]>=(int)U[j].size()) continue;
	if(i<10){
	  if(id[j]>=3) continue;
	} else if(i<20){
	  if(id[j]>=2) continue;
	} else if(i<26){
	  if(id[j]>=1) continue;
	}
	if(ind==-1) ind=j;
	if(U[j][id[j]] > U[ind][id[ind]]) ind = j;
      }
      if(ind==-1) break;
      ans.push_back(-U[ind][id[ind]].S);
      id[ind]++;
    }
    for(int i=0;i<ans.size();i++)
      printf("%d\n",ans[i]);

    for(int i=0;i<m;i++) U[i].clear();
  }
}