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,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

struct data {
	int score, time, team;
	data(int score, int time, int  team) :score(score), time(time), team(team) {}
};

bool cmp(data d1, data d2){
	if(d1.score == d2.score){
		if(d1.time == d2.time) return d1.team > d2.team;
		return d1.time < d2.time;
	}
	return d1.score > d2.score;
}

signed main() {
	int M, T, P, R, m, t, p, r;
	while (1) {
		cin >> M >> T >> P >> R;
		if (M + T + P + R == 0)  break;
		int wa[51][11] = { 0 };
		vector<data> d;
		rep(i, 0, T) {
			d.push_back(data(0, 0, 0));
			d[i].team = i + 1;
		}
		rep(i, 0, R) {
			cin >> m >> t >> p >> r;
			t--; p--;
			if (r == 0) {
				d[t].score++;
				d[t].time += m + wa[t][p] * 20;
				//cout << "  " << t + 1 << " " << d[t].score << " " << d[t].time << endl;
			}
			else {
				wa[t][p]++;
			}
		}
		sort(all(d), cmp);
		rep(i, 0, T) {
			if (i == 0) {
				cout << d[i].team;
				continue;
			}
			if (d[i].score == d[i - 1].score && d[i].time == d[i - 1].time) {
				cout << "=";
			}
			else {
				cout << ",";
			}
			cout << d[i].team;
		}
		cout << endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
const long long MOD = 1e9+7, INF = 1e18;
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a=b;return true;}return false;}

int M,T,P,R;
int kan[55][15];
int ac[55][15];
int wa[55][15];

signed main(){
	vector<string>ans;
	while(cin>>M>>T>>P>>R,M||T||P||R){
		int m,t,p,j;
		memset(ac,0,sizeof(ac));
		memset(wa,0,sizeof(wa));
		memset(kan,0,sizeof(kan));
		REP(i,R){
			cin>>m>>t>>p>>j;
			t--;p--;
			if(j){
				if(ac[t][p])continue;
				wa[t][p]++;
			}else{
				if(ac[t][p])continue;
				ac[t][p] = m;
				kan[t][p]++;
			}
		}
		vector<pair<pair<int,int>,int>>score(T,{{0,0},0});
		REP(i,T)score[i].second = i+1;
		REP(i,T){
			REP(j,P){
				if(kan[i][j]==0)continue;
				score[i].first.first++;
				score[i].first.second -= ac[i][j] + wa[i][j] * 20;
			}
		}
		sort(ALL(score));
		string ret = "";
		RREP(i,T){
			ret+=to_string(score[i].second);
			if(i!=0){
				if(score[i].first==score[i-1].first){
					ret+='=';
				}else{
					ret+=',';
				}
			}
		}
		ans.push_back(ret);
	}
	for(auto e:ans){
		cout<<e<<endl;
	}
}

C++: #include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;

int main(){
    int m, t, p, r;
    while(cin >> m >> t >> p >> r, m||t||p||r){
        vector< pair<pair<int,int>,int> > v(51);
        int miss_cnt[51][11] = {0};
        rep(i,51) v[i].first.second= INF;
        rep(i,51) v[i].second= i + 1;
        rep(i,r){
            int time, team, prob,jud;
            cin >> time >> team >> prob >> jud;
            team--; prob--;
            if(jud == 0){
                v[team].first.first++;
                v[team].first.second -= time + miss_cnt[team][prob] * 20;
            }else{
                miss_cnt[team][prob]++;
            }
        }
        sort(v.begin(), v.begin() + t, greater<pair<pair<int,int>,int>>());
        rep(i,t){
            if(i){
                if(v[i - 1].first.first == v[i].first.first && v[i - 1].first.second == v[i].first.second){
                    cout << '=';
                }else{
                    cout << ',';
                }
            }
            cout << v[i].second;
        }
        cout << endl;
    }
}

C++: #include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;
struct Team{
  int id,m,tm;
  Team():id(0),m(0),tm(0){}
  Team(int i):id(i),m(0),tm(0){}
};

bool operator < (const Team& a, const Team& b){
  return a.m>b.m || (a.m==b.m && a.tm < b.tm) || (a.m==b.m && a.tm==b.tm && a.id > b.id);
}

int mistake[60][20];

int main(){
  int m,t,p,r;
  while(cin>>m>>t>>p>>r,m||t||p||r){
    memset(mistake,0,sizeof(mistake));
    Team tem[60];
    for(int i=0;i<t;++i) tem[i]=Team(i+1);
    while(r--){
      int a,b,c,d;
      cin>>a>>b>>c>>d;
      b--;
      if(!d){
	tem[b].m++;
	tem[b].tm+=a+mistake[b][c]*20;
      }
      else
	mistake[b][c]++;
    }
    sort(tem,tem+t);
    for(int i=0;i+1<t;++i){
      cout<<tem[i].id;
      if(tem[i].m==tem[i+1].m && tem[i].tm==tem[i+1].tm) cout << "=";
      else cout << ",";
    }
    cout << tem[t-1].id << endl;
  }
  return 0;
}