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(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using TR = tuple<int, int, int>;

string join(const vector<string>& v, char c) {
	string s;
  for (auto p = begin(v); p != end(v); ++p) {
    s += *p;
    if (p != v.end() - 1) s += c;
  }
	return s;
}

int main() {
  for (int M, T, P, R; cin >> M >> T >> P >> R, M;) {
    vector<vector<int>> cnt(T, vector<int>(P, 0));
    vector<TR> sc(T);
    REP(i, T) sc[i] = TR(0, 0, -i);
    REP(i, R) {
      int m, t, p, j;
      cin >> m >> t >> p >> j, t--, p--;
      if (j) {
        cnt[t][p]++;
        continue;
      }
      int ps, ms, tmp;
      tie(ps, ms, tmp) = sc[t];
      sc[t] = TR(ps - 1, ms + m + 20 * cnt[t][p], -t);
    }
    sort(begin(sc), end(sc));
    vector<vector<string>> ans_vv;
    int ps, ms, t;
    tie(ps, ms, t) = sc[0];
    ans_vv.push_back({to_string(-t + 1)});
    REP(i, T - 1) {
      int pc, mc, tc;
      tie(pc, mc, tc) = sc[i];
      int pn, mn, tn;
      tie(pn, mn, tn) = sc[i + 1];
      if (pc == pn && mc == mn) {
        ans_vv.back().push_back(to_string(-tn + 1));
      } else {
        ans_vv.push_back({to_string(-tn + 1)});
      }
    }
    vector<string> ans_v(ans_vv.size());
    REP(i, ans_vv.size()) ans_v[i] = join(ans_vv[i], '=');
    string ans = join(ans_v, ',');
    cout << ans << endl;
  }
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
static const int N = 2001;
using namespace std;
struct data{
  int correctcnt,time,tnum;
  bool operator<(const data& right)const{
    if(correctcnt!=right.correctcnt) return correctcnt>right.correctcnt;
    if(time!=right.time) return time<right.time;
    return tnum>right.tnum;
  }
};
int main(){
  int M,T,P,R,i,j,m[N],t[N],p[N],in_j[N],incorrectcnt;
  while(1){
    cin >> M >> T >> P >> R;
    vector<data> V(T);
    if(M==0&&T==0&&P==0&&R==0) break;
    for(i=0;i<R;i++){
      cin >> m[i] >> t[i] >> p[i] >> in_j[i];
    }
    for(i=0;i<T;i++){
      V[i].tnum=i+1;
      V[i].correctcnt=V[i].time=0;
    }
    for(i=0;i<R;i++){
      if(in_j[i]==0){
    V[t[i]-1].correctcnt++;
    incorrectcnt=0;
    for(j=0;j<i;j++){
      if(t[i]==t[j]&&p[i]==p[j]) incorrectcnt++;
    }
    V[t[i]-1].time+=m[i]+20*incorrectcnt;
      }
    }
    sort(V.begin(),V.end());
    for(i=0;i<T-1;i++){
      cout << V[i].tnum;
      if(V[i].correctcnt==V[i+1].correctcnt&&V[i].time==V[i+1].time) cout << '=';
      else cout << ',';
    }
    cout << V[T-1].tnum << endl;
  }  
  return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define foreach(i,c) for(auto i=(c).begin();i!=(c).end();++i)
#define all(c) begin(c),end(c)
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int main()
{
	for(int M,T,P,R;cin>>M>>T>>P>>R,M|T|P|R;){
		vector<pii> res(T); // solved,penalty
		vvi cnt(T,vi(P));
		rep(i,R){
			int m,t,p,j; cin>>m>>t>>p>>j; t--,p--;
			if(j==0){
				res[t].first++;
				res[t].second-=m+20*cnt[t][p];
			}
			else
				cnt[t][p]++;
		}
		vi is(T); iota(all(is),0); reverse(all(is));
		stable_sort(all(is),[&](int i,int j){return res[i]>res[j];});
		cout<<is[0]+1;
		repi(i,1,T)
			cout<<(res[is[i]]==res[is[i-1]]?'=':',')<<is[i]+1;
		cout<<endl;
	}
}

C++: #include <cstdio>
#include <algorithm>

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

using namespace std;

int main(){
	for(int M,T,P,R;scanf("%d%d%d%d",&M,&T,&P,&R),M;){
		int AC[50]={},penalty[50]={},submit[50][10]={};
		rep(_,R){
			int m,t,p,j; scanf("%d%d%d%d",&m,&t,&p,&j); t--; p--;
			if(j==0){
				AC[t]++;
				penalty[t]+=m+20*submit[t][p];
			}
			submit[t][p]++;
		}

		pair<pair<int,int>,int> tmp[50];
		rep(i,T) tmp[i]=make_pair(make_pair(-AC[i],penalty[i]),-i);
		sort(tmp,tmp+T);
		rep(i,T) printf("%d%c",-tmp[i].second+1,i<T-1?tmp[i].first<tmp[i+1].first?',':'=':'\n');
	}

	return 0;
}