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 <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

int M,T,P,R,m[2010],t[2010],p[2010],J[2010];

void main2(){
	int solved[55]={},penal[55]={},failed[55][11]={};
	rep(i,R){
		if(J[i]==0){
			solved[t[i]]++;
			penal[t[i]]+=m[i]+failed[t[i]][p[i]]*20;
		}else{
			failed[t[i]][p[i]]++;
		}
	}
	pair<pi,int> team[55];
	rep2(i,1,T+1){
		team[i] = mp(mp(-solved[i],penal[i]),-i);
	}
	sort(team+1,team+T+1);
	rep2(i,1,T+1){
		cout<<-team[i].sec;
		if(i==T)cout<<endl;
		else cout<<(team[i].fir == team[i+1].fir ? "=":",");
	}
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	while(cin>>M>>T>>P>>R && M){
		rep(i,R)cin>>m[i]>>t[i]>>p[i]>>J[i];
		main2();
	}
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<pair<int,int>,int> p3;
typedef pair<int,int> p2;



int main(){
	int m,t,p,r;

	while(true){
		cin>>m>>t>>p>>r;
		if(m==t && t==p && p==r && m==0){
			break;
		}

		vector<p3> corrects; //first:correct number, second:time , third team number-1
		vector< vector<int> > submits;
		vector<int> times;

		for(int i=0;i<t;i++){
			corrects.push_back(p3(p2(0,0),i));
			times.push_back(0);
			submits.push_back(vector<int>(p));
			for(int j=0;j<p;j++){
				submits[i][j]=0;
			}
		}

		for(int i=0;i<r;i++){
			int mi,ti,pi,ri;
			cin>>mi>>ti>>pi>>ri;
			ti--;pi--;

			if(ri != 0){
				submits[ti][pi]++;
			}else{
				corrects[ti].first.second-=mi+submits[ti][pi]*20;
				corrects[ti].first.first++;
			}
		}

		sort(corrects.begin(),corrects.end());
		reverse(corrects.begin(),corrects.end());
		for(int i=0;i<corrects.size();i++){
			cout<<corrects[i].second+1;
			//cout<<" "<<"corrects:"<<corrects[i].first.first<<"time:"<<corrects[i].first.second;
			if(i+1 == corrects.size()){
				cout<<endl;
				break;
			}
			if(corrects[i].first.first==corrects[i+1].first.first){
				if(corrects[i].first.second==corrects[i+1].first.second){
					cout<<"=";
				}
				else{
					cout<<",";
				}
			}else{
				cout<<",";
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
#include <queue>
 
using namespace std;

class team{
public:
	int ac,pe,num;
	vector<int> wa;
	team(int n){
		ac=0;pe=0;
		wa=vector<int>(n);
	}

	bool operator<(const team& t) const{
		return ac<t.ac || ac==t.ac && pe>t.pe || ac==t.ac && pe==t.pe && num<t.num;
	}
	bool operator==(const team& t) const{
		return ac==t.ac && pe==t.pe;
	}

};

int main()
{

	int M,T,P,R;
	while(cin>>M>>T>>P>>R,M){
		vector<team> vt(T,team(P));
		for(int i=0;i<T;i++) vt[i].num=i+1;
		for(int i=0;i<R;i++){
			int m,t,p,j;
			cin>>m>>t>>p>>j;

			if(j){
				vt[t-1].wa[p-1]++;
			}else{
				vt[t-1].ac++;
				//vt[t-1].last=m;
				vt[t-1].pe+=m+vt[t-1].wa[p-1]*20;
			}
		}
		sort(vt.begin(),vt.end());
		reverse(vt.begin(),vt.end());


		for(int i=0;i<vt.size()-1;i++){
			cout<<vt[i].num;
			if(vt[i]==vt[i+1]) cout<<"=";
			else cout<<",";
		}
		cout<<vt.back().num<<endl;
	}

	return 0;
}