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>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

struct team{
  int id,ac,sec;
  vector<ll> v;
  bool operator<(const team& a){
    if(ac == a.ac){
      if(sec == a.sec) return id < a.id;
      return sec > a.sec;
    }
    return ac < a.ac;
  }
  bool operator>(const team& a){
    if(ac == a.ac){
      return sec > a.sec;
    }
    return ac < a.ac;
  }
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll M,T,P,R;
  while(cin >> M >> T >> P >> R && M+T+P+R){
    vector<team> v(T);
    rep(i,T){
      v[i].id = i+1;
      v[i].v.resize(P);
    }
    ll m,t,p,j;
    rep(i,R){
      cin >> m >> t >> p >> j;
      if(j == 0){
        v[t-1].ac++;
        v[t-1].sec += m + 20 * v[t-1].v[p-1];
      }
      else{
        v[t-1].v[p-1]++;
      }
    }
    sort(all(v));
    reverse(all(v));
    cout << v[0].id;
    REP(i,1,T){
      if(v[i] > v[i-1]){
        cout << ',' << v[i].id ;
      }
      else{
        cout << '=' << v[i].id ;
      }
    }
    cout << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
typedef struct{
    int time;
    int num;
    int qst;
    int judge;
}data;
typedef  pair<int, pair<int, int>>pi; //  seikai time number
int main(){
    int m,t,p,r;
    while(cin>>m>>t>>p>>r,m+t+r+p){
    vector<data>v;
    vvi team(60,vi(60,0));
    vvi lost(1000,vi(100,0));
    rep(i,r){
        data temp;
        cin>>temp.time>>temp.num>>temp.qst>>temp.judge; v.push_back(temp);
        if(!(v[i].judge)){
            team[v[i].num][v[i].qst]=1;
            lost[v[i].num][v[i].qst]+=v[i].time;
        }else{
            lost[v[i].num][v[i].qst]+=20;
        }
    }
    vector<pi>ans(100,pi(0,pii(-INF,0)));

    for(int i=1; i<=t;i++){
        ans[i].second.second=i;
        for(int j=1; j<=p;j++)
            if(team[i][j]){
                ans[i].first++; ans[i].second.first-=lost[i][j]; ans[i].second.second=i;
        }
    }
    sort(ans.begin()+1,ans.begin()+t+1,greater<pi>());
        rep(i,t){
            if(i){
                if(ans[i].first==ans[i+1].first&&ans[i].second.first==ans[i+1].second.first)
                    cout<<"=";
                else
                    cout<<",";
            }
            cout<<ans[i+1].second.second;
        }
        cout<<endl;
    }
}