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 <vector>
#include <map>

using std::cin;
using std::cout;
using std::endl;
using std::vector;
using std::map;

struct Pair {
	public:
		int a, b;
		void set(int, int);
};
inline void Pair::set(int _a, int _b) {
	a = _a;
	b = _b;
}
inline bool operator< (const Pair& left, const Pair& right) {
	if (left.a != right.a) {
		return (left.a < right.a);
	} else {
		return (right.b < left.b);
	}
}
inline bool operator== (const Pair& left, const Pair& right) {
	if (left.a == right.a and left.b == right.b) {
		return true;
	}
}

int main(void) {
	while (1) {
		int M, T, P, R;
		cin >> M >> T >> P >> R;
		if (M == 0 and T == 0 and P == 0 and R == 0) {
			break;
		}

		vector<int> correct_num(T, 0);
		vector<int> time(T, 0);
		vector<int> penalty(T, 0);
		vector<vector<int>> wrong(T, vector<int>(P, 0));
		map<Pair, vector<int>> rank;
		for (int i = 0; i < R; i++) {
			int m, t, p, j;
			cin >> m >> t >> p >> j;
			t--;
			p--;

			if (j == 0) {
				//time[t] = m;
				time[t] += m;
				correct_num[t]++;
				if (wrong[t][p] != 0) {
					penalty[t] += wrong[t][p];
				}
			} else {
				wrong[t][p]++;
			}
		}
		for (int i = 0; i < T; i++) {
			time[i] += 20 * penalty[i];
			Pair pair;
			pair.set(correct_num[i], time[i]);
			rank[pair].push_back(i+1);
		}

		for (auto itr_map = rank.rbegin(); itr_map != rank.rend(); ++itr_map) {
			//cout << itr_map->first.a << ":" << itr_map->first.b << endl;
			if (itr_map != rank.rbegin()) {
				cout << ",";
			}
			for (auto itr_vec = itr_map->second.rbegin(); itr_vec != itr_map->second.rend(); ++itr_vec) {
				if (itr_vec != itr_map->second.rbegin()) {
					cout << "=";
				}
				cout << *itr_vec;
				//cout << endl;
			}
		}
		cout << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <complex>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
const int INF = 1<<28;

struct team {
	int no, ac, wa[10], time;
	bool operator < (const team& a) const {
		if(ac == a.ac) {
			if(time == a.time)
				return no > a.no;
			else
				return time < a.time;
		}
		else
			return ac > a.ac;
	}
};

int main() {
	int M, T, P, R;
	while(cin >> M >> T >> P >> R, M|T|P|R) {
		vector<team> vt;
		REP(i, T) {
			team t;
			t.no = i + 1;
			t.ac = t.time = 0;
			memset(t.wa, 0, sizeof(t.wa));
			vt.push_back(t);
		}
		REP(i, R) {
			int m, t, p, j;
			cin >> m >> t >> p >> j;
			if(j)
				vt[t-1].wa[p-1]++;
			else {
				vt[t-1].ac++;
				vt[t-1].time += m + vt[t-1].wa[p-1] * 20;
			}
		}
		sort(vt.begin(), vt.end());
		int a = vt[0].ac, t = vt[0].time;
		cout << vt[0].no;
		FOR(i, 1, vt.size()) {
			if(vt[i].ac == a && vt[i].time == t)
				cout << '=';
			else {
				a = vt[i].ac;
				t = vt[i].time;
				cout << ',';
			}
			cout << vt[i].no;
		}
		cout << endl;
//		REP(i, vt.size()) cout << vt[i].no << ' ' << vt[i].ac << ' ' << vt[i].time << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

struct team{
	int num;
	int ans;
	double time;
};

bool hikaku(const team &right,const team &left){
 if(right.ans == left.ans){
 	if(right.time == left.time){
 		return right.num > left.num;
 	}
 	return right.time < left.time;
 }
 else return left.ans < right.ans;
}

int main(){
	int t,p,r,M;
	int wrong[52][12];
	int res[52];
	double pe[52];
	vector<team> v;
	int tid,pid,time;
	int hantei;
	team te;
	while(1){
		cin >> M >> t >> p >> r;
		if(M == 0)break;
		for(int i = 0;i <= t;i++){
			res[i] = 0;
			pe[i] = 0;
			for(int j = 0;j <= p;j++){
				wrong[i][j] = 0;	
			}
		}
		v.clear();
		for(int i = 0;i < r;i++){
			cin >> time >> tid >> pid >> hantei;
			if(hantei == 0){
				res[tid]++;
				pe[tid] += wrong[tid][pid] * 20 + time;
			}
			else if(hantei != 0){
				wrong[tid][pid]++;
			}
		}
		for(int i = 1;i <= t;i++){
			te.num = i;
			te.ans = res[i];
			te.time = pe[i];
			v.push_back(te);
		}
		sort(v.begin(),v.end(),hikaku);
		for(int i = 0;i < v.size();i++){
			cout << v[i].num;
			if(i != v.size()-1){
				if(v[i].ans == v[i+1].ans && v[i].time == v[i+1].time){
					cout << "=";
				}
				else cout << ",";
			}
		}
		cout <<endl;
	}
	return 0;
}

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

typedef pair<int,int> pii;
typedef pair<pii,int> tri;
int main(){
  int m,t,p,r;
  int team[55][15];
  while(cin>>m>>t>>p>>r,m){
    memset(team,0,sizeof(team));
    vector<tri> ans;
    int a,b,c,d;
    for(int i=0;i<r;i++){
      cin>>a>>b>>c>>d;
      if(d!=0){
	team[b][c]++;
      }else{
	team[b][p+1]+=a+20*team[b][c];
	team[b][p+2]++;
      }
    }
    for(int i=1;i<=t;i++){
      ans.push_back(tri(pii(-team[i][p+2],team[i][p+1]),-i));
    }
    sort(ans.begin(),ans.end());
    for(int i=0;i<t;i++){
      cout<<-ans[i].second;
      if(i+1==t)cout<<endl;
      else if(ans[i].first == ans[i+1].first)cout<<"=";
      else cout<<",";
    }
  }
}