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 "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef pair<ll, ll>P;

class Team{
    public:
    vector<ll>flg, tim;
    ll name;
    P score;
    Team(ll _name, ll P){
        name = _name;
        flg = vector<ll>(P + 1, 0);
        tim = vector<ll>(P + 1, 0);
    }
    void calc(){
        score.first = 0;
        score.second = 0;
        for(ll i = 0; i < flg.size(); i++){
            if(flg[i]){
                score.first--;
                score.second += tim[i];
            }
        }
    }
    bool operator < (const Team &t)const{
        if(score == t.score)return name > t.name;
        return score < t.score;

    }
};

int main(){
    
    for(ll M, T, P, R; cin >> M >> T >> P >> R, M;){
        vector<Team>teams;
        for(ll i = 0; i <= T; i++)teams.push_back(Team(i, P));
        for(ll i = 0; i < R; i++){
            ll m, t, p, j;
            cin >> m >> t >> p >> j;
            if(teams[t].flg[p])continue;
            if(j == 0){
                teams[t].tim[p] += m;
                teams[t].flg[p] = 1;
            }
            else{
                teams[t].tim[p] += 20;
            }
        }
        vector<Team>vec;
        for(ll i = 1; i <= T; i++){
            teams[i].calc();
            vec.push_back(teams[i]);
        }    
        sort(vec.begin(), vec.end());
        for(ll i = 0; i < T; i++){
            cout << vec[i].name;
            if(i + 1 == T)cout << endl;
            else if(vec[i].score == vec[i+1].score)cout << "=";
            else cout << ",";
        }
    }
    
    return 0;    
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

typedef struct _team{
    int tid;
    int ac;
    int time;
    _team(){tid=ac=time=0;}
} Team;

bool cmp(Team& a, Team& b){
    if(a.ac == b.ac){
        if(a.time == b.time){
            return a.tid > b.tid;
        }else{
            return a.time < b.time;
        }
    }else{
        return a.ac > b.ac;
    }
}

int main(){
    while(1){
        int m,t,p,r;
        cin >> m >> t >> p >> r;
        if(m==0) break;

        int mi, ti, pi, ji;
        vector<vector<int> > pena(t, vector<int>(p, 0));
        vector<Team> info(t);
        for(int i=0; i<t; i++){
            info[i].tid = i+1;
        }
        
        for(int i=0; i<r; i++){
            cin >> mi >> ti >> pi >> ji;
            ti--;
            pi--;
            if(ji==0){
                info[ti].time += mi;
                info[ti].ac++;
                pena[ti][pi] = -pena[ti][pi];
            }else{
                pena[ti][pi] -= 20;
            }
        }
        for(int i=0; i<t; i++){
            for(int j=0; j<p; j++){
                if(pena[i][j]>0){
                    info[i].time += pena[i][j];
                }
            }
        }

        sort(info.begin(), info.end(), cmp);
        cout << info[0].tid;
        for(int i=1; i<t; i++){
            if(info[i].ac==info[i-1].ac && info[i].time==info[i-1].time){
                cout << "=";
            }else{
                cout << ",";
            }
            cout << info[i].tid;
        }
        cout << endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <utility>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;

int main() 
{
	int M,T,P,R;
	while(cin >> M >> T >>P >> R  && !(M==0 && T==0 && P==0 && R==0))
	{
		
		int a[50][50]={}; // Team * Problem の成否 正解なら1
		int b[50][50]={}; // 同、得点（候補）
		
		int m[2000]={0};
		int t[2000]={0};
		int p[2000]={0};
		int j[2000]={0};
		
		REP(i,R){
		cin >> m[i] >> t[i] >> p[i] >> j[i];
		t[i]--;p[i]--;}
		
		REP(i,R){
			if(j[i]==0)
			{
				a[t[i]][p[i]]=1;
				b[t[i]][p[i]]+=m[i];
			}
			else
			{
				b[t[i]][p[i]]+=20;
			}
		}
		
		int xa[50]={}; //正解数
		int xb[50]={}; //得点合計
		REP(i,T){REP(j,P){
				xa[i]+=a[i][j];
				xb[i]+=a[i][j]*b[i][j];
			}
		}
		
		int po[50]; // 得点のパターンを照準に
		REP(i,T){po[i]=xb[i];}
		sort(po,po+T);
		
//		REP(i,T){cout << xa[i] << " " << xb[i] << endl;}
//		REP(i,T){cout << po[i] << " ";}
		
		bool flag1=false; // １チームでも出力したらフラグ立てる
		for(int i=P;i>-1;i--)
		{
			for(int j=0;j<T;j++)
			{
				bool flag2 = false;  //同一正解、同一得点のチームが出力されていたらフラグ立てる
				bool flag3 = false; //同一得点を検索していたらフラグ立てる
				if(po[j-1]==po[j] && j>0){flag3=true;}
				for(int k=(T-1);k>-1;k--)
				{
					if(flag3){break;}
					if(	xa[k]==i && xb[k]==po[j] )
					{
						if(!flag1){cout << k+1; flag1=true;flag2=true;}
						else if(flag1 && !flag2){cout<<"," << k+1;flag2=true;}
						else {cout << "=" << k+1;}
					}
				}
			}
		}
		cout << endl;
	}
	return 0;
}