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 <algorithm>
#include <vector>

using namespace std;

int M, T, P, R;

struct Team {
    int id, penalty[11], score, ans;
    Team() {
        for (int i = 0; i < 11; ++i)
            penalty[i] = 0;
        score = ans = 0;
    }
};

bool cmp(const Team &a, const Team &b)
{
    return (a.ans > b.ans) || (a.ans == b.ans && (a.score < b.score))
        || ((a.ans == b.ans && a.score == b.score && a.id > b.id));
}

int main()
{
    while (cin >> M >> T >> P >> R) {
        if (M + T + P + R == 0)
            break;

        Team team[T];
        for (int i = 0; i < T; ++i)
            team[i].id = i + 1;

        int m, t, p, j;
        for (int i = 0; i < R; ++i) {
            cin >> m >> t >> p >> j;

            --t;
            if (j == 0) { // 正解
                ++team[t].ans;
                team[t].score += m + 20 * team[t].penalty[p];
            }
            else { // 不正解
                ++team[t].penalty[p];
            }
        }

        sort(team, team + T, cmp);

        cout << team[0].id;
        for (int i = 1; i < T; ++i) {
            if (team[i - 1].ans == team[i].ans &&
                team[i - 1].score == team[i].score)
                cout << "=";
            else
                cout << ",";
            cout << team[i].id;
        }
        cout << endl;
    }

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef tuple<int,int,int> Team;
int AC[50][10],WA[50][10];
int main() {
    int  M,T,P,R;
    while(cin>>M>>T>>P>>R,M) {
        memset(AC,-1,sizeof(AC));
        memset(WA,0,sizeof(WA));
        for(int i=0;i<R;i++) {
            int m,t,p,j;
            cin>>m>>t>>p>>j;
            t--;p--;
            if(j==0) {
                AC[t][p]=m;
            }else {
                WA[t][p]++;
            }
        }
        vector<Team> v;
        for(int i=0;i<T;i++) {
            int solved=0,penalty=0;
            for(int j=0;j<P;j++) {
                if(AC[i][j]!=-1) solved++,penalty+=AC[i][j]+WA[i][j]*20;
            }
            v.push_back(make_tuple(-solved,penalty,-(i+1)));
        }
        sort(v.begin(),v.end());
        printf("%d",-get<2>(v[0]));
        for(int i=1;i<v.size();i++) {
            if(get<0>(v[i-1])<get<0>(v[i])||get<1>(v[i-1])<get<1>(v[i])) putchar(',');
            else putchar('=');
            printf("%d",-get<2>(v[i]));
        }
        putchar('\n');
    }
}

C++: #include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include<fstream>
#include<numeric>

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
using namespace std;

const LL MOD = 1000000007;// 10^9+7
const int INF = (1 << 30);

struct Team {
	Team(int id_, int P) {
		id = id_;
		times.resize(P, INF);
		penalties.resize(P, 0);
	}

	int id;
	vector<int> times;
	vector<int> penalties;

	pair<int, int> score() const{
		int solveNum = 0;
		int penalty = 0;

		for (int time : times) {
			if (time != INF) {
				solveNum++;
				penalty += time;
			}
		}
		REP(i, times.size()) {
			if (times[i] != INF) {
				penalty += 20 * penalties[i];
			}
		}

		return { -solveNum,penalty };
	}

	const bool operator < (const Team r)const {
		if (score() == r.score()) {
			return id > r.id;
		}
		else {
			return score() < r.score();
		}
	}
};

//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	while (true) {
		int M, T, P, R;
		cin >> M >> T >> P >> R;
		if (M == 0)break;

		vector<Team> teams;
		REP(i, T) {
			teams.push_back(Team(i + 1, P));
		}
		REP(i, R) {
			int m, t, p, j;
			cin >> m >> t >> p >> j;
			t--;
			p--;
			if (j == 0) {
				teams[t].times[p] = m;
			}
			else {
				teams[t].penalties[p]++;
			}
		}
		sort(teams.begin(), teams.end());

		//output
		REP(i, T) {
			cout << teams[i].id;
			if (i != T - 1) {
				if (teams[i].score() == teams[i + 1].score()) {
					cout << "=";
				}
				else {
					cout << ",";
				}
			}
		}
		cout << endl;
	}
	//debug();
	
	return 0;
}