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 <vector>
#include <utility>
using namespace std;

int main(){
  int m,t,p,r,i,j,k;
  while(1){
    cin >> m >> t >> p >> r;
    if(m==0)break;
    int ac[t]={},wa[t][p],actime[t]={};
    for(i=0;i<t;i++){
      for(j=0;j<p;j++)wa[i][j]=0;
    }
    for(i=0;i<r;i++){
      int M,T,P,R;
      cin >> M >> T >> P >> R;
      if(R!=0)wa[T-1][P]++;
      else{
        ac[T-1]++;
        actime[T-1]+=wa[T-1][P]*20+M;
      }
    }

    //cout << actime[0] << actime[1] << endl;

    bool flag[t]={};
    int bscore=-1,bfinaltime=-1;
    for(j=0;j<t;j++){
      int team=-1,score=-1,finaltime=300*20;
      for(i=0;i<t;i++){
        if(flag[i]==true)continue;
        if(score<ac[i]){
          team=i;
          score = ac[i];
          finaltime= actime[i];
        }else if(score == ac[i] && finaltime>=actime[i]){
          team=i;
          finaltime=actime[i];
        }
      }
      if(j!=0){
        if(bscore==score && bfinaltime==finaltime)cout << "=";
        else cout << ",";
      }
      cout << team+1;
      flag[team]=true;
      bscore = score;
      bfinaltime=finaltime;
    }
    cout << endl;
  }
  return 0;
}

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

typedef vector<int> vi;
typedef vector<vi> vvi;

#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int M,T,P,R;
    while(cin>>M>>T>>P>>R && M){
        vector<vector<vector<pair<int,bool>>>> v(T,vector<vector<pair<int,bool>>>(P));
        rep(i,R){
            int m,t,p,j;
            cin>>m>>t>>p>>j;
            t--,p--;
            v[t][p].push_back(make_pair(m,j==0));
        }
        // solved, time, id
        vvi rank(T);
        rep(i,T){
            int s = 0;
            int t = 0;
            rep(j,P)if(v[i][j].size()!=0 && v[i][j].back().second){
                s++;
                t+=v[i][j].back().first;
                t+=20*(v[i][j].size()-1);
            }
            rank[i] = vi{s,t,i+1};
        }
        sort(rank.begin(),rank.end(),[](const vi& a, const vi& b){
                if(a[0]!=b[0]) return a[0]>b[0];
                if(a[1]!=b[1]) return a[1]<b[1];
                else return a[2]>b[2];
            });
        cout << rank[0][2];
        rep(i,T-1){
            if(rank[i+1][0]==rank[i][0] && rank[i+1][1]==rank[i][1]){
                cout << "=";
            }
            else cout << ",";
            cout << rank[i+1][2];
        }
        cout << endl;
    }
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
#include <memory>
#include <time.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-9;
const double PI  = acos(-1.0);

struct team{
	int ac,penalty,id;
	vi penalties;
//	team(int ac,int penalty,int id):ac(ac),penalty(penalty),id(id){}
	team(int numP):penalties(vi(numP)),ac(0),penalty(0){}
	bool operator<(const team &other)const{
		if(ac==other.ac){
			if(penalty==other.penalty){
				return id>other.id;
			}else{
				return penalty<other.penalty;
			}
		}else{
			return ac>other.ac;
		}
	}
	bool same(const team &other) const{
		return(ac==other.ac&&penalty==other.penalty);
	}
};


int main(){
	int M,T,P,R;
	while(cin>>M>>T>>P>>R,M|T|P|R){
		vector<team> teams(T,team(P));
		REP(i,T){
			teams[i].id=i+1;
		}
		REP(i,R){
			int m,t,p,j;
			cin>>m>>t>>p>>j;
			t--;p--;
			if(j==0){
				teams[t].ac++;
				teams[t].penalty+=teams[t].penalties[p]+m;
			}else{
				teams[t].penalties[p]+=20;
			}
		}
		sort(ALL(teams));
		cout<<teams[0].id;
		FOR(i,1,T){
			if(teams[i-1].same(teams[i])){
				cout<<"=";
			}else{
				cout<<",";
			}
			cout<<teams[i].id;
		}
		cout<<endl;
	}
}