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 <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    while(1){
        ll M,T,P,R; cin >> M >> T >> P >> R;
        if(!M && !T && !P && !R) break;
        ll solve[55][15] = {};
        ll pena[55][15] = {};
        while(R--){
            ll m,t,p,b; cin >> m >> t >> p >> b; t--; p--;
            if(!b){
                solve[t][p] = 1;
                pena[t][p] -= m;
            }else{
                pena[t][p] -= 20;
            }
        }
        vector<tapu> ans(T);
        rep(i,T){
            ll a=0, b=0, c=0;
            rep(j,P){
                a += solve[i][j];
                if(solve[i][j]) b += pena[i][j];
            }
            c = i+1;
            ans[i] = tie(a,b,c);
        }
        sort(rall(ans));
        rep(i,T){
            ll a,b,c;
            tie(a,b,c) = ans[i];
            cout << c;
            if(i<T-1){
                ll d,e,f; tie(d,e,f) = ans[i+1];
                if(a==d && b==e) cout << '=';
                else cout << ",";
            }
        }
        cout << endl;
        rep(i,T) rep(j,P) solve[i][j] = 0, pena[i][j] = 0;
    }
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>

#define INF 999999999
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define MOD(x) (x%(mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

/*---------------------------------------------------*/

bool debug=false;

pair<pi,int> data[55];
int miss[55][15];
int M,T,P,R;

void init(){
  rep(i,55){
    data[i].first.first=0;
    data[i].first.second=0;
    data[i].second=i+1;
    rep(j,15){
      miss[i][j]=0;
    }
  }
}

void solve(){
  int m,t,p,j;
  rep(i,R){
    cin>>m>>t>>p>>j;
    if(j==0&&miss[t][p]!=-1){
      data[t-1].first.first++;
      data[t-1].first.second-=(t+miss[t][p]*20);
      miss[t-1][p]=-1;
    }else if(miss[t-1][p]!=-1){
      miss[t-1][p]++;
    }
  }

  if(debug){cout<<"solve ";rep(i,T)cout<<data[i].first.first<<" ";cout<<endl;}
  if(debug){cout<<"time ";rep(i,T)cout<<data[i].first.second<<" ";cout<<endl;}

  sort(data,data+T);reverse(data,data+T);
  cout<<data[0].second;
  REP(i,1,T){
    if(data[i].first.first==data[i-1].first.first&&data[i].first.second==data[i-1].first.second){
      cout<<'='<<data[i].second;
    }else{
      cout<<','<<data[i].second;
    }
  }
  cout<<endl;
}

int main(){

  while(cin>>M>>T>>P>>R){
    if(M==0&&T==0&&P==0&&R==0)break;
    init();
    solve();
  }
  
  return 0;
}

C++: #include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>

using namespace std;

#define INF 999999999

int wa[51][11];

struct team{
	int ac, pe, id;
	bool operator<(const team& a) const{
		if(ac != a.ac) return ac > a.ac;
		if(pe != a.pe) return pe < a.pe;
		if(id != a.id) return id > a.id;
	}
};

int main(){
	int i, j, M, T, P, R, m, t, p, ju;
	vector<team> set(51);
	while(1){
		cin >> M >> T >> P >> R;
		if(!M)break;
		for(i=0;i<=T;i++){
			set[i].ac = 0;
			set[i].pe = 0;
			set[i].id = i;
			for(j=1;j<=P;j++){
				wa[i][j] = 0;
			}
		}
		for(i=0;i<R;i++){
			cin >> m >> t >> p >> ju;
			if(!ju){
				set[t].ac++;
				set[t].pe += wa[t][p] * 20 + m;
			}
			else wa[t][p]++;
		}
		sort(set.begin()+1, set.begin()+1+T);
		for(i=1;i<=T;i++){
			if(i>1){
				if(set[i-1].ac==set[i].ac && set[i-1].pe==set[i].pe){
					cout << "=";
				}
				else cout << ",";
			}
			cout << set[i].id;
		}
		cout << endl;
	}
	return 0;
}