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 <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0; i < (n); i++)
#define all(c) (c).begin(), (c).end()

struct Team {
  int i, u, a, p;
};

// team1 < team2 ならtrueを返す関数
bool comp(Team team1, Team team2) {
  if (team1.a != team2.a) return team1.a > team2.a;
  if (team1.p != team2.p) return team1.p < team2.p;
  return team1.i < team2.i;
}

// 選抜基準を満たしているならtrue
bool can_qualify(int num_u, int num_qualified) {
  if (num_qualified < 10) return num_u < 3;
  if (num_qualified < 20) return num_u < 2;
  if (num_qualified < 26) return num_u < 1;
  return false;
}

int main() {
  int n;
  while(cin >> n, n) {
    vector<Team> teams(n);
    rep(i, n) {
      cin >> teams[i].i >> teams[i].u >> teams[i].a >> teams[i].p;
    }
    sort(all(teams), comp);

    const int MAX_U = 1001;
    int num_qualified = 0; // 選抜された数
    vector<int> num_u_qualified(MAX_U, 0); // 所属毎の選抜された数
    rep(i, n) {
      if (can_qualify(num_u_qualified[teams[i].u], num_qualified)) {
        num_qualified++;
        num_u_qualified[teams[i].u]++;
        cout << teams[i].i << endl;
      }
    }
  }
  return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

struct st {
	int i, u, a, p;
};
st s[300];
int cnt[1001];
int main() {
	int n;
	while (scanf("%d", &n), n) {
		rep(j, n) {
			int i, u, a, p; scanf("%d%d%d%d", &i, &u, &a, &p);
			s[j] = { i,u,a,p };
		}
		sort(s, s + n, [](st a, st b) {
			if (a.a != b.a)return a.a > b.a;
			if (a.p != b.p)return a.p < b.p;
			return a.i < b.i;
		});
		memset(cnt, 0, sizeof(cnt));
		int k = 0;
		rep(i, n) {
			if (k < 10) {
				if (cnt[s[i].u] < 3) {
					cnt[s[i].u]++; k++;
					printf("%d\n", s[i].i);
				}
			}
			else if (k < 20) {
				if (cnt[s[i].u] < 2) {
					cnt[s[i].u]++; k++;
					printf("%d\n", s[i].i);
				}
			}
			else if (k < 26) {
				if (!cnt[s[i].u]) {
					cnt[s[i].u]++; k++;
					printf("%d\n", s[i].i);
				}
			}
			else break;
		}
	}
}

C++: //https://onlinejudge.u-aizu.ac.jp/challenges/sources/UOA/PCKWU/1043

#include <bits/stdc++.h>

using namespace std;

struct Team {
    int id;
    int univ;
    int ac;
    int penalty;

    bool operator<(const Team inst) const {
        if (ac != inst.ac) {
            return ac > inst.ac;
        } else if (penalty != inst.penalty) {
            return penalty < inst.penalty;
        } else {
            return id < inst.id;
        }
    }
};

int main() {
    int n;

    while (true) {
        cin >> n;
        if (n == 0) return 0;

        vector<Team> team(n);
        for (int i = 0; i < n; ++i) {
            cin >> team[i].id >> team[i].univ >> team[i].ac >> team[i].penalty;
        }
        sort(team.begin(), team.end());

        int selected = 0;
        int same[1010] = {};
        for (int i = 0; i < n; ++i) {
            if ((selected < 10 and same[team[i].univ] < 3) or
                (selected < 20 and same[team[i].univ] < 2) or
                (selected < 26 and same[team[i].univ] == 0)) {
                cout << team[i].id << endl;
                selected++;
                same[team[i].univ]++;
            }
        }
    }
}

/*
 *
 */

C++: #include <bits/stdc++.h>

using namespace std;

int main(){
    int n;
    while(cin >> n, n){
        vector<pair<pair<int, int>, int>> v;
        int m[1010], uni[1010];
        fill(uni, uni+1010, 0);
        for(int i=0; i < n; i++){
            int id, u, a, p;
            cin >> id >> u >> a >> p;
            m[i] = u;
            v.push_back(make_pair(make_pair(-a, p), id));
        }
        sort(v.begin(), v.end());
        int count = 0;
        for(int i=0; i< v.size(); i++){
            if((count < 10 && uni[m[i]] < 3) || (count < 20 && uni[m[i]] < 2) || (count < 26 && uni[m[i]] < 1)){cout << v[i].second << endl; uni[m[i]]++; count++;}
        }
    }
}