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>
#define REP(a,b,c) for(int a=b; a<(int)c; a++)
#define REPE(a,b,c) for(int a=b; a<=(int)c; a++)
#define REPD(a,b,c) for(int a=b; a>(int)c; a--)
#define rep(a,b) REP(a,0,b)
#define repd(a,b) REPD(a,b,0)
typedef struct{
  int m;
  int t;
  int p;
  int j;
}_datas;
typedef struct{
  int p;
  int t;
}_score;
typedef long long int ll;
using namespace std;

  

int main(){
  while(true){
    int M,T,P,R;
    cin >> M >> T >> P >> R;
    if(M == 0) break;
    vector<_datas> datas(R);
    rep(i,R) cin >> datas[i].m >> datas[i].t >> datas[i].p >> datas[i].j;
    //rep(i,R) cout << datas[i].m << " "<< datas[i].t << " "<< datas[i].p << " "<< datas[i].j << " " << endl;
    vector<_score> scores(T+1,{0,0});
    REPE(i,1,T){
      vector<int> miss_cnt(P+1,0);
      rep(j,R){
        _datas data = datas[j];
        if(data.t == i){
          if(data.j == 0){
            scores[i].p++;
            scores[i].t += data.m + miss_cnt[data.p]*20;
          }else{
            miss_cnt[data.p]++;
          }
        }
      }
    }
    /*cout << "score" << endl;
    REPE(i,1,T){
      cout<<i<<":" << scores[i].p << " " << scores[i].t << endl;
      }*/
    _score b_score = {0,0};
    REPE(i,1,T){
      int max_idx = 1;
      REPE(j,2,T){
        if(scores[j].p > scores[max_idx].p || (scores[j].p==scores[max_idx].p && scores[j].t <= scores[max_idx].t)){
          max_idx = j;
        }
      }
      if(i != 1){
        if(b_score.p == scores[max_idx].p && b_score.t==scores[max_idx].t) cout << "=";
        else cout << ",";
      }
      cout << max_idx;
      b_score = scores[max_idx];
      scores[max_idx] = {-1,0};
    }
    cout << endl;
  }
  return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include <stdio.h>
#include <functional>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

string x(string s, const string cs, const string se) {
	int pos = 0;
	while ((pos = s.find_first_of(se)) != string::npos) {
		s.replace(pos, 1, cs);
	}
	return s;
}

string y(string a) {
	int pos4 = 0, pos9 = 0;
	a = x(a, "3", "5");
	a = x(a, "5", "6");
	a = x(a, "6", "7");
	a = x(a, "7", "8");
	int pos = a.length();
	if ((pos4 = a.find_first_of("4")) != string::npos && (pos9 = a.find_first_of("9")) != string::npos)
	{
		if (pos4 > pos9) {//4>9
			a = a.replace(pos9, 1, "7");
			pos = pos9 + 1;
		}
		else {
			a = a.replace(pos4, 1, "3");
			pos = pos4 + 1;
		}
	}
	else if ((pos4 = a.find_first_of("4")) != string::npos) {
		a = a.replace(pos4, 1, "3");
		pos = pos4 + 1;
	}
	else if ((pos9 = a.find_first_of("9")) != string::npos) {
		a = a.replace(pos9, 1, "7");
		pos = pos9 + 1;
	}
	while (pos != a.length()) {
		a = a.replace(pos, 1, "7");
		pos++;
	}
	return a;
}

int n;
int m;
int aji[100000];

int saiki(){
	return 0;
}

int main(){
	int m, t, p, r;
	while (cin >> m >> t >> p >> r && !(m == 0 && t == 0 && p == 0 && r == 0)){
		vector<pair<int, pair<int, int>>> juni; // テヲツュツ」ティツァツ」テヲツ閉ー テヲツ卍づゥツ鳴?テ」ツδ?」ツδシテ」ツδ?・ツ青?テァツュツ氾」ツ?暗」ツ?ョテ」ツ?淌」ツつ?」ツ?ョvector)
		int teamscore[50]; // テ・ツ青?」ツδ?」ツδシテ」ツδ?」ツ?ョテ」ツつケテ」ツつウテ」ツつ「
		int teamsecond[50]; // テ・ツ青?」ツδ?」ツδシテ」ツδ?」ツ?ョテヲツ卍づゥツ鳴?
		int teamincorr[50][2000]; // テ・ツ青?」ツδ?」ツδシテ」ツδ?・ツ青?・ツ閉湘ゥツ。ツ古」ツ?ョテゥツ鳴禿ゥツ?陛」ツ?暗」ツ?淌・ツ崢榲ヲツ閉ー
		int teamincorrcnt[50]; // テ・ツ青?」ツδ?」ツδシテ」ツδ?」ツ?ョテヲツュツ」ティツァツ」テ」ツ?療」ツ?淌・ツ閉湘ゥツ。ツ古」ツ?ョテゥツ鳴禿ゥツ?陛」ツ?暗」ツ?淌・ツ崢榲ヲツ閉ー
		for (int i = 0; i < 50; i++) {
			teamscore[i] = 0;
			teamsecond[i] = 100000;
			teamincorrcnt[i] = 0;
			for (int j = 0; j < 2000; j++) {
				teamincorr[i][j] = 0;
			}
		}
		for (int i = 0; i < r; i++) {
			int mk, tk, pk, jk;
			cin >> mk >> tk >> pk >> jk;
			if (jk == 0) { // テヲツュツ」ティツァツ」
				teamscore[tk - 1]++; // テヲツュツ」ティツァツ」テヲツ閉ーテ」ツつ津・ツ「ツ療」ツつ?」ツ??
				teamincorrcnt[tk - 1] += teamincorr[tk - 1][pk];
				teamsecond[tk - 1] = 100000 - (mk + 20 * teamincorrcnt[tk - 1]);
			}
			else { // テゥツ鳴禿ゥツ?陛」ツ??
				teamincorr[tk - 1][pk]++;
			}
		}
		for (int i = 0; i < t; i++) {
			juni.push_back(make_pair(teamscore[i], make_pair(teamsecond[i], i + 1)));
		}
		sort(juni.begin(), juni.end());

		int score = -1;
		int jikan = -1;
		for (int i = t - 1; i >= 0; i--) {
			if (i != t - 1) {
				if (score == juni[i].first && jikan == juni[i].second.first) {
					cout << "=";
				}
				else {
					cout << ",";
				}
			}
			cout << juni[i].second.second;
			score = juni[i].first;
			jikan = juni[i].second.first;
		}
		cout << endl;
	}
	return 0;
}