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 <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <sstream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <ctime>
#include <cmath>
#include <cassert>
#include <limits>
#include <functional>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(int)(n);++(i))

typedef struct {
    int id, ac, time;
    vector<int> logTime;
} data;

bool comp(data& a, data& b) {
    if (a.ac != b.ac)
        return a.ac > b.ac;
    if (a.time != b.time)
        return a.time < b.time;
    return a.id > b.id;
}


int main() {
    int M, T, P, R;
    while (true) {
        cin >> M >> T >> P >> R;
        if (!M && !T && !P && !R) break;
        vector<data> team(T);
        rep(i, T) {
            team[i].id = i+1;
            team[i].ac = 0;
            team[i].time = 0;
            rep(j, P) {
                team[i].logTime.push_back(0);
            }
        }
        rep(i, R) {
            int m, t, p, j; cin >> m >> t >> p >> j; t--; p--;
            if (!j) {
                team[t].ac++;
                team[t].time += m + team[t].logTime[p];
            } else {
                team[t].logTime[p] += 20;
            }
        }
        sort(team.begin(), team.end(), comp);
        rep(i, team.size()) {
            if (i) {
                if (team[i-1].ac == team[i].ac && team[i-1].time == team[i].time)
                    cout << "=";
                else
                    cout << ",";
            }
            cout << team[i].id;
        }
        cout << endl;
    }
}

C++: //(各チーム,各問題)ごとに(正解問題,時間)2つのようそを持っておくと簡単。
#include<iostream>
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 Score{
	int team_num;
	int ac=0;
	int time=0;
	int miss_tmp[20]={0};
	int miss_sum=0;
};

bool asc(const Score& left, const Score& right) {
	return left.ac == right.ac ? (left.time == right.time ?  left.team_num > right.team_num : left.time < right.time) :
		   left.ac > right.ac;
}

int main(){
	while(1){
		int M, T, P, R; cin>>M>>T>>P>>R;
		if(!M && !T && !P && !R) break;
		vector <Score> score(T);
		for(int i=0; i<T; i++) score[i].team_num = i;
		int m, t, p, j;
		for(int i=0; i<R; i++){
			cin>>m>>t>>p>>j;
			t=t-1;//0オリジン
			if(j == 0){
				score[t].ac++;
				if(score[t].miss_tmp != 0){
					score[t].miss_sum += score[t].miss_tmp[p];
				}
				score[t].time += m+(score[t].miss_tmp[p]*20);
			} else{
				score[t].miss_tmp[p]++;
			}
		}
		sort(score.begin(), score.end(), asc);
		for(int i=0; i<T; i++){
			cout << score[i].team_num+1;
			if(i!=T-1){
				if(score[i].ac == score[i+1].ac && score[i].time == score[i+1].time) cout << "=";
				else cout << ",";
			}
		}
		cout << endl;
	}
	return 0;
}