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 <vector>
#include <string>
using namespace std;
typedef long long int ll;

int tim[55];
int solved[55][12];
int WA[55][12];
int cnt[55];
int m,t,p,r;
int main(){
	while(1){
		cin >> m >>t >> p >>r;
		if(m==0)break;
		for(int i=0;i<t;i++){
			tim[i]=0;
			cnt[i]=0;
		}
		for(int i=0;i<t;i++){
			for(int j=0;j<p;j++){
				solved[i][j]=0;
				WA[i][j]=0;
			}
		}
		for(int i=0;i<r;i++){
			int mk,tk,pk,jk;
			cin >> mk >> tk >> pk >> jk;
			tk--; pk--;
			if(jk==0){
				solved[tk][pk]=1;
				tim[tk]+=mk;
			}
			else{
				WA[tk][pk]++;
			}
		}
		for(int i=0;i<t;i++){
			for(int j=0;j<p;j++){
				if(solved[i][j]){
					cnt[i]++;
					tim[i]+=WA[i][j]*20;
				}
			}
		}
		vector<pair<int,pair<int,int> > > rank;
		for(int i=0;i<t;i++){
			rank.push_back(make_pair(-cnt[i],make_pair(tim[i],-(i+1))));
		}
		sort(rank.begin(),rank.end());
		for(int i=0;i<t;i++){
			if(i)cout << ",";
			cout << -rank[i].second.second;
			while(i+1<t&&rank[i].first==rank[i+1].first&&rank[i].second.first==rank[i+1].second.first){
				i++;
				cout << "=";
				cout << -rank[i].second.second;
			}
		}
		cout << endl;
	}
}

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

int main(void){
  while(true){
    int M, T, P, R;
    cin >> M >> T >> P >> R;
    if(M == 0 && T == 0 && P == 0 && R == 0){ break; }


    vector<vector<pair<bool, int> > > status(T, vector<pair<bool, int> >(P, make_pair(false, 0)));
    for(int i = 0; i < R; i++){
      int m, t, p, j;
      cin >> m >> t >> p >> j;
      --t;
      --p;
      if(status[t][p].first){ continue; }
      if(j == 0){
        status[t][p].first = true;
        status[t][p].second += m;
      }
      else{ status[t][p].second += 20; }
    }

    vector<pair<pair<int, int>, int> > team(T, make_pair(make_pair(0, 0), 0));
    for(int i = 0; i < T; i++){
      for(int j = 0; j < P; j++){
        if(status[i][j].first){
          --team[i].first.first;
          team[i].first.second += status[i][j].second;
        }
      }
      team[i].second = -(i + 1);
    }
    
    sort(team.begin(), team.end());
    for(int i = 0; i < T; i++){
      if(i != 0){
        if(team[i - 1].first.first == team[i].first.first
           && team[i - 1].first.second == team[i].first.second){
          cout << "=";
        }else{ cout << ","; }
      }
      cout << -team[i].second;
    }
    cout << endl;
  }

  return 0;
}

C++: 
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
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(); }
template<class T> inline T sqr(T x) { return x*x; }
typedef pair<int, int> P;
typedef long long ll;
typedef unsigned long long ull;

#define For(i,a,b)	for(int (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define rall(a)		(a).rbegin(), (a).rend()
#define sz(a)		(sizeof(a))
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

bool cheak(int x, int y, int xMax, int yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; }
const int dx[4] = { -1, 0, 1, 0 }, dy[4] = { 0, 1, 0, -1 };
const int mod = 1000000007;
const int INF = 1e9;

int main()
{
	int m, t, p, r;

	while (cin >> m >> t >> p >> r && m){

		const int M = 51;
		tuple<int,int,int> d[M]; clr(d);
		rep(i, M)get<2>(d[i]) = i + 1;

		int w[M][M]; clr(w);

		rep(_, r){
			int tm, tt, tp, tj;
			cin >> tm >> tt >> tp >> tj;
			tt--;
			if (tj){
				w[tt][tp]++;
			}
			else{
				get<0>(d[tt])++;
				get<1>(d[tt]) -= w[tt][tp] * 20 + tm;
			}
		}
		sort(d, d + t,greater<tuple<int,int,int>>());
		rep(i, t){
			cout << get<2>(d[i]);
			For(j, i + 1, t){

				if (get<0>(d[i]) == get<0>(d[j]) &&
					get<1>(d[i]) == get<1>(d[j])){
					cout << "=" << get<2>(d[j]);
					i++;
				}

			}
			if (i != t-1)
			cout << ",";
		}

		cout << endl;
	}

	return 0;
}