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 MAX 51
#define PROB 11

using namespace std;

int Task[MAX][PROB];
int Solved[MAX];
int sum[MAX];

bool Compare(const std::pair<std::pair<int, int>, int> &a,
             const std::pair<std::pair<int, int>, int> &b
             ) {
    if (a.first.first > b.first.first) { return true; }
    else if (a.first.first == b.first.first) {
        if (a.first.second < b.first.second) { return true; }
        else if (a.first.second == b.first.second) {
            if (a.second > b.second) { return true; }
            else { return false; }
        }
        else { return false; }
    } else {
        return false;
    }
}


int main() {


    int N, T, P, R;

    int elTime, teamNum, probNum, judge;

    while (cin >> N >> T >> P >> R, N) {


        std::memset(Task, 0, sizeof(Task));
        std::memset(Solved, 0, sizeof (Solved));
        std::memset(sum, 0, sizeof (Solved));




        for (int i = 0; i < R; i++) {
            std::cin >> elTime >> teamNum >> probNum >> judge;
            if (judge == 0) {
                sum[teamNum] += elTime + Task[teamNum][probNum] * 20;
                Solved[teamNum]++;
            } else {
                Task[teamNum][probNum]++;
            }
        }

        std::vector<std::pair<std::pair<int, int>, int> > vt;

        for (int i = 1; i <= T; i++) {
            vt.push_back(std::make_pair(std::make_pair(Solved[i], sum[i]), i));
        }

        sort(vt.begin(), vt.end(), Compare);

        for (unsigned long i = 0; i < vt.size() - 1; i++) {
            std::cout << vt[i].second;
            if (vt[i].first.first == vt[i+1].first.first && vt[i].first.second == vt[i+1].first.second) std::cout << "=";
            else { std::cout <<","; }
        }
        std::cout << vt[vt.size()-1].second << std::endl;

    }

    return 0;

}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>

#define INF 999999999
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define MOD(x) (x%(mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

/*---------------------------------------------------*/

bool debug=false;

pair<pi,int> data[55];
int miss[55][15];
int M,T,P,R;

void init(){
  rep(i,55){
    data[i].first.first=0;
    data[i].first.second=0;
    data[i].second=i+1;
    rep(j,15){
      miss[i][j]=0;
    }
  }
}

void solve(){
  int m,t,p,j;
  rep(i,R){
    cin>>m>>t>>p>>j;
    if(j==0&&miss[t-1][p]!=-1){
      data[t-1].first.first++;
      data[t-1].first.second-=(m+miss[t-1][p]*20);
      miss[t-1][p]=-1;
    }else if(miss[t-1][p]!=-1){
      miss[t-1][p]++;
    }
  }

  sort(data,data+T);reverse(data,data+T);
  
  if(debug){cout<<"tema ";rep(i,T)cout<<data[i].second<<" ";cout<<endl;}
  if(debug){cout<<"solv ";rep(i,T)cout<<data[i].first.first<<" ";cout<<endl;}
  if(debug){cout<<"time ";rep(i,T)cout<<data[i].first.second<<" ";cout<<endl;}
  
  cout<<data[0].second;
  REP(i,1,T){
    if(data[i].first.first==data[i-1].first.first&&data[i].first.second==data[i-1].first.second){
      cout<<'='<<data[i].second;
    }else{
      cout<<','<<data[i].second;
    }
  }
  cout<<endl;
}

int main(){

  while(cin>>M>>T>>P>>R){
    if(M==0&&T==0&&P==0&&R==0)break;
    init();
    solve();
  }
  
  return 0;
}