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 <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <string>
#include <algorithm>
#include <string>
#include <climits>
#include <utility>
 
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define REG(i, a, b) for (int (i) = ((int)(a)); (i) < ((int)(b)); i++)
#define ALL(V) (V).begin(), (V).end()
#define PRINT(STR) cout << (STR) << endl
#define ROUNDED(N) fixed << setprecision(N)
#define SPACE " "
 
typedef long long ll;
using namespace std;
 
int nextInt() { int n; cin >> n; return n; }
double nextDouble() { double d; cin >> d; return d; }
string nextString() { string str; cin >> str; return str; }
 
int main() {
    cin.tie(0); //??????±?????????????????????
    ios::sync_with_stdio(false); //printf???¨???±??????????????????
    int M,T,P,R;
    while(cin>>M>>T>>P>>R,M){
      vector<vector<pair<bool,int>>> team(T,vector<pair<bool,int>>(P,make_pair(false,0)));//first is the number of problem
        REP(i,R){
            int m,t,p,j;
            cin >> m>>t>>p>>j;
	    t--;
	    p--;
            if(!j){
                team[t][p].first = true;
                team[t][p].second += m;
            }else{
                team[t][p].second += 20;
            }
        }
        vector<pair<int,pair<int,int>>> teamres(T,make_pair(0,make_pair(15000,0)));
        REP(i,T){
            teamres[i].second.second = i;
            REP(j,P){
                if(team[i][j].first){
                    teamres[i].first++;
                    teamres[i].second.first -= team[i][j].second;
                }
            }
        }
        sort(ALL(teamres));
        reverse(ALL(teamres));
            REP(i,T-1){
                if(teamres[i].first == teamres[i+1].first && teamres[i].second.first == teamres[i+1].second.first){
                    cout << teamres[i].second.second + 1 << "=";
                }else{
                    cout << teamres[i].second.second + 1 << ",";
                }
            }
            cout << teamres[T-1].second.second + 1 << endl;
 
    }
return 0;
}

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

const int INF=5000000;

int data[51][12];

int main(){
	int M,T,P,R;
	while(cin>>M>>T>>P>>R && M){
		fill((int*)data,(int*)(data+12),0);
		for(int i=0;i<R;i++){
			int m,t,p,j;
			cin>>m>>t>>p>>j;
			if(j==0){
				data[t][0]++;
				data[t][11]+=m+data[t][p]*20;
			}
			else data[t][p]++;
		}
		int prev[2]={INF,0};
		for(int i=0;i<T;i++){
			int ans=0;
			int now[2]={0,INF};
			for(int j=T;j>=0;j--){
				if(data[j][0]>now[0]){
					now[0]=data[j][0];
					now[1]=data[j][11];
					ans=j;
				}
				else if(data[j][0]==now[0] && data[j][11]<now[1]){
					now[1]=data[j][11];
					ans=j;
				}
			}
			if(i){
				if(memcmp(now,prev,sizeof(now))==0)cout<<"=";
				else cout<<",";
			}
			cout<<ans;
			memcpy(prev,now,sizeof(now));
			data[ans][0]=-1;
		}
		cout<<endl;
	}
}

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

using namespace std;

bool cmp(pair<pair<int,int>,int> a, pair<pair<int,int>,int> b){
  if(a.first.first==b.first.first){
    if(a.first.second==b.first.second) return a.second > b.second;
    return a.first.second < b.first.second;
  }else return a.first.first > b.first.first;
}

int main(){
  int m,t,p,r;
  while(cin >> m >> t >> p >> r && (m || t || p || r)){
    vector<vector<int> > unc(t,vector<int>(p,0));
    vector<pair<int,int> > cntc(t,make_pair(0,0)),cost(t,make_pair(0,0));
    for(int i=0;i<t;++i) { cntc[i].second=i; cost[i].second=i; }
    for(int i=0;i<r;++i){
      int mi,ti,pi,ji; cin >> mi >> ti >> pi >> ji;
      if(ji==0) {
	cost[ti-1].first+=(mi + unc[ti-1][pi-1]*20);
	cntc[ti-1].first++;
      } else unc[ti-1][pi-1]++;
    }
    vector<pair<pair<int,int>,int> > rank(t);
    for(int i=0;i<t;++i) {
      rank[i].first.first=cntc[i].first;
      rank[i].first.second=cost[i].first;
      rank[i].second=i + 1;
    }
    sort(rank.begin(),rank.end(),cmp);
    cout << rank[0].second;
    for(int i=1;i<t;++i){
      if(rank[i-1].first.first==rank[i].first.first &&
	 rank[i-1].first.second==rank[i].first.second)
	cout << "=";
      else cout << ",";
      cout << rank[i].second;
    }
    cout << endl;
  }
}