object Main {
  def solve(result: Array[Array[Int]]): (Array[Int], Array[Boolean]) = {
    val rank = result.map(res => res.map(s => (if (s != -1) 1 else 0)).sum)
    val time = result.map(_.sum)
    val ret = rank.zipWithIndex.sortWith((p, q) => {
      if (p._1 == q._1)
        if (time(p._2) == time(q._2)) p._2 > q._2
        else time(p._2) < time(q._2)
      else p._1 > q._1
    }).map(p => p._2 + 1)
    val eq = ret.init.zip(ret.tail).map(p =>
      rank(p._1 - 1) == rank(p._2 - 1) && time(p._1 - 1) == time(p._2 - 1))
    (ret, eq)
  }

  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    var f = true
    while(f) {
      val m, t, p, r = sc.nextInt
      if(m == 0 && t == 0 && p == 0 && r == 0) f = false
      else {
        val result = Array.fill[Int](t, p)(-1)
        val penalty = Array.ofDim[Int](t, p)
        for(_ <- 1 to r) {
          val mm, tt, pp, j = sc.nextInt
          if (j == 0) result(tt - 1)(pp - 1) = mm + penalty(tt - 1)(pp - 1) * 20
          else penalty(tt - 1)(pp - 1) += 1
        }
        val (rank, eq) = solve(result)
        rank.init.zip(eq).foreach( x => if (x._2) print (x._1 + "=")
                                        else print (x._1 + ","))
        println(rank.last)
      }
    }
  }
}