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 <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <cassert>
#include <iomanip>

using namespace std;

#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;
typedef complex<int> P;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tii;
const double EPS = 1e-10;
const double PI = acos(-1.0);


const int pena = 20;

struct st{
	int id;
	int ac = 0;
	int t = 0;
	vector<int> ac_t;
	vector<int> wa_cnt;

	st(int p){
		ac_t = vector<int>(p, -1);
		wa_cnt.resize(p);
	}
	bool operator<(const st& o) const{
		return (*this).ac == o.ac ? (*this).t > o.t : (*this).ac < o.ac;
	}
	bool operator==(const st& o) const{
		return (*this).ac == o.ac && (*this).t == o.t;
	}
	bool operator!=(const st& o) const{
		return !((*this) == o);
	}

	void calc(){
		for(int i=0;i<ac_t.size();++i){
			if(ac_t[i] == -1) continue;
			++ac;
			t += ac_t[i] + wa_cnt[i] * pena;
		}
	}
};

void debug(vector<st> team){
	for(auto& o : team){
		cerr<< o.id<< " : ";
		cerr<< o.ac<< " "<< o.t;
		cerr<< " , ";
		for(auto& p : o.ac_t) cerr<< " "<< p;
		cerr<< " , ";
		for(auto& p : o.wa_cnt) cerr<< " "<< p;
		cerr<< endl;
	}
}

bool solve(){
	int m, t, p, r;
	cin>> m>> t>> p>> r;
	if(!m && !t && !p && !r) return false;
	vector<st> team(t, st(p));
	for(int i=0;i<t;++i) team[i].id = i + 1;

	for(int i=0;i<r;++i){
		int m, t, p, j;
		cin>> m>> t>> p>> j;
		--t; --p;
		if(j == 0){
			team[t].ac_t[p] = m;
		}else{
			++team[t].wa_cnt[p];
		}
	}

	//debug(team);
	for(auto& o : team) o.calc();
	sort(rall(team));
	//debug(team);

	for(int i=0;i<team.size();++i){
		if(i) cout<< ",";
		vector<int> tmp;
		tmp.push_back(team[i].id);
		for(int j=i+1;j<team.size();++j){
			if(team[i] != team[j]) break;
			tmp.push_back(team[j].id);
		}
		sort(rall(tmp));
		for(int j=0;j<tmp.size();++j){
			if(j) cout<< "=";
			cout<< tmp[j];
		}
		i += tmp.size() - 1;
	}
	cout<< endl;

	return true;
}

int main(){
	cout.setf(ios::fixed); cout.precision(10);
	while(solve());
	return 0;
}

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

class TM{
public:
  int id, s, p;
  TM(){}
  TM(int id):id(id){ s = p = 0;}
  bool operator < ( const TM &t) const{
    if ( s == t.s ){
      if ( p == t.p ) return id > t.id;
      return p < t.p;
    } return s > t.s;
  }
};

int M, T, P, R;
bool S[51][11];
int X[51][11];

void solve(){
  int m, t, p, j;
  TM B[51];
  B[0] = TM(0); B[0].s = 100;
  for ( int i = 1; i <= T; i++ ) B[i] = TM(i);

  for ( int i = 0; i < R; i++ ){
    cin >> m >> t >> p >> j;
    if ( j == 0 ){
      B[t].s++;
      B[t].p += 20*X[t][p] + m;
    } else {
      X[t][p]++;
    }
  }
  sort(B, B+(T+1));

  for ( int i = 1; i <= T; i++ ) {
    if ( i> 1 ){
      if ( B[i].s == B[i-1].s && B[i].p == B[i-1].p ) cout << "=";
      else cout << ",";
    }
    cout << B[i].id;
  }
  cout << endl;

}

main(){
  while(1){
    cin >> M >> T >> P >> R;
    if ( M == 0 ) break;
    for ( int i = 1; i <= T; i++ ){
      for ( int j = 1; j <= P; j++ ){
	S[i][j] = false;
	X[i][j] = 0;
      }
    }
    solve();
  }
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <ctime>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppiii;
typedef vector<int> vi;
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define RREP(i,x) for(int i=(x)-1;i>=0;i--)
#define RFOR(i,c) for(auto i=(c).rbegin();i!=(c).rend();++i)
#define ALL(container) container.begin(), container.end()
#define SZ(container) ((int)container.size())

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;

main(){
	int M, T, P, R;
	while(cin >> M >> T >> P >> R, M){
		vector<ppiii> lis(T);
		vector< vector<int> > wa(T+1, vector<int>(P+1, 0));
		REP(i, T) lis[i] = ppiii(pii(0, 0), -i-1);
		REP(i, R){
			int m, t, p, j;
			cin >> m >> t >> p >> j;
			if(j) wa[t][p]++;
			else{
				lis[t-1].first.first --;
				lis[t-1].first.second += m + wa[t][p]*20;
			}
		}
		sort(lis.begin(), lis.end());
		cout << -lis[0].second;
		for(int i=1;i<T;i++){
			cout << (lis[i-1].first==lis[i].first?"=":",")<<-lis[i].second;
		}
		cout << endl;
	}
	return 0;
}