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 <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int m, t, p, r;
    while (cin >> m >> t >> p >> r && m){
        vector<pair<P, int> > a(t);
        REP(i,t) a[i].second = -(i+1);
        int w[50][10] = {};
        while (r--){
            int x, y, z, j;
            cin >> z >> x >> y >> j;
            x--;
            y--;
            if (j != 0){
                w[x][y]++;
            }else{
                a[x].first.first--;
                a[x].first.second += z + 20 * w[x][y];
            }
        }
        sort(a.begin(), a.end());
        cout << -a[0].second;
        FOR(i,1,t-1){
            if (a[i].first == a[i-1].first) cout << "=";
            else cout << ",";
            cout << -a[i].second;
        }
        cout << endl;
    }

    return 0;
}

C++: #include<bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;
int main(){
    int M,T,P,R;
    while(1){
        cin>>M>>T>>P>>R;
        if(M==0 && T==0 && P==0 && R==0) break;
        int m,t,p,j;
        bool judge[51][11]={};
        int pena[51][11]={};
        int time[51]={};
        int rep[51]={};
        pair<int,int> ans[51];
        for(int i=0;i<R;i++){
            cin>>m>>t>>p>>j;
            if(j==0){
                judge[t][p]=true;
                time[t]+=m;
                rep[t]++;
            }
            else pena[t][p]++;
        }
        
        for(int i=1;i<=T;i++) ans[i].S=i,ans[i].F=rep[i];
        
        for(int i=1;i<=T;i++)
            for(int j=1;j<=P;j++) if(judge[i][j]) time[i]+=pena[i][j]*20;
        
        sort(ans+1,ans+1+T);
        reverse(ans+1,ans+1+T);
        
        bool flag=true;
        while(flag){
            flag=false;
            for(int i=1;i<T;i++){
                if(ans[i].F==ans[i+1].F && time[ans[i].S] > time[ans[i+1].S]){
                    swap(ans[i],ans[i+1]);
                    flag=true;
                }
            }
        }
        
        for(int i=1;i<T;i++){
            cout<<ans[i].S;
            if(ans[i].F==ans[i+1].F && time[ans[i].S]==time[ans[i+1].S]) cout<<"=";
            else cout<<",";
        }
        cout<<ans[T].S<<endl;
    }
    return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<set>

using namespace std;

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

typedef pair<int,int> pii;
typedef pair<pii,int> piii;

piii mk(int a, int b, int c){
	return piii(pii(a,b), c);
}

int main(){
	A:;
	
	int teemwrong[55][11]={0};
	int teemcost[55]={0};
	int teemac[55]={0};
	
	int M,T,P,R;
	cin>>M>>T>>P>>R;
	
	if(M==0&&T==0&&R==0&&P==0)return 0;
	
	rep(i,R){
		int m,t,p,j;
		cin>>m>>t>>p>>j;
		
		if(j==0){
			teemac[t]++;
			teemcost[t]+=m+teemwrong[t][p]*20;
		}else{
			teemwrong[t][p]++;
		}
	}
	
	vector<piii> rank;
	reps(i,1,T+1){
		rank.push_back(mk(teemac[i], -teemcost[i], i));
	}
	
	sort(rank.begin(),rank.end());
	reverse(rank.begin(),rank.end());
	
	rep(i,rank.size()){
		if(i!=0){
			if(rank[i].first==rank[i-1].first)printf("=");
			else printf(",");
		}
		printf("%d",rank[i].second);
	}puts("");
	
	
	goto A;
}