import java.util.*

fun main(args:Array<String>?): Unit {
    while (true) {
        val (m, t, p, r) = readLine()!!.trim().split(' ').map(String::toInt)
        if (m == 0 && t == 0 && p == 0 && r == 0) return
        val teams = Array(t) { Team(it + 1, p) }
        repeat(r) {
            val (time, team, problem, status) = readLine()!!.trim().split(' ').map(String::toInt)
            teams[team - 1].submit(problem, time, status)
        }
        val sorted = teams.sortedDescending()
        val result = Stack<Any>()
        result.push(sorted.first().id)
        for (id in sorted.indices.drop(1)) {
            val team = sorted[id]
            if (result.isEmpty()) {
                result.push(team.id)
            } else if (sorted[id - 1].isSameScore(team)) {
                result.push("=")
                result.push(team.id)
            } else {
                result.push(",")
                result.push(team.id)
            }
        }
        println(result.joinToString(""))
    }
}
class Team(val id: Int, problemSize: Int): Comparable<Team> {
    private val problems = Array(problemSize){History()}
    fun submit(problem: Int, time: Int, status: Int): Unit {
        problems[problem - 1].submit(time, status)
    }
    private fun acCount(): Int = problems.count{it.accepted}
    private fun sumTime(): Int = problems.sumBy{it.acTime}
    fun isSameScore(other: Team): Boolean {
        return acCount() == other.acCount() && sumTime() == other.sumTime()
    }
    override fun compareTo(other: Team): Int {
        return if (acCount() != other.acCount()) acCount().compareTo(other.acCount())
            else if (sumTime() != other.sumTime()) other.sumTime().compareTo(sumTime())
            else id.compareTo(other.id)
    }

    override fun equals(other: Any?): Boolean {
        return when(other){
            is Team -> this.compareTo(other) == 0
            else -> super.equals(other)
        }
    }
}

class History {
    private var submitCount: Int = 0
    private var acceptedTime: Int = -1
    fun submit(time: Int, status: Int): Unit {
        if (acceptedTime == -1){
            if (status == 0){
                acceptedTime = time
            }else {
                submitCount++
            }
        }
    }
    val accepted: Boolean
        get() = acceptedTime != -1
    val acTime: Int
        get() {
            return if (accepted) acceptedTime + 20 * submitCount else 0
        }
}

