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 <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>

#define el endl
#define fd fixed
#define INF INT_MAX/2-1
#define pb push_back

using namespace std;

class Team
{
private:
  int m_id;
  int m_time;
  bool m_correct[10];
  int m_incorrect[10];
public:
  void setId(int id);
  void setTime(int time);
  void addTime(int time);
  void initCor();
  void success(int qid);
  void initIncor();
  void incIncor(int qid);
  int getId();
  int getTime();
  bool getCor(int qid);
  int getIncor(int qid);
  int getSolved();
  Team(int id) {
    setId(id);
    setTime(0);
    initCor();
    initIncor();
  }
};

void Team::setId(int id) {
  m_id = id;
}

void Team::setTime(int time) {
  m_time = time;
}

void Team::addTime(int time) {
  m_time += time;
}

void Team::initCor() {
  for (int i = 0; i < 10; i++) {
    m_correct[i] = false;
  }
}

void Team::success(int qid) {
  m_correct[qid-1] = true;
}

void Team::initIncor() {
  for (int i = 0; i < 10; i++) {
    m_incorrect[i] = 0;
  }
}

void Team::incIncor(int qid) {
  m_incorrect[qid-1]++;
}

int Team::getId() {
  return m_id;
}

int Team::getTime() {
  return m_time;
}

bool Team::getCor(int qid) {
  return m_correct[qid-1];
}

int Team::getIncor(int qid) {
  return m_incorrect[qid-1];
}

int Team::getSolved() {
  int count = 0;
  for (int i = 0; i < 10; i++) {
    if (m_correct[i]) {
      count++;
    }
  }
  return count;
}

int main() {
  int M, T, P, R, m, t, p, j;
  while (cin >> M >> T >> P >> R, M | T | P | R) {
    vector<Team> teams;
    for (int i = 0; i < T; i++) {
      teams.pb(Team(i+1));
    }
    while (R--) {
      cin >> m >> t >> p >> j;
      if (j == 0) {
        teams[t-1].success(p);
        teams[t-1].addTime(m);
      } else {
        teams[t-1].incIncor(p);
      }
    }
    for (int i = 0; i < T; i++) {
      for (int j = 1; j <= 10; j++) {
        if (teams[i].getCor(j)) {
          teams[i].addTime(teams[i].getIncor(j)*20);
        }
      }
    }
    for (int i = 0; i < T; i++) {
      for (int j = i+1; j < T; j++) {
        if ((teams[i].getSolved() < teams[j].getSolved()) || ((teams[i].getSolved() == teams[j].getSolved()) && (teams[i].getTime() > teams[j].getTime())) || ((teams[i].getSolved() == teams[j].getSolved()) && (teams[i].getTime() == teams[j].getTime()) && (teams[i].getId() < teams[j].getId()))) {
          swap(teams[i], teams[j]);
        }
      }
    }
    for (int i = 0; i < T-1; i++) {
      cout << teams[i].getId();
      if ((teams[i].getSolved() == teams[i+1].getSolved()) && (teams[i].getTime() == teams[i+1].getTime())) {
        cout << '=';
      } else {
        cout << ',';
      }
    }
    cout << teams[T-1].getId() << el;
  }
}

C++: #include <bits/stdc++.h>

#define rep(i, a, n) for(int i = (a);i < (n);i++)
#define REP(i, n)    rep(i, 0, n)
#define all(e)       (e).begin(), (e).end()

#ifdef LOCAL
#define show(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

using namespace std;
using ll = long long;
template<class T>
using V = vector<T>;

template<class T, class U>
void chmin(T &t, const U u) { if (t > u) t = u; }

template<class T, class U>
void chmax(T &t, const U u) { if (t < u) t = u; }

const int INF = (1 << 30) - 1;
const ll INFL = (ll) 5e15;
const int MOD = 1e9 + 7;

class score {
public:
    int solves;
    int time;
    int team;

    bool operator<(score s) const {
        if (solves < s.solves) return true;
        else if (solves == s.solves) {
            if (time > s.time) return true;
            else if (time == s.time) {
                if (team < s.team) return true;
            }
        }

        return false;
    }
};

class Solver {
public:
    bool solve() {
        cin >> M >> T >> P >> R;
        if (M == 0) return false;
        scores.resize(T);
        REP(i, T) {
            scores[i].team = i + 1;
        }
        penalty.resize(T + 1, V<int>(P + 1));
        REP(i, R) {
            int m, t, p, j;
            cin >> m >> t >> p >> j;
            if (j == 0) {
                scores[t - 1].solves++;
                scores[t - 1].time += m + penalty[t][p] * 20;
            } else {
                penalty[t][p]++;
            }
        }
        sort(scores.rbegin(), scores.rend());

        REP(i, T - 1) {
            cout << scores[i].team;
            if (scores[i].solves == scores[i + 1].solves && scores[i].time == scores[i + 1].time) {
                cout << "=";
            } else {
                cout << ",";
            }
        }
        cout << scores[T - 1].team << endl;

        return true;
    }

private:
    int M, T, P, R;

    V<score> scores;// ans, time, team
    V<V<int>> penalty;
};

int main() {

    while (Solver().solve());

    return 0;
}