#include<bits/stdc++.h>
#define int long long
using namespace std;
 
signed main(){
int a;
while(cin>>a,a){
    multimap<int,int>s;
    for(int b=0;b<a;b++){
	int c,d,e,f;
	scanf("%lld%lld%lld%lld",&c,&d,&e,&f);
	s.insert(pair<int,int>(-e*10000000000+f*10000-c,d));
	}
	map<int,int>k;
	int sum=0;
	for(auto u=s.begin();u!=s.end()&&sum<26;u++){
	    if(sum<10){
		if(k[u->second]<3){printf("%lld\n",abs((u->first)%10000));k[u->second]++;sum++;}
		}
		else if(sum<20){if(k[u->second]<2){printf("%lld\n",abs(u->first%10000));k[u->second]++;sum++;}}
		else if(k[u->second]==0){printf("%lld\n",abs(u->first%10000));k[u->second]++;sum++;}
	    }
    }
}