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 <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;

#define rep(i, j) for(int i= 0; i < j;i++)
#define all(i) i.begin(), i.end()

struct team { int num, ac, time; };

// t0<t1
bool compare(team &t0, team &t1)
{
	if (t0.ac == t1.ac) 
	{
		if (t0.time == t1.time){ return t0.num < t1.num; }
		return t0.time > t1.time; 
	}
	return t0.ac < t1.ac;
}
int main()
{
	int M, T, P, R;
	while (cin >> M >> T >> P >> R && (M != 0 && T != 0))
	{
		vector<int> m(R, 0), t(R, 0), p(R, 0), j(R, 0);
		vector<team> dat(T + 10);
		vector<vector<int>> wa(T + 10, vector<int>(P + 10, 0));
		rep(i, R)
		{
			int tmp[4] = { 0 };
			cin >> tmp[0] >> tmp[1] >> tmp[2] >> tmp[3];
			if (tmp[3] > 0) { wa[tmp[1]][tmp[2]] += 20; }
			else if(tmp[3] == 0)
			{
				dat[tmp[1]].time += tmp[0] + wa[tmp[1]][tmp[2]];
				dat[tmp[1]].ac += 1;
				dat[tmp[1]].num = tmp[1];
			}
		}
		rep(i, T + 1) { dat[i].num = i; }
		sort(dat.rbegin(), dat.rend(), compare);
		rep(i, T)
		{
			if (i == T - 1){ printf("%d\n", dat[i].num); }
			else if(dat[i].time == dat[i+1].time && i != T - 1){ printf("%d=", dat[i].num); }
			else{ printf("%d,", dat[i].num); }
		}
	}
}

C++: #include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
#include<cctype>

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VII;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int M, T, P, R;

struct Score {
	Score() {
		count = 0;
		time = 0;
	}
	int team;
	int count;
	int time;

	bool operator < (const Score& right) const {
		if (count != right.count) {
			return count > right.count;
		}
		if (time != right.time) {
			return time < right.time;
		}
		return team > right.team;
	}
};

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	while (1) {
		cin >> M >> T >> P >> R;
		if (M == 0 && T == 0 && P == 0 && R == 0) break;
		vector<Score> score(T);
		VII pena(T, VI(P, 0));
		rep (i, T) {
			score[i].team = i;
		}
		rep (i, R) {
			int m, t, p, f;
			cin >> m >> t >> p >> f;
			if (f != 0) {
				pena[t - 1][p - 1] += 20;
			} else {
				score[t - 1].count++;
				score[t - 1].time += m + pena[t - 1][p - 1];
			}
		}
		sort(all(score));
		rep (i, score.size()) {
			if (i != 0) {
				cout << (score[i - 1].count == score[i].count && score[i - 1].time == score[i].time? '=' : ',');
			}
			cout << score[i].team + 1;
		}
		cout << endl;
	}
	return 0;
}

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

const int MAX_T=51,MAX_P=11;

int M,T,P,R,m,t,p,r;
vector<vector<int>> result(MAX_T,vector<int>(3));
vector<vector<int>> penalty(MAX_T,vector<int>(MAX_P));

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> M >> T >> P >> R,M){
        for (int i=0;i<T;++i){
            result[i][0]=result[i][1]=0,result[i][2]=i+1;
            for (int j=0;j<P;++j) penalty[i][j]=0;
        }
        for (;R--;){
            cin >> m >> t >> p >> r; --t,--p;
            if (r) ++penalty[t][p];
            else {
                ++result[t][0];
                result[t][1]-=m+penalty[t][p]*20;
            }
        }
        sort(result.begin(),result.begin()+T);
        reverse(result.begin(),result.begin()+T);
        for (int i=0;i<T;++i){
            if (i) cout << (result[i][0]==result[i-1][0]&&result[i][1]==result[i-1][1]?'=':',');
            cout << result[i][2];
        }
        cout << '\n';
    }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct data_t {
	int ID;
	int time;
	int ac;

	bool operator<(const data_t& right) const {
		if (ac == right.ac) {
			if (time == right.time) {
				return (ID > right.ID);
			}
			else {
				return (time < right.time);
			}
		}
		else {
			return (ac > right.ac);
		}
	}
};

int main(void) {
	int M,T,P,R;
	while (cin >> M >> T >> P >> R, M) {
		vector<data_t> data(T);
		for (int i = 0; i < T; ++i) {
			data[i].ID = i+1;
			data[i].time = 0;
			data[i].ac = 0;
		}

		int m,t,p,judge;
		vector< vector<int> > wrong(T,vector<int>(P,0));
		for (int i = 0; i < R; ++i) {
			cin >> m >> t >> p >> judge;
			if (judge != 0) {
				++wrong[t-1][p-1];
			}
			else {
				++data[t-1].ac;
				data[t-1].time += m + (20 * wrong[t-1][p-1]);
			}
		}
		sort(data.begin(),data.end());
		for (int i = 0; i < T; ++i) {
			cout << data[i].ID;
			if (i < T-1) {
				if (data[i].ac == data[i+1].ac && data[i].time == data[i+1].time) {
					cout << "=";
				}
				else {
					cout << ",";
				}
			}
		}
		cout << endl;
	}
	return 0;
}