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 <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)

int main()
{
    int m,t,p,j;
    while(cin>>m>>t>>p>>j,m||t||p||j){
        vector<pair<pair<int,int>,int> >team(t);
        REP(i,t)team[i].second=-i-1;
        vector<vector<int> >pro(t,vector<int>(p,0));
        int a,b,c,d;
        REP(i,j){
            cin>>a>>b>>c>>d;b--;c--;
            if(d) pro[b][c]++;
            else {
                team[b].first.first--;
                team[b].first.second+=a+pro[b][c]*20;
            }
            
        }
        sort(team.begin(),team.end());
        cout<<-team[0].second;
        rep(i,1,t) cout<<(team[i].first==team[i-1].first?"=":",")<<-team[i].second;cout<<endl;
    }
}

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

struct Team
{
    int name, ca, time;
    int wa[11];
};

void swap( Team& a, Team& b );
void bubbleSort( Team* t, int x, int k );

int main()
{
    int m, t, p, r;
    int a, b, c, d;
    Team team[51];

    while( cin >> m >> t >> p >> r )
    {
        if( m + t + p + r == 0 )
            break;

        for( int i = 0; i < 51; i++ )
        {
            team[i].name = i;
            team[i].ca = 0;
            team[i].time = 0;
            for( int j = 0; j < 11; j++ )
                team[i].wa[j] = 0;
        }
        
        for( int i = 0; i < r; i++ )
        {
            cin >> a >> b >> c >> d;
            if( d == 0 )
            {
                team[b].ca++;
                team[b].time += a + team[b].wa[c] * 20;
            }
            else
                team[b].wa[c]++;
        }

        bubbleSort( team, t, 1 );
        bubbleSort( team, t, 0 );
        bubbleSort( team, t, 2 );

        for( int i = 1; i <= t - 1; i++ )
        {
            cout << team[i].name;
            if( team[i].ca > team[i+1].ca )
                cout << ",";
            else
            {
                if( team[i].time < team[i+1].time )
                    cout << ",";
                else
                    cout << "=";
            }
        }
        cout << team[t].name << endl;
    }
    return 0;
}

void swap( Team& a, Team& b )
{
    Team t = a;
    a = b;
    b = t;
}

void bubbleSort( Team* t, int x, int k )
{
    for( int i = 1; i <= x; i++ )
        for( int j = x; j >= 1 + i; j-- )
        {
            if( t[j].ca > t[j-1].ca && k == 1 )
                swap( t[j], t[j-1] );
            if( t[j].ca == t[j-1].ca && !k && t[j].time < t[j-1].time )
                swap( t[j], t[j-1] );
            if( t[j].ca == t[j-1].ca && k == 2 && t[j].time == t[j-1].time && t[j].name > t[j-1].name )
                swap( t[j], t[j-1] );
        }
}

C++: #include <bits/stdc++.h>
using namespace std;

int main(void){
    int M,T,P,R,m,t,p,j;

    while(cin>>M>>T>>P>>R, M|T|P|R){
        int cnt[51]={};
        int time[51]={};
        int penalty[51][11]={};
        int s[51]={};

        /*????????¨??????????????£????¨????*/
        while(R--){
            cin>>m>>t>>p>>j;
            if(j==0){
                ++cnt[t];
                time[t] += m+penalty[t][p];
            }
            else penalty[t][p]+=20;
        }

        /*???????????¨??????*/
        for(t=1;t<=T;t++)s[t]=t;

        /*??????????????????*/
        for(int a=1;a<T;a++){
            for(int b=T;b>a;b--){
                if(cnt[s[b]]<cnt[s[b-1]]
                   ||(cnt[s[b]]==cnt[s[b-1]] && time[s[b]]>time[s[b-1]])
                   ||(cnt[s[b]]==cnt[s[b-1]] && time[s[b]]==time[s[b-1]] && s[b]<s[b-1]))
                    swap(s[b],s[b-1]);
            }
        }

        /*??????????????????????????????*/
        for(t=T;t>=1;t--){
            cout<<s[t];
            if(t==1)break;
            if(cnt[s[t]]==cnt[s[t-1]] && time[s[t]]==time[s[t-1]])cout<<"=";
            else cout<<",";
        }
        cout<<endl;

    }
    return 0;
}