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 rep(i,n) for(int i=0;i<(n);i++)
// #define fi first
// #define se second
// #define pb push_back
// #define mp make_pair

using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using pii = pair<int,int>;

template<typename T> ostream& operator<< (ostream& os,const vector<T>& vec){ os << "{"; for(T v:vec) os << v << ","; os << "}"; } template<typename T> ostream& operator<< (ostream& os,const set<T>& st){ os << "{"; for(T v:st) os << v << ","; os << "}"; }
template<typename T,typename U> ostream& operator<< (ostream& os,const pair<T,U>& p){ os << "{" << p.first << "," << p.second << "}"; return os; }

struct Result {
    int num;
    int ac;
    int pen;

    Result() : num(-1), ac(0), pen(0) {}

    bool operator < (const Result& o) const {
        return ac == o.ac ? pen == o.pen ? num > o.num : pen < o.pen : ac > o.ac;
    }
};

int main(){
    int M, T, P, R;
    while (true) {
        cin >> M >> T >> P >> R;
        if (M == 0 && T == 0 && P == 0 && R == 0) break;

        int ac[50][10], wa[50][10], pen[50][10];
        for (int j = 0; j < T; ++j) {
            fill(ac[j], ac[j]+P, 0);
            fill(wa[j], wa[j]+P, 0);
            fill(pen[j], pen[j]+P, -1);
        }

        for (int i = 0; i < R; ++i) {
            int m, t, p, j;
            cin >> m >> t >> p >> j;
            --t; --p;
            if (j == 0 && ac[t][p] == 0) {
                ac[t][p] = 1;
                pen[t][p] = m;
            }
            if (j != 0 == ac[t][p] == 0) {
                wa[t][p]++;
            }
        }

        Result res[50];
        for (int j = 0; j < T; ++j) {
            res[j].num = j+1;
            for (int k = 0; k < P; ++k) {
                if (ac[j][k] == 1) {
                    res[j].ac ++;
                    res[j].pen += wa[j][k] * 20 + pen[j][k];
                }
            }
        }

        sort(res, res+T);
        cout << res[0].num;
        for (int j = 1; j < T; ++j) {
            if (res[j-1].ac == res[j].ac && res[j-1].pen == res[j].pen) {
                cout << "=";
            } else {
                cout << ",";
            }
            cout << res[j].num;
        }
        cout << endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int M, T, P, R;
  while (cin >> M >> T >> P >> R, M) {
    vector<vector<int>> time(T, vector<int>(P));
    vector<vector<int>> ac(T, vector<int>(P));
    while (R--) {
      int m, t, p, j;
      cin >> m >> t >> p >> j;
      --t, --p;
      if (j == 0) {
        time[t][p] += m;
        ac[t][p] = 1;
      } else {
        time[t][p] += 20;
      }
    }
    vector<pair<int, int>> v(T);
    for (int t = 0; t < T; ++t) {
      int sum = 0;
      for (int p = 0; p < P; ++p) {
        if (ac[t][p]) {
          sum += time[t][p];
        }
      }
      v[t] = {accumulate(begin(ac[t]), end(ac[t]), 0), -sum};
    }
    vector<int> idx(T);
    iota(rbegin(idx), rend(idx), 0);
    stable_sort(begin(idx), end(idx), [&](int l, int r) {
      return v[l] > v[r];
    });
    bool first = true;
    for (int i = 0; i < T; ++i) {
      int t = idx[i];
      if (not exchange(first, false)) {
        cout << (v[t] == v[idx[i - 1]] ? '=' : ',');
      }
      cout << t + 1;
    }
    cout << '\n';
  }
}

C++: #include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;++i)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(x) x.begin(),x.end()

struct team {
    int id, pro, tm;
    team(int id, int pro, int tm) : id(id), pro(pro), tm(tm) {}
    bool operator < (const team& a) const {
	if (pro != a.pro) { return pro < a.pro; }
	if (tm != a.tm) { return tm > a.tm; }
	if (id != a.id) { return id < a.id; }
    }
};

vector<team> vec;

int M, T, P, R;
int pn[50][10];
int ac[50][10];

int main() {
    while (scanf("%d %d %d %d", &M, &T, &P, &R), M) {
	vec.clear();
	memset(pn, 0, sizeof(pn));
	memset(ac, -1, sizeof(ac));

	rep(i, R) {
	    int m, t, p, j;
	    scanf("%d %d %d %d", &m, &t, &p, &j);
	    --t; --p;
	    if (j) ++pn[t][p];
	    else ac[t][p] = m;
	}

	rep(i, T) {
	    int sol = 0, tm = 0;
	    rep(j, P) {
		if (ac[i][j] == -1) continue;
		++sol;
		tm += ac[i][j] + pn[i][j] * 20;
	    }
	    vec.push_back(team(i + 1, sol, tm));

	    //cout << i + 1 << " " << sol << " " << tm << endl;
	}

	sort(ALL(vec));
	reverse(ALL(vec));

	int i;
	for (i = 0; i < T; ++i) {
	    if (i) printf(",");
	    team &tt = vec[i];
	    int j = i;

	    while (j + 1 < T && vec[j + 1].pro == vec[i].pro && vec[j + 1].tm == vec[i].tm) ++j;

	    for (int k = i; k <= j; ++k) {
		if (k != i) printf("=");
		printf("%d", vec[k].id);
	    }
	    i = j;
	}
	puts("");
    }
    return 0;
}