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++: #define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include <stdio.h>
#include <functional>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

string x(string s, const string cs, const string se) {
	int pos = 0;
	while ((pos = s.find_first_of(se)) != string::npos) {
		s.replace(pos, 1, cs);
	}
	return s;
}

string y(string a) {
	int pos4 = 0, pos9 = 0;
	a = x(a, "3", "5");
	a = x(a, "5", "6");
	a = x(a, "6", "7");
	a = x(a, "7", "8");
	int pos = a.length();
	if ((pos4 = a.find_first_of("4")) != string::npos && (pos9 = a.find_first_of("9")) != string::npos)
	{
		if (pos4 > pos9) {//4>9
			a = a.replace(pos9, 1, "7");
			pos = pos9 + 1;
		}
		else {
			a = a.replace(pos4, 1, "3");
			pos = pos4 + 1;
		}
	}
	else if ((pos4 = a.find_first_of("4")) != string::npos) {
		a = a.replace(pos4, 1, "3");
		pos = pos4 + 1;
	}
	else if ((pos9 = a.find_first_of("9")) != string::npos) {
		a = a.replace(pos9, 1, "7");
		pos = pos9 + 1;
	}
	while (pos != a.length()) {
		a = a.replace(pos, 1, "7");
		pos++;
	}
	return a;
}

int n;
int m;
int aji[100000];

int saiki(){
	return 0;
}

int main(){
	int m, t, p, r;
	while (cin >> m >> t >> p >> r && !(m == 0 && t == 0 && p == 0 && r == 0)){
		vector<pair<int, pair<int, int>>> juni; // 正解数 時間 チーム名(答えのためのvector)
		int teamscore[50]; // 各チームのスコア
		int teamsecond[50]; // 各チームの時間
		int teamincorr[50][2000]; // 各チーム各問題の間違えた回数
		int teamincorrcnt[50]; // 各チームの正解した問題の間違えた回数
		for (int i = 0; i < 50; i++) {
			teamscore[i] = 0;
			teamsecond[i] = 100000;
			teamincorrcnt[i] = 0;
			for (int j = 0; j < 2000; j++) {
				teamincorr[i][j] = 0;
			}
		}
		for (int i = 0; i < r; i++) {
			int mk, tk, pk, jk;
			cin >> mk >> tk >> pk >> jk;
			if (jk == 0) { // 正解
				teamscore[tk - 1]++; // 正解数を増やす
				teamincorrcnt[tk - 1] += teamincorr[tk - 1][pk];
				teamsecond[tk - 1] = 100000 - (mk + 20 * teamincorrcnt[tk - 1]);
			}
			else { // 間違い
				teamincorr[tk - 1][pk]++;
			}
		}
		for (int i = 0; i < t; i++) {
			juni.push_back(make_pair(teamscore[i], make_pair(teamsecond[i], i + 1)));
		}
		sort(juni.begin(), juni.end());

		int score = -1;
		int jikan = -1;
		for (int i = t - 1; i >= 0; i--) {
			if (i != t - 1) {
				if (score == juni[i].first && jikan == juni[i].second.first) {
					cout << "=";
				}
				else {
					cout << ",";
				}
			}
			cout << juni[i].second.second;
			score = juni[i].first;
			jikan = juni[i].second.first;
		}
		cout << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
bool solved[50][10];
int time[50][10];
int anstime[50];
int main(){
	int m,t,p,r;
	int a[4];
	while(true){
		cin>>m>>t>>p>>r;
		if(m==0&&t==0&&p==0&&r==0)
			break;
		for(int i=0;i<t;i++){
			anstime[i]=0;
			for(int j=0;j<p;j++){
				solved[i][j]=false;
				time[i][j]=0;
			}
		}
		for(int i=0;i<r;i++){
			for(int j=0;j<4;j++)
				cin>>a[j];
			if(a[3]==0){
				solved[a[1]-1][a[2]-1]=true;
				anstime[a[1]-1]+=time[a[1]-1][a[2]-1]+a[0];
			}
			else
				time[a[1]-1][a[2]-1]+=20;
		}
		int b[50];
		for(int i=0;i<t;i++){
			int count=0;
			for(int j=0;j<p;j++)
				count+=solved[i][j];
			anstime[i]=count*1000-anstime[i];
			b[i]=i+1;
		}
		for(int i=0;i<t-1;i++){
			for(int j=t-1;j>i;j--){
				if(anstime[j]>anstime[j-1]||(anstime[j]==anstime[j-1]&&b[j]>b[j-1])){
					int tmp=anstime[j];
					anstime[j]=anstime[j-1];
					anstime[j-1]=tmp;
					tmp=b[j];
					b[j]=b[j-1];
					b[j-1]=tmp;
				}
			}
		}
		cout<<b[0];
		for(int i=1;i<t;i++){
			if(anstime[i]==anstime[i-1])
				cout<<'=';
			else
				cout<<',';
			cout<<b[i];
		}
		cout<<endl;
	}
	return 0;
}