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 <algorithm>
#include <string.h>
#include <vector>
#include <map>
using namespace std;
typedef pair<int,int> pii;
int miss[66][20];
int main(){
    
  int M,T,P,R;
  int m,t,p,j;
  int i,k;
  vector<pii> team;
  while(cin>>M>>T>>P>>R,M|T|P|R){
    memset(miss,0,sizeof(miss));
    team.clear();
    for(i=0;i<=T;i++){
      team.push_back(pii(0,0));
    }
    
    for(i=0;i<R;i++){
      cin>>m>>t>>p>>j;
      if(j==0){
	team[t].first++;
	team[t].second+=(m+miss[t][p]*20);
      }
      else{
	miss[t][p]++;
      }
    }
    /*
    for(i=0;i<T;i++){
      cout<<i<<":"<<team[i].first<<" : "<<team[i].second<<endl;
    }
    */
    int prei,tmpi,tmp;
    int use[60];
    memset(use,0,sizeof(use));
    for(j=0;j<T;j++){
      i=T;
      while(use[i]==1)i--;
      tmpi=i;
      for(i=i-1;i>0;i--){
	if(use[i]==1) continue;
	if(team[i].first>team[tmpi].first){
	  tmpi=i;
	}
	else if(team[i].first==team[tmpi].first){
	  if(team[i].second<team[tmpi].second){
	    tmpi=i;
	  }
	}
	
      }
      use[tmpi]=1;
      //cout<<"["<<tmpi<<"];"<<team[tmpi].first<<"---"<<team[tmpi].second<<endl;
      if(j==0) cout<<tmpi;
      else if(team[tmpi].first==team[prei].first&&team[tmpi].second==team[prei].second){
	cout<<"="<<tmpi;
      }
      else{
	cout<<","<<tmpi;
      }
      prei=tmpi;
    }
    cout<<endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int M,T,p,R;
    cin >> M >> T >> p >> R;
    while(M != 0){
        vector<pair<int,pair<int,int>>> G(T);
        for(int i=0; i<T; i++){
            G[i].second.second = i;
        }
        vector<vector<int>> cnt(T,vector<int> (p,0));
        for(int i=0; i<R; i++){
            int m,t,q,j;
            cin >> m >> t >> q >> j;
            t--;
            q--;
            if(cnt[t][q] == -1) continue;
            if(j){
                cnt[t][q]++;
            }else{
                G[t].first++;
                G[t].second.first += (-1)*(cnt[t][q]*20+m);
                cnt[t][q] = -1;
            }
        }
        sort(G.begin(),G.end());
        reverse(G.begin(),G.end());
        cout << G[0].second.second+1;
        for(int i=1; i<T; i++){
            if(G[i-1].first == G[i].first and G[i-1].second.first == G[i].second.first){
                cout << "=";
            }else{
                cout << ",";
            }
            cout << G[i].second.second+1;
        }
        cout << endl;
        cin >> M >> T >> p >> R;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const double EPS=1e-10;
const ll INF=1000000000;
const ll MAX=100010;
int main(){
    int M,T,P,R;
    while(cin>>M>>T>>P>>R,M+T+P+R){
        pair<pair<int,int>,int> v[60]={};
        int wa[60][11]={};
        int pn[60]={};
        for(int i=0;i<R;i++){
            int m,t,p,j;
            cin>>m>>t>>p>>j;
            t--;
            if(j!=0){
                wa[t][p]++;
                continue;
            }
            pn[t]+=wa[t][p]*20;
            v[t].first.first--;
            v[t].first.second+=m;
        }
        for(int i=0;i<T;i++){
            v[i].first.second+=pn[i];
            v[i].second=-(i+1);
        }
        sort(v,v+T);
        for(int i=0;i<T;i++){
            cout<<-v[i].second;
            if(i==T-1){
                cout<<endl;
                continue;
            }
            if(v[i].first==v[i+1].first){
                cout<<"=";
            }else{
                cout<<",";
            }
        }
    }
}