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 push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 22;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

struct TeamResult {
  int teamnumber;
  int num, time, ptime;
  vi penalty;

  TeamResult() {

  }

  void init(int p, int t) {
    penalty.resize(p, 0);
    teamnumber = t;
    num = 0;
    time = 0;
    ptime = 0;
  }

  void update(int m, int p, int j) {
    if(j == 0) {
      num++;
      time += m + penalty[p] * 20;
    } else {
      penalty[p]++;
    }
  }
};


bool operator>(const TeamResult &t1, const TeamResult &t2) {
  if(t1.num == t2.num) {
    if(t1.time == t2.time) {
      return t1.teamnumber > t2.teamnumber;
    } else {
      return t1.time < t2.time;
    }
  } else {
    return t1.num > t2.num;
  }
}

bool operator==(const TeamResult &t1, const TeamResult &t2) {
  return (t1.num == t2.num && t1.time == t2.time);
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  while(1) {
    int m, t, p, r; cin >> m >> t >> p >> r;
    if(m == 0 && t == 0 && p == 0 && r == 0) break;
    vector<TeamResult> team(t);
    REP(i, t) {
      team[i].init(p, i);
    }

    REP(i, r) {
      int m, t, p, j;
      cin >> m >> t >> p >> j;
      team[t-1].update(m, p-1, j);
    }

    sort(ALL(team), greater<TeamResult>());

    cout << team[0].teamnumber + 1;
    FOR(i, 1, t) {
      if(team[i] == team[i-1]) cout << "=";
      else cout << ",";
      cout << team[i].teamnumber + 1;
    }
    cout << endl;
  }
}

C++: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define INF 1LL << 61
#define MAX (1LL << 31) -1
#define MOD 1000000007

typedef long long ll;
typedef pair<int,int> pi;
//typedef pair<pair<int,int>,ll> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
template<class T,class U>bool inline chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool inline chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll
int dx[]={1,-1,0,0},dy[]={0,0,-1,1};

int pena[55][11];
pi kekka[51];

signed main(){
    while(true){
        int M,T,P,R;
        cin>>M>>T>>P>>R;
        if(M==0 && T==0 && P==0 && R==0) return 0;
        vector<vector<int>> pena(T+1,vector<int>(P+1,0));
        vector<pi> kekka(T+1,pi(0,0));
        while(R--){
            int m,t,p,j;
            cin>>m>>t>>p>>j;
            if(j==0){
                kekka[t].first++;
                kekka[t].second+=m+pena[t][p]*20;
            }else{
                pena[t][p]++;
            }
        }
        vector< tuple<int,int,int> > ans;
        for(int i=1;i<=T;i++){
            ans.emplace_back(-kekka[i].first,kekka[i].second,-i);
        }
        sort(ans.begin(),ans.end());
        for(int i=0;i<T;i++){
            cout<<-get<2>(ans[i]);
            if(i!=T-1){
                if(get<0>(ans[i])==get<0>(ans[i+1]) && get<1>(ans[i])==get<1>(ans[i+1]) ){
                    cout<<"=";
                }else cout<<",";
            }
        }
        cout<<endl;
    }
}

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

struct agg{
  int sol,tim,num;
  int wrg[11];
};

class ctr{
public:
  bool operator()(const agg& left,const agg& right)const{
    if(left.sol == right.sol && left.tim == right.tim){
      return left.num > right.num;
    }
    else if(left.sol == right.sol) return left.tim < right.tim;
    else return left.sol > right.sol; 
  }
};

void init(int n,vector<agg> *trg){
  for(int i=1;i<n+1;i++){
    (*trg)[i].sol = 0;
    (*trg)[i].tim = 0;
    (*trg)[i].num = i;
    memset((*trg)[i].wrg,0,sizeof((*trg)[i].wrg));
  }
}

int main(){
  int M,T,P,R;
  while(cin >> M >> T >> P >> R,M||T||P||R){
    vector<agg>info(T+1);
    init(T,&info);

    while(R--){
      int m,t,p,j;
      cin >> m >> t >> p >> j;
      if(j == 0){
	info[t].tim += info[t].wrg[p] * 20 + m;
	info[t].sol++;
      }
      else info[t].wrg[p]++;
    }

    sort(info.begin()+1,info.end(),ctr());
    for(int i=1;i<T;i++){
      cout << info[i].num;
      cout << (info[i].sol == info[i+1].sol && info[i+1].tim == info[i].tim ? '=' : ',');
    }
    cout << info[T].num <<  endl;
  }
}