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 <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>
#include <fstream>
#include <cassert>
using namespace std;

//common
typedef long long i64,ll;

#define BR "\n"
#define ALL(c) (c).begin(),(c).end()
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,r) for(int i=(l);i<(int)(r);++i)
#define EACH(it,o) for(auto it = (o).begin(); it != (o).end(); ++it)
#define IN(l,v,r) ((l)<=(v) && (v)<(r))

//debug
#ifdef NDEBUG
#define DUMP(x)
#define DUMPLN(x)
#define DEBUG(x)
#define DEBUGLN(x)
#define LINE()
#define LINELN()
#define CHECK(exp,act)
#define STOP(e)
#else
#define DUMP(x)  cerr << #x << " = " << (x)
#define DUMPLN(x)  DUMP(x) <<endl
#define DEBUG(x) DUMP(x) << LINE() << " " << __FILE__
#define DEBUGLN(x) DEBUG(x)<<endl
#define LINE()    cerr<< " (L" << __LINE__ << ")"
#define LINELN()    LINE()<<endl
#define CHECK(exp,act)  if(exp!=act){DUMPLN(exp);DEBUGLN(act);}
#define STOP(e)  CHECK(e,true);if(!(e)) exit(1);
#endif

template<class T> inline string toString(const vector<T>& x) {
	stringstream ss;
	REP(i,x.size()){
		if(i!=0)ss<<" ";
		ss<< x[i];
	}
	return ss.str();
}

template<class T> inline string toString(const vector<vector<T> >& map) {
	stringstream ss;
	REP(i,map.size()){
		if(i!=0)ss<<BR;
		ss<< toString(map[i]);
	}
	return ss.str();
}
template<class K,class V>  string toString(map<K,V>& x) {
	string res;stringstream ss;
	for(auto& p:x)ss<< p.first<<":" << p.second<<" ";
	return ss.str();
}

string BITtoString(int bit){
    stringstream ss;
    while(bit!=0){ss<<(bit%2);bit/=2;}
    string res=ss.str();reverse(ALL(res));
    return res;
}

template<typename T,typename V> inline T pmod(T v,V MOD){
	return (v%MOD+MOD)%MOD;
}


int M,T,P,R;
class Team{
public:
	int id;int sc;
	vector<int> wts;
	int time;
	Team(int id,int sc,int time):id(id),sc(sc),time(time){
		wts=vector<int>(P);
	}

	bool operator < (const Team& r) const{
		if(sc!=r.sc)return sc<r.sc;
		else if(time!=r.time)return time>r.time;
		return id<r.id;
	}

	bool operator > (const Team& r) const{
		if(sc!=r.sc)return sc>r.sc;
		else if(time!=r.time)return time<r.time;
		return id>r.id;
	}
};

class Main{
public:
	
	vector<int> ms,ts,ps,js;

	bool input(){
		cin >> M >> T >> P >> R;if(M==0)return false;

		ms=vector<int>(R);ts=vector<int>(R);
		ps=vector<int>(R);js=vector<int>(R);

		REP(i,R){
			cin >> ms[i] >> ts[i] >> ps[i] >> js[i];ts[i]--;
		}
		return true;
	}

	void run(){

		while(input()){
			vector<Team> teams;  
			REP(i,T)teams.push_back(Team(i,0,0));
			
			REP(i,R){
				if(js[i]==0){
					Team& t=teams[ts[i]];
					t.sc++;
					t.time+=ms[i];
					t.time+=t.wts[ps[i]];
				}else{
					Team& t=teams[ts[i]];
					t.wts[ps[i]]+=20;
				}
			}

			//REP(i,T)teams[i].time/=60;

			sort(ALL(teams),greater<Team>());
			int psc=-1,ptime=-1;
			stringstream res;
			REP(i,T){
				if(i!=0){
					if(teams[i].sc==psc && teams[i].time==ptime){
						res<<"=";
					}else{
						res<<",";
					}
				}
				res<<teams[i].id+1;
				psc=teams[i].sc;
				ptime=teams[i].time;
			}
			cout << res.str()<<endl;
		}
		
	}
};

 int main(){
	//ios::sync_with_stdio(false);
 	Main().run();
 	return 0;
 }

C++: #include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const double EPS=1e-10;
const ll INF=1000000000;
const ll MAX=100010;
int main(){
    int M,T,P,R;
    while(cin>>M>>T>>P>>R,M+T+P+R){
        pair<pair<int,int>,int> v[60]={};
        int wa[60][11]={};
        int pn[60]={};
        for(int i=0;i<R;i++){
            int m,t,p,j;
            cin>>m>>t>>p>>j;
            t--;
            if(j){
                wa[t][p]++;
                continue;
            }
            pn[t]+=wa[t][p]*20;
            v[t].first.first--;
            v[t].first.second=m;
        }
        for(int i=0;i<T;i++){
            v[i].first.second+=pn[i];
            v[i].second=-(i+1);
        }
        sort(v,v+T);
        for(int i=0;i<T;i++){
            cout<<-v[i].second;
            if(i==T-1){
                cout<<endl;
                continue;
            }
            if(v[i].first==v[i+1].first){
                cout<<"=";
            }else{
                cout<<",";
            }
        }
    }
}