Go: package main

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

func main() {
	io := NewIo()
	defer io.Flush()
	for {
		M, T, P, R := io.NextInt(), io.NextInt(), io.NextInt(), io.NextInt()
		if M == 0 {
			break
		}
		score := make([]struct{ num, time, index int }, T)
		submit := make([][]int, T)
		for i := 0; i < T; i++ {
			score[i].index = i + 1
			submit[i] = make([]int, P)
		}

		for i := 0; i < R; i++ {
			m, t, p, j := io.NextInt(), io.NextInt()-1, io.NextInt()-1, io.NextInt()
			if j == 0 {
				score[t].num++
				score[t].time += submit[t][p]*20 + m
			} else {
				submit[t][p]++
			}
		}
		sort.SliceStable(score, func(i, j int) bool {
			return score[i].num < score[j].num || score[i].num == score[j].num && score[i].time > score[j].time
		})

		for i := T - 1; i > 0; i-- {
			io.Printf("%d", score[i].index)
			if score[i].num == score[i-1].num && score[i].time == score[i-1].time {
				io.Printf("=")
			} else {
				io.Printf(",")
			}
		}
		io.Println(score[0].index)
	}
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double PI = 3.14159265358979;
const double E = 2.718281828459045;
const double root2 = sqrt(2);
typedef pair<int, int> P;
typedef unsigned int ui;
int main() {
	int m, t, p, r;
	while (cin >> m >> t >> p >> r) {
		if (m == 0)break;
		int score[51] = {}; int pena[51] = {}; int wa[51][11];
		for (int i = 0; i < 51; i++) {
			for (int j = 0; j < 11; j++) {
				wa[i][j] = 0;
			}
		}
		int a, b, c, d;
		for (int i = 0; i < r; i++) {
			cin >> a >> b >> c >> d;
			if (d == 0) {
				score[b]++;
				pena[b] += a + 20 * wa[b][c];
			}
			else {
				wa[b][c]++;
			}
		}
		int memo; int used[51] = {};
		for (int i = 1; i <= t; i++) {
			int chk=-1;
			for (int j = 1; j <= t; j++) {
				if (used[j] == 0) {
					if (chk == -1)chk = j;
					else if (score[j] > score[chk] || (score[j] == score[chk] && pena[j] < pena[chk]) || (score[j] == score[chk] && pena[j] == pena[chk] && j > chk)) {
						chk = j;
					}
				}
			}
			if (i == 1) {
				cout << chk;
			}
			else {
				if (score[chk] == score[memo] && pena[chk] == pena[memo]) {
					cout << "=" << chk;
				}
				else cout << "," << chk;

			}
			used[chk] = 1; memo = chk;
		}
		cout << endl;
	}
	return 0;
}

C++: //(各チーム,各問題)ごとに(正解問題,時間)2つのようそを持っておくと簡単。
#include<iostream>
#include<stdlib.h>
using namespace std;
#define rep(i,N) for(i=0;i<N;i++)

int M,T,P,R;
int m,t,p,j;

struct TEAM{
	int sac;
	int stime;
	int id;
	int ac[10];
	int time[10];
}team[50],syukei_team[50];

int compare( const void *s1,const void *s2 ){
	int t1 = ((TEAM*)s2)->sac - ((TEAM*)s1)->sac;
	int t2 = ((TEAM*)s1)->stime - ((TEAM*)s2)->stime;
	int t3 = ((TEAM*)s2)->id - ((TEAM*)s1)->id;
	if( t1 )
		return t1;
	if( t2 )
		return t2;
	return t3;
}

int main(){
	int y,x;
	while( cin >> M >> T >> P >> R ){
		if(!M)break;
		rep(y,T){
			rep(x,P){
				team[y].ac[x] = 0;
				team[y].time[x] = 0;
			}
			syukei_team[y].sac = 0;
			syukei_team[y].stime = 0;
			syukei_team[y].id = y+1;
		}
		rep(y,R){
			cin >> m >> t >> p >> j;
			t--;
			p--;
			if( j == 0 ){
				team[t].ac[p] = 1;
				team[t].time[p] += m;
			}
			else{
				team[t].time[p] += 20;
			}
		}
		rep(y,T){
			rep(x,P){
				if( team[y].ac[x] == 1 ){
					syukei_team[y].stime += team[y].time[x];
					syukei_team[y].sac++;
				}
			}
		}
		qsort( syukei_team, T, sizeof(syukei_team[0]), compare );
		
		rep(y,T){
			cout << syukei_team[y].id;
			if( y < T-1 ){
				if( syukei_team[y].sac == syukei_team[y+1].sac && syukei_team[y].stime == syukei_team[y+1].stime ){
					cout << "=";
				}
				else{
					cout << ",";
				}
			}
			else{
				cout << endl;
			}
			//printf(" team=%d ac=%d time=%d\n",syukei_team[y].id,syukei_team[y].sac,syukei_team[y].stime);
		}
	}
	return 0;
}

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

struct Team{
	vector<bool> is_solve;
	vector<int> WA;
	int team_id, time, solved;
	Team(){}
	Team(int P, int id){
		is_solve = vector<bool>(P, false);
		WA = vector<int>(P, 0);
		team_id = id;
		time = 0;
		solved = 0;
	}
};
bool operator<(const Team &a, const Team &b){
	if( a.solved == b.solved ){
		if( a.time == b.time ){
			return a.team_id > b.team_id;
		}
		return a.time < b.time;
	}
	return a.solved > b.solved;
}
bool operator==(const Team &a, const Team &b){
	return a.solved == b.solved && a.time == b.time;
}

int main(){
	int M, T, P, R;
	while( cin >> M >> T >> P >> R, M ){
		vector<Team> v;
		for(int i = 0; i < T; i++){
			v.push_back( Team(P, i) );
		}
		
		for(int i = 0; i < R; i++){
			int m, t, p, j;
			cin >> m >> t >> p >> j;
			t--; p--;
			if( j == 0 ){ // Correct Answer
				for(int k = 0; k < v.size(); k++){
					if( v[k].team_id == t ){
						v[k].is_solve[p] = true;
						v[k].solved++;
						v[k].time += m;
						v[k].time += 20 * v[k].WA[p];
						break;
					}
				}
			}else{ // Wrong Answer
				for(int k = 0; k < v.size(); k++){
					if( v[k].team_id == t ){
						v[k].WA[p]++;
						break;
					}
				}
			}
		}
		
		sort(v.begin(), v.end());
		for(int i = 0; i < v.size(); i++){
			if( i ){
				bool flag = (v[i-1] == v[i]);
				cout << (flag? "=" : ",");
			}
			cout << v[i].team_id + 1;
		}
		cout << endl;
	}
}