Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	for n := getNextInt(scanner); n > 0; n = getNextInt(scanner) {
		tt := make([]team, n)
		for i := 0; i < n; i++ {
			tt[i].id = getNextInt(scanner)
			tt[i].uni = getNextInt(scanner)
			tt[i].ac = getNextInt(scanner)
			tt[i].pn = getNextInt(scanner)
		}
		sort.SliceStable(tt, func(i, j int) bool {
			if tt[i].ac == tt[j].ac {
				if tt[i].pn == tt[j].pn {
					return tt[i].id < tt[j].id
				}
				return tt[i].pn < tt[j].pn
			}
			return tt[i].ac > tt[j].ac
		})
		cc := make([]int, 100005)
		ans := make([]int, 0)
		for i := 0; i < n; i++ {
			if cc[0] < 10 && cc[tt[i].uni] < 3 {
				cc[0]++
				cc[tt[i].uni]++
				ans = append(ans, tt[i].id)
				continue
			}
			if cc[0] < 20 && cc[tt[i].uni] < 2 {
				cc[0]++
				cc[tt[i].uni]++
				ans = append(ans, tt[i].id)
				continue
			}
			if cc[0] < 26 && cc[tt[i].uni] < 1 {
				cc[0]++
				cc[tt[i].uni]++
				ans = append(ans, tt[i].id)
				continue
			}
		}
		for i := 0; i < len(ans); i++ {
			fmt.Fprintln(writer, ans[i])
		}
	}
}

type team struct {
	id, uni, ac, pn int
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a,c) memset(a,c,sizeof(a))

#define DEBUG(x) cout<<"#x"<<": "<<x<<endl

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll INF = INT_MAX/3;
const ll MOD = 1000000007;
const double EPS = 1e-14;
const int dx[] = {1,0,-1,0} , dy[] = {0,1,0,-1};

map<int,bool> used;
map<int,int> count_t;
map<int,bool> isDecided;
vector<bool> ans;

int main(){
    while(true){
	int n;
	vector< pair< pair<int,int> , pair<int,int> > > t;
	cin >> n;
	if(n==0) break;
	used.clear();
	count_t.clear();
	isDecided.clear();
	REP(i,n){
	    int I,A,U,P;
	    cin >> I >> U >> A >> P;
	    t.PB( MP( MP(-A,P) , MP(I,U) ) );
	    used[I] = false;
	    count_t[U] = false;
	    isDecided[I] = false;
	}
	sort(ALL(t));
	int temp = 0;

	REP(i,n){
	    if(!used[t[i].second.second]){
		used[t[i].second.second] = true;
		count_t[t[i].second.second]++;
		isDecided[t[i].second.first] = true;
		temp++;
	    }
	}

	if(temp < 10){
	    REP(i,n){
		if(!isDecided[t[i].second.first] && count_t[t[i].second.second] < 3){
		    count_t[t[i].second.second]++;
		    isDecided[t[i].second.first] = true;
		    temp++;
		}
	    }
	}


	if(temp < 20){
	    REP(i,n){
		if(!isDecided[t[i].second.first] && count_t[t[i].second.second] < 2){
		    count_t[t[i].second.second]++;
		    isDecided[t[i].second.first] = true;
			temp++;
		}
	    }
	}

	if(temp < 26){
	    REP(i,n){
		if(!isDecided[t[i].second.second] && count_t[t[i].second.second] < 1){
		    count_t[t[i].second.second]++;
		    isDecided[t[i].second.first] = true;
		    temp++;
		}
	    }
	}

	REP(i,n){
	    if(isDecided[t[i].second.first]) cout << t[i].second.first << endl;
	}
    }

    return 0;
}

C++: #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();
  }
}

C++: #include <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;

struct team{
  int i,u,a,p;
  bool operator<(const team& t){
    if(a == t.a && p == t.p) return i < t.i;
    if(a == t.a) return p < t.p;
    return a > t.a;
  }
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  while(cin >> n && n){
    vector<team> T(n);
    map<ll,ll> m;
    rep(i,n){
      cin >> T[i].i >> T[i].u >> T[i].a >> T[i].p;
      m[T[i].u] = 0;
    }
    sort(all(T));
    ll sum = 0;
    rep(i,n){
      if(sum < 10 && m[T[i].u] < 3){
        ++sum;
        cout << T[i].i << endl;
        m[T[i].u]++;
      }
      else if(sum < 20 && m[T[i].u] < 2){
        ++sum;
        cout << T[i].i << endl;
        m[T[i].u]++;
      }
      else if(sum < 26 && m[T[i].u] < 1){
        ++sum;
        cout << T[i].i << endl;
        m[T[i].u]++;
      }
      //     cout << T[i].i << ":" << T[i].u << ":" << T[i].a << ":" << T[i].p << endl;
    }
  }
  return 0;
}