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 <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
struct square {
	int s, t, u; // solved, time, team
	square() : s(0), t(0), u(0) {}
	square(int p, int q, int r) : s(p), t(q), u(r) {}
};
bool operator==(square s1, square s2) { return s1.s == s2.s && s1.t == s2.t; }
bool operator!=(square s1, square s2) { return !(s1 == s2); }
bool operator<(square s1, square s2) {
	if(s1.s != s2.s) return s1.s > s2.s;
	if(s1.t != s2.t) return s1.t < s2.t;
	return s1.u > s2.u;
}
int T, N, P, Q, t, n, p, q;
int main() {
	while(scanf("%d%d%d%d", &T, &N, &P, &Q), N) {
		square d[50]; int v[50][10]; memset(v, 0, sizeof(v));
		for(int i = 0; i < N; i++) d[i] = square(0, 0, i + 1);
		for(int i = 0; i < Q; i++) {
			scanf("%d%d%d%d", &t, &n, &p, &q);
			if(q != 0) v[n - 1][p - 1]++;
			else d[n - 1].s++, d[n - 1].t += t + v[n - 1][p - 1] * 20;
		}
		sort(d, d + N);
		printf("%d", d[0].u);
		for(int i = 1; i < N; i++) {
			if(d[i - 1] != d[i]) printf(",%d", d[i].u);
			else printf("=%d", d[i].u);
		}
		printf("\n");
	}
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
using namespace std;
/*int p = 998244353;*/
int p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<pin,int>
#define V vector
#define Endl endl
#define veb vector<bool>
#define sq(a) (a)*(a)
#define rev(s) reverse(s.begin(),s.end())
#define end_pr(s) cout << s <<endl;return 0
#define itn int
int RE() {
	vel v(3, 2);
	return v.at(4);
}
int ru(int a, int r) {
	if (r == 0) { return 1; }
	int ans = ru(a, r / 2);
	ans *= ans; ans %= p;
	if (r % 2 == 1) { ans *= a; }
	return ans % p;
}
int inv(int a) {
	return ru(a,p - 2);
}
vel dis(int mid1, vvel &way) {
	int n = way.size();
	vel dist(n, -1); dist[mid1] = 0;
	queue<int> q;
	q.push(mid1);
	while (!q.empty()) {
		int st = q.front(); q.pop();
		rep(i, way[st].size()) {
			int to = way[st][i];
			if (dist[to] == -1) {
				dist[to] = dist[st] + 1;
				q.push(to);
			}
		}
	}
	return dist;
}
pin most_far(int now, int n, vvel &way) {
	vel dist1 = dis(now, way);
	pin ans = mkp(-1, 0);
	rep(i, n) {
		if (dist1[i] > ans.first) { ans = mkp(dist1[i], i); }
	}
	return ans;
}

template<typename T>
V<T> uni(V<T> &v) {
	if (v.size() == 0) { return v; }
	sor(v);
	V<T> ans(1, v[0]);
	for (int i = 1; i < v.size(); i++) {
		if (v[i] != v[i - 1]) { ans.push_back(v[i]); }
	}
	v = ans;
	return v;
}
int s_gcd(int a, int b) {
	if (b == 0) { return a; }
	return s_gcd(b, a%b);
}
int gcd(int a, int b) {
	a = abs(a);
	b = abs(b);
	if (a < b) { swap(a, b); }
	return s_gcd(a, b);
}
signed main() {
	while (true) {
		int m, t, p, r;
		cin >> m >> t >> p >> r;
		if (m == 0) { break; }
		vvel time(t, vel(p, -1));
		vvel pena(t, vel(p, 0));
		rep(i, r) {
			int m1, t1, p1, j1;
			cin >> m1 >> t1 >> p1 >> j1;
			t1--; p1--;
			if (j1 != 0) {
				pena[t1][p1]++;
			}
			else {
				time[t1][p1] = m1;
			}
		}
		vel count(t, 0);
		vel sum_time(t, 0);
		V<qin> ret(t);
		rep(i, t) {
			rep(j, p) {
				if (time[i][j] != -1) {
					count[i]++;
					sum_time[i] += time[i][j];
					sum_time[i] += pena[i][j] * 20;
				}
			}
			ret[i] = mkp(mkp(count[i], -sum_time[i]), i);
		}
		sor(ret); rev(ret);
		cout << ret[0].second+1;
		for (int i = 1; i < t; i++) {
			if (ret[i].first == ret[i - 1].first) {
				cout << "=" << ret[i].second+1;
			}
			else {
				cout << "," << ret[i].second+1;
			}
		}
		cout << endl;
	}
}

C++: #include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <memory>
#include <cstring>
#include <cassert>
#include <numeric>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define REP2(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(S) (S).begin(), (S).end()
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  int M, T, P, R;
  while (cin >> M >> T >> P >> R && M + T + P + R > 0){
    vector<int> sum(T);
    vector<int> num(T);
    vector<vector<int> > wa(T, vector<int>(P));
    REP(i, R){
      int m, t, p, j;
      cin >> m >> t >> p >> j;
      t--, p--;
      if (j == 0){
        num[t]++;
        sum[t] += wa[t][p] * 20 + m;
      } else {
        wa[t][p]++;
      }
    }
    vector<tuple<int, int, int> > vp;
    REP(i, T){
      vp.push_back(make_tuple(-num[i], sum[i], -i));
    }
    sort(ALL(vp));

    REP(i, T){
      if (i > 0){
        if (get<0>(vp[i]) == get<0>(vp[i - 1]) && get<1>(vp[i]) == get<1>(vp[i - 1])){
          cout << "=";
        } else {
          cout << ",";
        }
      } 
      cout << - get<2>(vp[i]) + 1;
    }
    cout << endl;
  }
  return 0;
}