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

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
typedef long long ll;

struct Team {
    int id,time,score;
    int p[100];

    void addscore() {
        score++;
    }

    bool operator<(const Team &t) const {
        if(score == t.score) {
            if(time == t.time)  {
                return id < t.id;
            }
            return time > t.time;
        }
        return score < t.score;
    }
};

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

        vector<Team> v;
        rep(i,T) {
            Team team;
            team.id = i;
            team.score = 0;
            team.time = 0;
            memset(team.p,0,sizeof(team.p));
            v.push_back(team);
        }

        rep(i,R) {
            int m,t,p,j;
            cin >> m >> t >> p >> j;
            
            t--;
            p--;

            if(j == 0) {
                v[t].addscore();
                v[t].time += m + v[t].p[p] * 20;
            }
            else {
                v[t].p[p]++;
            }
        }

        sort(v.begin(),v.end());
        
        // cout << "--------- id output -------==" << endl;
        // REP(i,1,T) {
        //     int id = T-i;
        //     int id2 = T-i-1;
        //
        //     cout << id2 << " " << id << endl;
        // }

        cout << v[T-1].id+1;
        REP(i,1,T) {
            int id = T-i;
            int id2 = T-i-1;
            if(v[id2].score == v[id].score && v[id2].time == v[id].time) {
                cout << "=";
            }
            else cout << ",";

            cout << v[T-1-i].id+1;
        }

        cout << endl;
        
    }
    return 0;
}

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

struct team{
    int cor=0,pen=0,id=0;
    vector<int>AC;
    vector<int>correct;
    vector<int>penalty;
};
bool com(team t1,team t2){
    return t1.cor==t2.cor?t1.pen==t2.pen?t1.id>t2.id:t1.pen<t2.pen:t1.cor>t2.cor;
}
bool com2(team t1,team t2){
    return t1.cor==t2.cor?t1.pen<t2.pen:t1.cor>t2.cor;
}
int main(){
    int M,T,P,R,m,t,p,j;
    while(cin>>M>>T>>P>>R,M){
        vector<team>vec(T);
        for(int i=0;i<T;i++){
            vec[i].id=i;
            vec[i].correct.resize(P,0);
            vec[i].penalty.resize(P,0);
            vec[i].AC.resize(P,0);
        }
        for(int i=0;i<R;i++){
            cin>>m>>t>>p>>j;
            t--;p--;
            if(j==0){
                vec[t].correct[p]=vec[t].penalty[p]+m;
                vec[t].AC[p]=1;
            }
            else{
                vec[t].penalty[p]+=20;
            }
        }
        for(int i=0;i<T;i++){
            for(int a=0;a<P;a++){
                if(vec[i].AC[a]>0){
                    vec[i].cor++;
                    vec[i].pen+=vec[i].correct[a];
                }
            }
        }
        sort(vec.begin(),vec.end(),com);
        
        for(int i=0;i<T-1;i++){
            if(com2(vec[i],vec[i+1]))
                cout<<vec[i].id+1<<",";
            else
                cout<<vec[i].id+1<<"=";
        }
        cout<<vec[T-1].id+1<<endl;
        vec.clear();
    }
    
}