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 <utility>

using namespace std;

const int T = 50, P = 10;

struct team{
	int id, time, score;
	int counts[P];
};

team teams[T] = { };

bool comp(const team& a, const team& b){
	if(a.score == b.score){
		if(a.time == b.time){
			return a.id > b.id;
		}
		return a.time < b.time;
	}
	else{
		return a.score > b.score;
	}
}

int main(){
	int m, t, p, r;
	while(cin >> m >> t >> p >> r){
		int a, b, c, d;
		for(int i = 0;i < t;++i){
			teams[i].id = i + 1;
			teams[i].time = teams[i].score = 0;
			fill(teams[i].counts, teams[i].counts + P, 0);
		}
		for(int i = 0;i < r;++i){
			cin >> a >> b >> c >> d;
			--b;
			if(!d){
				teams[b].time += a + teams[b].counts[--c] * 20;
				++teams[b].score;
			}
			else{
				++teams[b].counts[--c];
			}
		}
		sort(teams, teams + t, comp);
		for(int i = 0;i < t;++i){
			if(i > 0){
				if(teams[i - 1].time == teams[i].time && teams[i - 1].score == teams[i].score) cout << "=";
				else cout << ",";
			}
			cout << teams[i].id;
			if(i == t - 1) cout << endl;
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, s, n) for (int i = (s); i < (n); i++)
#define all(co) begin(co), end(co)

int main() {
	int m,t,p,r;
while (cin >> m >> t >> p >> r && m) {
	vector<vector<int>> v(t, vector<int>(p));
	rep(i, r) {
		int m, t, p, j; cin >> m >> t >> p >> j;
		t--;
		if (j == 0) {
			if(v[t][p] == 0) v[t][p] = m;
			else v[t][p] = m + -v[t][p] * 20;
		}
		else v[t]--;
	}
	map<int, vector<int>> rank;
	rep(i, t) {
		int s = -accumulate(all(v[i]), 0);
		if(rank.count(s)) rank.push_back(i + 1);
		else rank.insert(s, vector<int>{i+1});
	}
	for(auto it = rank.begin(); it != --rank.end(); it++) {
		rep(i, it->size() - 1) cout << it->at(i) << '=';
		cout << it->back();
		cout << ',';
	}
	{
		auto it = --rank.end();
		rep(i, it->size() - 1) cout << it->at(i) << '=';
		cout << it->back();
	}
	cout << endl;
}

C++: #include <iostream>
#include <algorithm>
#define REP(i, a, n) for(int i = (a); i <= (n); i++)
using namespace std;
typedef pair<int, int> PII;

int M, T, P, R, m, t, p, j, q[51][11];
PII s[51];

int main(void) {
  while(cin >> M >> T >> P >> R, M || T || P || R) {
    REP(i, 1, T) {
      s[i] = PII(P, 0);
      REP(j, 1, P) q[i][j] = 0;
    }

    REP(i, 1, R) {
      cin >> m >> t >> p >> j;
      if(j == 0) {
        if(q[t][p] >= 0) {
          s[t].first--;
          s[t].second += q[t][p] * 20 + m;
        }
      } else {
        q[t][p]++;
      }
    }

    REP(i, 1, T) {
      s[i].first = s[i].first * 100000000 + s[i].second;
      s[i].second = T - i;
    }
    sort(s + 1, s + T + 1);
    REP(i, 1, T) {
      cout << (T - s[i].second);
      if(i < T) cout << (s[i].first == s[i + 1].first ? '=' : ',');
    }
    cout << endl;
  }
}

C++: #include<bits/stdc++.h>
#define f first 
#define sf second.first 
#define ss second.second 
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P > iP;

int main(){
  int t,p,r,b;
  while(cin>>b>>t>>p>>r&&t){
    iP a[51];
    int k[11][51]={};
    a[0]=iP(-1,P(-1,-1));
    for(int i=1;i<=t;i++)a[i]=iP(0,P(0,i));
    for(int i=0;i<r;i++){
      int ti,pi,m,s;
      cin>>m>>ti>>pi>>s;
      if(!s)a[ti].f++,a[ti].sf-=m+k[pi][ti]*20;
      else k[pi][ti]++;
    }
    sort(a+1,a+t+1);
    for(int i=t;i>0;i--){
      cout<<a[i].ss;
      if(i!=1)
	if(a[i-1].f==a[i].f&&a[i-1].sf==a[i].sf)cout<<"=";
	else cout<<",";
    }
    cout<<endl;
  }
  return 0;
}

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

struct team{
	int n, c, t, p;
};

bool operator<(const team team1, const team team2){
	bool rep;
	if(team1.c == team2.c){
		rep = (team1.t == team2.t) ? team1.n > team2.n : team1.t < team2.t;
	}else{
		rep = (team1.c > team2.c);
	}
	return rep;
}

int main(){
	int M, T, P, R;
	while( cin >> M >> T >> P >> R, M || T || P || R ){
		vector<team> teams(T);
		for(int i = 0; i < T; i++){
			teams[i].n = i+1;
			teams[i].c = 0;
			teams[i].t = 0;
			teams[i].p = 0;
		}
		for(int i = 0; i < R; i++){
			int m, t, p, j;
			cin >> m >> t >> p >> j;
			if( j == 0 ){
				teams[t-1].c++;
				teams[t-1].t = m + 20 * teams[t-1].p;
			}else{
				teams[t-1].p++;
			}
		}
		sort(teams.begin(), teams.end());
		cout << teams[0].n;
		for(int i = 1; i < T; i++){
			if( teams[i].c == teams[i-1].c && teams[i].t == teams[i-1].t ) cout << "=";
			else cout << ",";
			cout << teams[i].n;
		}
		cout << endl;
	}
}