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 FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(5)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<short, short> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 114514810;
const int MOD = 100000007;
const double EPS = 1e-10;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator > (const edge& e) const { return cost > e.cost; }
};

int m, t, p, r;
struct data{ int sol, pe, team; };
bool comp(const data& d1, const data& d2)
{
	if (d1.sol != d2.sol) return d1.sol > d2.sol;
	else if (d1.pe != d2.pe) return d1.pe < d2.pe;
	else return d1.team>d2.team;
}

int main()
{
	while (cin >> m >> t >> p >> r,m)
	{
		vector<data> v;
		REP(i, t)
		{
			v.push_back(data{ 0, 0, i });
		}
		vector<vi> res(t, vi(p));
		while (r--)
		{
			int a, b, c, d;
			cin >> a >> b >> c >> d;
			b--; c--;
			if (d == 0)
			{
				v[b].sol++;
				v[b].pe += a+res[b][c];
			}
			else
			{
				res[b][c] += 20;
			}
		}

		sort(ALL(v),comp);

		REP(i, t)
		{
			cout << v[i].team+1;
			if (i == t - 1) cout << endl;
			else if (v[i].sol == v[i + 1].sol&&v[i].pe == v[i + 1].pe) cout << "=";
			else cout << ",";
		}
	}
}

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

int main() {
  for(int M, T, P, R; cin >> M >> T >> P >> R && (M|T|P|R);) {
    vector<int> ac(T, 0), ti(T, 0);
    vector<vector<int> > wa(T, vector<int>(P, 0));
    for(int i = 0; i < R; ++i) {
      int m, t, p, j;
      cin >> m >> t >> p >> j;
      if(j) {
        ++wa[t-1][p-1];
      } else {
        ++ac[t-1];
        ti[t-1] += m + wa[t-1][p-1] * 20;
      }
    }
    vector<vector<int> > v;
    for(int i = 0; i < T; ++i) {
      vector<int> u(3);
      u[0] = ac[i];
      u[1] = -ti[i];
      u[2] = i+1;
      v.push_back(u);
    }
    sort(v.begin(), v.end(), greater<vector<int> >());
    for(int i = 0; i < v.size(); ++i) {
      if(i) {
        cout << (v[i-1][0] == v[i][0] && v[i-1][1] == v[i][1] ? '=' : ',');
      }
      cout << v[i][2];
    }
    cout << endl;
  }
  return 0;
}

C++: #include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

struct Team {
  int index;
  int cnts[10];
  int solved;
  int penalty;
  Team() {;}
  bool operator<(const Team &rhs) const {
    if (solved != rhs.solved) { return solved < rhs.solved; }
    if (penalty != rhs.penalty) { return penalty > rhs.penalty; }
    return index < rhs.index;
  }
  void ac(int t, int p) {
    solved++;
    penalty += t + cnts[p] * 20;
  }
  void wa(int t, int p) {
    cnts[p]++;
  }
};

Team teams[100];
int M, T, P, R;
int main() {
  while (cin >> M >> T >> P >> R, M) {
    MEMSET(teams, 0);
    REP(i, T) { teams[i].index = i; }
    REP(i, R) {
      int m, t, p, j;
      cin >> m >> t >> p >> j;
      t--; p--;
      if (j == 0) {
        teams[t].ac(m, p);
      } else {
        teams[t].wa(m, p);
      }
    }
    sort(teams, teams + T);
    reverse(teams, teams + T);
    REP(i, T) {
      printf("%d", teams[i].index + 1);
      if (i != T - 1) {
        if (teams[i].solved == teams[i + 1].solved && teams[i].penalty == teams[i + 1].penalty) {
          printf("=");
        } else {
          printf(",");
        }
      }
    }
    puts("");
  }
}