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 <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

struct Team {
    Team(int team_number) {
        tn_ = team_number;
        n_ = 0;
        t_ = 0;
        pc_ = 0;
    }
    int tn_;
    int n_;
    int t_;
    int pc_;
    vector<int> p_list_;
};

int main (int argc, char *argv[]) {
    int M, T, P, R;
    int m, t, p, j;
    int count = 0;
    vector<Team> tv;

    while (cin>>M>>T>>P>>R) {
        if (count != 0 )cout<<endl;
        count++;
        for (int i = 0; i < T; ++i) {
            tv.push_back(Team(i+1));
        }
        for (int i = 0; i < R; ++i) {
            cin>>m>>t>>p>>j;
            if (j != 0) {
                tv[t-1].p_list_.push_back(p);
            }
            else {
                for (auto e : tv[t-1].p_list_) {
                    if (e == p) {
                        tv[t-1].pc_++;
                    }
                }
                tv[t-1].n_++;
                tv[t-1].t_ += m;
            }
        }
        for (auto& e : tv) {
            e.t_ += e.pc_ * 20;
        }

        // for (auto e : tv) {
        //     cout<<"-----------"<<endl;
        //     cout<<e.tn_<<endl;
        //     cout<<e.n_<<endl;
        //     cout<<e.t_<<endl;
        //     cout<<e.pc_<<endl;
        //     for (auto c : e.p_list_) {
        //         cout<<c<<" ";
        //     }
        //     cout<<endl;
        //     cout<<"-----------"<<endl;
        // }

        sort(tv.begin(), tv.end(), [](const auto& lhs, const auto& rhs) -> bool{
            if (lhs.n_ != rhs.n_ ) {
                return lhs.n_ > rhs.n_;
            }
            else if (lhs.n_ == rhs.n_ && lhs.t_ != rhs.t_) {
                return lhs.t_ < rhs.t_;
            }
            else return lhs.tn_ > rhs.tn_;
        });

        const int size = static_cast<int>(tv.size());
        for (int i = 0; i < size; ++i) {
            cout<<tv[i].tn_;
            if(i != size -1) {
                if (tv[i].n_ != tv[i+1].n_ || tv[i].t_ != tv[i+1].t_ ) {
                    cout<<",";
                }
                else cout<<"=";
            }
        }
        tv.clear();
    }

    return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
typedef struct{
    int time;
    int num;
    int qst;
    int judge;
}data;
typedef  pair<int, pair<int, int>>pi; //  seikai time number
int main(){
    int m,t,p,r;
    while(cin>>m>>t>>p>>r,m+t+r+p){
    vector<data>v;
    vvi team(60,vi(60,0));
    vvi lost(1000,vi(100,0));
    rep(i,r){
        data temp;
        cin>>temp.time>>temp.num>>temp.qst>>temp.judge; v.push_back(temp);
        if(!(v[i].judge)){
            team[v[i].num][v[i].qst]=1;
            lost[v[i].num][v[i].qst]+=v[i].time;
        }else{
            lost[v[i].num][v[i].qst]+=20;
        }
    }
    vector<pi>ans(100,pi(0,pii(-INF,0)));

    for(int i=1; i<=t;i++){
        ans[i].second.second=i;
        for(int j=1; j<=p;j++)
            if(team[i][j]){
                ans[i].first++; ans[i].second.first-=lost[i][j]; ans[i].second.second=i;
        }
    }
    sort(ans.begin()+1,ans.begin()+t+1,greater<pi>());
        rep(i,t){
            if(i){
                if(ans[i].first==ans[i+1].first&&ans[i].second.first==ans[i+1].second.first)
                    cout<<"=";
                else
                    cout<<",";
            }
            cout<<ans[i+1].second.second;
        }
        cout<<endl;
    }
}