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++: // #ifdef DEBUG
// #define _GLIBCXX_DEBUG
// #endif
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>

// these require C++11
#include <unordered_set>
#include <unordered_map>
#include <random>
#include <thread>
#include <chrono>

using namespace std;

#define int long long

#define all(c) c.begin(), c.end()
#define repeat(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x) 
#endif

template<typename A,typename B>
ostream &operator<<(ostream&os,const pair<A,B>& p){
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

typedef complex<double> point;

// template<typename T,std::size_t N>
// struct _v_traits {using type = std::vector<typename _v_traits<T,N-1>::type>;};
// template<typename T>
// struct _v_traits<T,1> {using type = std::vector<T>;};
// template<typename T,std::size_t N=1>
// using vec = typename _v_traits<T,N>::type;

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

struct Team{
    int id;
    vector<int> time;
    vector<int> try_count;
    vector<char> ok;
};

int succeeded(const Team& t){
    int ret = 0;
    for(int i : t.time){
        ret += (0 < i);
    }
    return ret;
}

int get_time(const Team& t){
    int ret = 0;
    for(int i=0;i<t.time.size();i++){
        if(t.time[i] > 0){
            ret += (t.time[i]-1) + 20 * t.try_count[i];
        }
    }
    return ret;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

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

        vector<Team> teams;
        for(int i=0;i<T;i++){
            teams.push_back(Team{i+1,vector<int>(P,0),vector<int>(P,0)});
        }
        for(int i=0;i<R;i++){
            int m,t,p,j;
            cin >> m >> t >> p >> j;
            t--;p--;
            if(j == 0){
                teams[t].time[p] = m+1;
            }else{
                teams[t].try_count[p]++;
            }
        }

        sort(teams.begin(),teams.end(),[](const Team& left,const Team& right){
                if(succeeded(left) != succeeded(right)){
                    return succeeded(left) > succeeded(right);
                }
                if(get_time(left) != get_time(right)){
                    return get_time(left) < get_time(right);
                }
                return left.id > right.id;
            });

        for(int i=0;i<T;i++){
            if(i > 0){
                if(([](const Team& left,const Team& right){
                            return succeeded(left) == succeeded(right) and 
                                get_time(left) == get_time(right);

                        })(teams[i-1],teams[i])){
                    cout << "=";
                }else{
                    cout << ",";
                }
            }
            cout << teams[i].id;
        }
        cout << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>

using namespace std;

struct team{
    int ac,time,num;
    team(int ac,int time,int num):
    ac(ac),time(time),num(num){}
};

auto operator < (const team &e,const team &f){
    if(e.ac!=f.ac)return e.ac>f.ac;
    else if(e.time!=f.time)return e.time<f.time;
    else return e.num>f.num;
}

int main(){
    int M,T,P,R;
    while(cin>>M>>T>>P>>R,M){
        vector<team>tm;
        int plus[100][100]={};
        for(int i=0;i<T;++i){
            tm.emplace_back(0,0,i);
        }
        for(int i=0;i<R;++i){
            int m,t,p,j;
            cin>>m>>t>>p>>j;
            --t;
            if(!j){
                tm[t].time+=m+plus[t][p];
                tm[t].ac++;
            }else{
                plus[t][p]+=20;
            }
        }
        sort(tm.begin(),tm.end());
        cout<<tm[0].num+1;
        for(int i=1;i<T;++i){
            if(tm[i-1].ac==tm[i].ac && tm[i-1].time==tm[i].time){
                cout<<"=";
            }else{
                cout<<",";
            }
            cout<<tm[i].num+1;
        }
        cout<<endl;
    }
}