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>
using namespace std;

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

int main()
{
	for(int n;cin>>n && n;){
		vvi a(n,vi(4));
		rep(i,n) rep(j,4) cin>>a[i][j];
		sort(all(a),[](const vi& a,const vi& b){
			if(a[2]!=b[2]) return a[2]>b[2];
			if(a[3]!=b[3]) return a[3]<b[3];
			return a[0]<b[0];
		});
		
		map<int,int> f;
		vi res;
		for(int i=0;i<n && res.size()<26;i++)
			if(res.size()<10){
				if(f[a[i][1]]<3){
					res.push_back(a[i][0]);
					f[a[i][1]]++;
				}
			}
			else if(res.size()<20){
				if(f[a[i][1]]<2){
					res.push_back(a[i][0]);
					f[a[i][1]]++;
				}
			}
			else if(res.size()<26){
				if(f[a[i][1]]==0){
					res.push_back(a[i][0]);
					f[a[i][1]]++;
				}
			}
		for(int x:res) cout<<x<<endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <queue>
using namespace std;

class Team {
public:
    int id, belong, correct, penalty;
};

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }

        vector<Team> teams(n);
        for (int i = 0; i < n; i++) {
            cin >> teams[i].id >> teams[i].belong >> teams[i].correct >> teams[i].penalty;
        }
        for (int i = 0; i < n - 1; i++) {
            for (int j = n - 1; j > i; j--) {
                if (teams[j - 1].correct < teams[j].correct
                    || (teams[j - 1].correct == teams[j].correct && teams[j - 1].penalty > teams[j].penalty)
                    || (teams[j - 1].correct == teams[j].correct && teams[j - 1].penalty == teams[j].penalty
                        && teams[j - 1].id > teams[j].id)) {
                    swap(teams[j - 1], teams[j]);
                }
            }
        }
        int selected = 0;
        queue<int> selected_i;
        int belongs[20];
        fill_n(belongs, 20, 0);
        for (int i = 0; i < n; i++) {
            if (selected < 10) {
                if (belongs[teams[i].belong] < 3) {
                    selected_i.push(i);
                    belongs[teams[i].belong]++;
                }
            } else if (selected < 20) {
                if (belongs[teams[i].belong] < 2) {
                    selected_i.push(i);
                    belongs[teams[i].belong]++;
                }
            } else if (selected < 26) {
                if (belongs[teams[i].belong] == 0) {
                    selected_i.push(i);
                    belongs[teams[i].belong]++;
                }
            } else {
                break;
            }
        }
        while (selected_i.empty() == false) {
            cout << teams[selected_i.front()].id << endl;
            selected_i.pop();
        }
    }
}

C++: #include <vector>
#include <cstring>
#include <map>
#include <algorithm>
#include <cstdio>
using namespace std;

struct data{
	int id,a,p,b;
	data(){}
	data(int idd,int aa,int pp,int bb){
		id=idd;
		a=aa;
		p=pp;
		b=bb;
	}
	bool operator<(const data& d1)const{
		if(a!=d1.a)return a>d1.a;
		if(p!=d1.p)return p<d1.p;
		return id<d1.id;
	}
};

int n;
data dat[301];
int cnt[1001];
int win[28];
int main(void){
	while(1){
		memset(cnt,0,sizeof(cnt));
		scanf("%d",&n);
		if(n==0)break;
		for(int i=0;i<n;i++){
			scanf("%d %d %d %d",&dat[i].id,&dat[i].b,&dat[i].a,&dat[i].p);
		}
		sort(dat,dat+n);
		int wcnt=0;
		for(int i=0;i<n;i++){
			if(wcnt<10 && cnt[dat[i].b]<3){
				cnt[dat[i].b]++;
				win[wcnt++]=dat[i].id;
			}else if(wcnt<20 && cnt[dat[i].b]<2){
				cnt[dat[i].b]++;
				win[wcnt++]=dat[i].id;
			}else if(wcnt<26 && cnt[dat[i].b]<1){
				cnt[dat[i].b]++;
				win[wcnt++]=dat[i].id;
			}
		}
		for(int i=0;i<wcnt;i++){
			printf("%d\n",win[i]);
		}
	}
	return 0;
}