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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


struct Team
{
	int id, u, a, p;
	void input()
	{
		cin >> id >> u >> a >> p;
	}
};
bool operator<(const Team& a, const Team& b)
{
	return a.a > b.a || a.a == b.a && a.p < b.p
		|| a.a == b.a && a.p == b.p && a.id < b.id;
}
int main()
{
	int n;
	while (cin >> n, n)
	{
		Team team[500];
		rep (i, n)
			team[i].input();
		sort(team, team + n);

		int	select[1024];
		fill_n(select, n, 0);
		int s = 0;
		for (int i = 0; i < n && s < 26; ++i)
		{
			static const int limit[] = { 3, 2, 10000 };
			if (select[team[i].u] < limit[s / 10])
			{
				++s;
				++select[team[i].u];
				printf("%d\n", team[i].id);
			}
		}
	}
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
int x[1000][4], t[1000], n, team, maxn, maxp, maxid, loop; vector<int>p[10000];
int main() {
	while (true) {
		cin >> n;
		memset(t, 0, sizeof(t));
		for (int i = 0; i < 10000; i++) { p[i].clear(); }
		if (!n) { break; }
		for (int i = 0; i < n; i++) {
			cin >> x[i][0] >> x[i][1] >> x[i][2] >> x[i][3];
		}
		team = 0; loop = 0;
		while (loop < n) {
			maxn = 0; maxp = 1000000;
			for (int i = 0; i < n; i++) {
				if (t[i] == 0) {
					if (maxn < x[i][2]) {
						maxn = x[i][2]; maxid = i; maxp = x[i][3];
					}
					else if (maxn == x[i][2] && maxp>x[i][3]) {
						maxp = x[i][3]; maxid = i;
					}
				}
			}
			if (p[x[maxid][1]].size() < 3 && team < 10) {
				goto E;
			}
			if (p[x[maxid][1]].size() < 2 && team < 20) {
				goto E;
			}
			if (p[x[maxid][1]].size() < 1 && team < 26) {
				goto E;
			}
			goto F;
		E:;
			cout << x[maxid][0] << endl;
			p[x[maxid][1]].push_back(maxid);
		F:;
			t[maxid] = 1;
			loop++;
		}
	}
}

C++: #include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define REP(i,a,n) for(int i = a ; i < n ; i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

class T{
public:
  int id,school,ac,p;
  T(){}
  T(int _id,int _school,int _ac,int _p){
    id = _id;
    school = _school;
    ac = _ac;
    p = _p;
  }

  bool operator<(const T &t)const{
    if(ac == t.ac){
      if(p == t.p){
        return id < t.id;
      }
      return p < t.p;
    }
    return ac > t.ac;
  }
};

int n;
T t[302];

void solve(){
  int pass = 0;
  int scCnt[1002];
  vector<int> ans;
  memset(scCnt,0,sizeof(scCnt));
  sort(t,t+n);

  rep(i,n){
    bool flg = false;

    if(pass < 10){
      if(scCnt[t[i].school] < 3){
        flg = true;
      }
    }
    else if(pass < 20){
      if(scCnt[t[i].school] < 2){
        flg = true;
      }
    }
    else if(pass < 26){
      if(scCnt[t[i].school] == 0){
        flg = true;
      }
    }

    if(flg){
      ans.push_back(t[i].id);
      scCnt[t[i].school]++;
      pass++;
    }
  }

  rep(i,ans.size()){
    cout<<ans[i]<<endl;
  }
}

int main(){
  while(cin>>n,n){
    rep(i,n){
      cin>>t[i].id>>t[i].school>>t[i].ac>>t[i].p;
    }
    solve();
  }
}

C++: #include<iostream>
#include<algorithm>

using namespace std;

const int MAX = 301;
const int UMAX = 1001;
typedef pair<int,int> P;

struct team{
  int I,U,A,P;
  bool passed;
};

int UNUM[UMAX],pass,n;
team T[MAX];
P p[3] = {P(10,3),P(20,2),P(26,1)};

void T_sort(){

  for(int i = 0; i < n; i++)
    for(int j = i; j < n; j++)
      if(T[i].A < T[j].A || (T[i].A == T[j].A && T[i].P > T[j].P) ||
	 (T[i].A == T[j].A && T[i].P == T[j].P && T[i].I > T[j].I))
	swap(T[i],T[j]);
}

void solve(){
  
  for(int R = 0; R < 3; R++)
    for(int i = 0; pass < p[R].first && i < n; i++){
      if(T[i].passed == false && UNUM[T[i].U] < p[R].second){
	cout << T[i].I << endl;
	T[i].passed = true;
	UNUM[T[i].U]++;
	pass++;
      }
    }
}

void init(){
  pass = 0;
  fill(UNUM,UNUM+UMAX,0);
}
int main(){
  while(cin >> n && n){
    init();
    for(int i = 0; i < n; i++){
      cin >> T[i].I >> T[i].U >> T[i].A >> T[i].P;
      T[i].passed = false;
    }
    T_sort();
    solve();
  }
  
  return 0;
}