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 <cstring>

using namespace std;

struct Result {
  int time, prob, No;
  Result () {
    time = prob = No = 0;
  }
  Result (int time, int prob, int No) : time(time), prob(prob), No(No) {}
};

bool comp(const Result &r1, const Result &r2) {
  
  if (r1.prob > r2.prob) {
    return true;
  } else if (r1.prob == r2.prob) {
    if (r1.time < r2.time) {
      return true;
    } else if (r1.time == r2.time) {
      return r1.No > r2.No;
    } else {
      return false;
    }
  } else {
    return false;
  }
  /*
  if (r1.prob == r2.prob) return r1.time < r2.time; 
  return r1.prob > r2.prob;
  */
}

int M, T, P, R, m, t, p, j, penalty[60][20];
Result r[60];

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  while (cin >> M >> T >> P >> R, M | T | P | R) {
    memset(penalty, 0, sizeof(penalty));
    for (int i = 0; i < T; ++i) r[i] = Result(0, 0, i);
    for (int i = 0; i < R; ++i) {
      cin >> m >> t >> p >> j;

      if (j == 0) {
        r[t-1].prob++;
        r[t-1].time += m + penalty[t-1][p-1];
      }
      else {
        penalty[t-1][p-1] += 20;
      }
    }
    /*cerr << "==========" << endl;
    for (int i = 0; i < T; ++i) cout << r[i].No + 1<< " " << r[i].time << " " << r[i].prob << endl;
    */
    
    sort(r, r + T, comp);

    /*cerr << "==========" << endl;
      for (int i = 0; i < T; ++i) cout << r[i].No << " " << r[i].time << " " << r[i].prob << endl;*/
    /* */
    for (int i = 0; i < T; ++i) {
      if (i == 0) {
        cout << r[i].No+1;
      }
      else {
        if (r[i-1].time == r[i].time && r[i-1].prob == r[i].prob) {
          cout << "=";
        }
        else {
          cout << ",";
        }
        cout << r[i].No+1;
      }
    }
    cout << endl;
    /* */
  }

  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <complex>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cmath>
#include <time.h>
#include <tuple>
#define all(c) ((c).begin(),(c).end())
#define rall(c) ((c).rbegin(),(c).rend())
//#define sort(v,n) sort(v,v+n)
#define ll long long
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int m, t, p, r;

int main() {
	while (cin >> m >> t >> p >> r, m) {
		int wa[55][11];
		bool ac[55][11];
		vector<pair<int,pair<int,int>>> vp(t);
		for (int i = 0; i < t; i++) {
			vp[i].first = 0;
			vp[i].second.first = 0;
			vp[i].second.second = i+1;
		}
		for (int i = 0; i < 55; i++) {
			for (int j = 0; j < 11; j++) {
				ac[i][j] = 0;
				wa[i][j] = 0;
			}
		}
		for (int i = 0; i < r; i++) {
			int m1, t1, p1, j;
			cin >> m1 >> t1 >> p1 >> j;
			if (j == 0) {
					ac[t1][p1] = 1;
					vp[t1-1].first++;
					vp[t1-1].second.first -= (m1 + 20 * wa[t1][p1]);
			}
			else {
				wa[t1][p1]++;
			}
		}
		sort(vp.rbegin(), vp.rend());
		int preac = -1;
		int pret = inf;
		for (int i = 0; i < t; i++) {
			if (preac != vp[i].first) {
				if (i != 0)cout << ",";
				cout << vp[i].second.second;
				pret = vp[i].second.first;
				preac = vp[i].first;
			}
			else if (pret != vp[i].second.first) {
				if (i != 0)cout << ",";
				cout << vp[i].second.second;
				preac = vp[i].fi;
				pret = vp[i].second.first;
			}else {
					cout << "=" << vp[i].second.second;
				}
			}
		cout << endl;
		}
	return 0;
	}

C++: #include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
struct data{
    int ac,all_time,n;
    data(int a,int b,int c):ac(a),all_time(b),n(c){}
    data(){}
    bool operator<(const data &d)const{
        return ac<d.ac||(ac==d.ac&&(all_time>d.all_time||all_time==d.all_time&&n<d.n));
    }
};
int main(){
    int M,T,P,R;
    while(scanf("%d%d%d%d",&M,&T,&P,&R),M||T||P||R){
        int wa[50][10];
        vector<data>V(T);
        for(int i=0;i<T;i++)V[i]=data(0,0,i+1);
        fill_n(*wa,500,0);
        while(R--){
            int m,t,p,j;
            scanf("%d%d%d%d",&m,&t,&p,&j);
            if(j){
                t--;p--;
                wa[t][p]++;
            }
            else{
                t--;p--;
                V[t].ac++;
                V[t].all_time+=m+wa[t][p]*20;
            }
        }
        sort(V.begin(),V.end());
        reverse(V.begin(),V.end());
        printf("%d",V[0].n);
        for(int i=1;i<T;i++){
            if(V[i].ac==V[i-1].ac&&V[i].all_time==V[i-1].all_time){
                printf("=");
            }
            else{
                printf(",");
            }
            printf("%d",V[i].n);
        }
        puts("");
    }
}