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++: #define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include <stdio.h>
#include <functional>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

string x(string s, const string cs, const string se) {
	int pos = 0;
	while ((pos = s.find_first_of(se)) != string::npos) {
		s.replace(pos, 1, cs);
	}
	return s;
}

string y(string a) {
	int pos4 = 0, pos9 = 0;
	a = x(a, "3", "5");
	a = x(a, "5", "6");
	a = x(a, "6", "7");
	a = x(a, "7", "8");
	int pos = a.length();
	if ((pos4 = a.find_first_of("4")) != string::npos && (pos9 = a.find_first_of("9")) != string::npos)
	{
		if (pos4 > pos9) {//4>9
			a = a.replace(pos9, 1, "7");
			pos = pos9 + 1;
		}
		else {
			a = a.replace(pos4, 1, "3");
			pos = pos4 + 1;
		}
	}
	else if ((pos4 = a.find_first_of("4")) != string::npos) {
		a = a.replace(pos4, 1, "3");
		pos = pos4 + 1;
	}
	else if ((pos9 = a.find_first_of("9")) != string::npos) {
		a = a.replace(pos9, 1, "7");
		pos = pos9 + 1;
	}
	while (pos != a.length()) {
		a = a.replace(pos, 1, "7");
		pos++;
	}
	return a;
}

int n;
int m;
int aji[100000];

int saiki(){
	return 0;
}

int main(){
	int m, t, p, r;
	while (cin >> m >> t >> p >> r && !(m == 0 && t == 0 && p == 0 && r == 0)){
		vector<pair<int, pair<int, int>>> juni; // 正解数 時間 チーム名(答えのためのvector)
		int teamscore[50]; // 各チームのスコア
		int teamsecond[50]; // 各チームの時間
		int teamincorr[50][2000]; // 各チーム各問題の間違えた回数
		int teamincorrcnt[50]; // 各チームの正解した問題の間違えた回数
		for (int i = 0; i < 50; i++) {
			teamscore[i] = 0;
			teamsecond[i] = 100000;
			teamincorrcnt[i] = 0;
			for (int j = 0; j < 2000; j++) {
				teamincorr[i][j] = 0;
			}
		}
		for (int i = 0; i < r; i++) {
			int mk, tk, pk, jk;
			cin >> mk >> tk >> pk >> jk;
			if (jk == 0) { // 正解
				teamscore[tk - 1]++; // 正解数を増やす
				teamincorrcnt[tk - 1] += teamincorr[tk - 1][pk];
				teamsecond[tk - 1] = 100000 - (mk + 20 * teamincorrcnt[tk - 1]);
			}
			else { // 間違い
				teamincorr[tk - 1][pk]++;
			}
		}
		for (int i = 0; i < t; i++) {
			juni.push_back(make_pair(teamscore[i], make_pair(teamsecond[i], i + 1)));
		}
		sort(juni.begin(), juni.end());

		int score = -1;
		int jikan = -1;
		for (int i = t - 1; i >= 0; i--) {
			if (i != t - 1) {
				if (score == juni[i].first && jikan == juni[i].second.first) {
					cout << "=";
				}
				else {
					cout << ",";
				}
			}
			cout << juni[i].second.second;
			score = juni[i].first;
			jikan = juni[i].second.first;
		}
		cout << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;
int main(void) {
  int i,j;
  int m,t,p,r;
  while(1){
    cin>>m>>t>>p>>r;
    if(m==0 && t==0 && p==0 && r==0)break;
    pair<pii,int> p[50];
    rep(i,t){
      p[i].second=i+1;
      p[i].first.first=p[i].first.second=0;
    }
    int penalty[50][10]={};//team,prob                       
    rep(i,r){
      int time,team,pn,judge;
      cin>>time>>team>>pn>>judge;
      team--;pn--;
      if(judge){//WA                                         
        penalty[team][pn]++;
      }else{//AC                                             
        p[team].first.first++;
        p[team].first.second-=time+penalty[team][pn]*20;
      }
    }
    sort(p,p+t);
    cout<<p[t-1].second;
    for(i=t-2;i>=0;i--)
      if(p[i].first.first==p[i+1].first.first &&
         p[i].first.second==p[i+1].first.second)
        cout<<"="<<p[i].second;
      else
        cout<<","<<p[i].second;
    cout<<endl;
  }
}

C++: #include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
#define MOD 1000000007
using namespace std;
int time_sum[100][100],
    is_ac[100][100];
signed main() {
  int N, T, P, R;
  while (cin>>N>>T>>P>>R, N+T+P+R) {
    for (int i = 0; i < 100; i++) {
      for (int j = 0; j < 100; j++) {
        time_sum[i][j] = 0;
        is_ac[i][j] = 0;
      }
    }

    for (int i = 0; i < R; i++) {
      int m, t, p, j;
      cin >> m >> t >> p >> j;
      t--;p--;
      if (j != 0) {
        time_sum[t][p] += 20; 
      } else {
        time_sum[t][p] += m;
        is_ac[t][p] = 1;
      }
    }
    
    vector<pair<int,int>> ans(T);
    for (int i = 0; i < T; i++) {
      int time = 0;
      for (int j = 0; j < P; j++) {
        time += is_ac[i][j]*time_sum[i][j];
        time -= is_ac[i][j]*R*100;
      }
      ans[i] = make_pair(time, -(i+1));
    }
    sort(ans.begin(), ans.end());
    for (int i = 0; i < T-1; i++) {
      cout << -ans[i].second;
      if (ans[i+1].first == ans[i].first) {
        cout << "=";
      } else {
        cout << ",";
      }
    }
    cout << -ans[T-1].second << endl;
     
  }
}