import scala.io.StdIn.{readLine,readInt}

object Main {
  def main(args:Array[String]) = {
    var s = ""
    while({ s = readLine; s.trim } != "0 0 0 0") {
      val n = s.split(" ").map(_.toInt)
      val m = n(0);val t = n(1);val p = n(2); val r = n(3)
      val team = new Array[(Int,Int)](t)
      val tdata = (for(i<-0 until t) yield {
        (for(j<-0 until p) yield {
          (0,0,0) // (??????,??£?§£?????????,?????£?§£??°)
        }).toArray
      }).toArray

      for(i<-0 until r) {
        val s = readLine.split(" ").map(_.toInt)
        val data = tdata(s(1)-1)(s(2)-1)
        tdata(s(1)-1)(s(2)-1) = (if(s(3)==0) s(0) else 0,if(s(3)==0) 1 else 0,if(s(3)!=0) data._3+1 else data._3)
      }
      for(i<-0 until t) {
        val data = tdata(i)
        var success = 0
        var time = 0
        for(j<-0 until data.length) {
          if(data(j)._2 == 1) {
            success += 1
            time += data(j)._1 + data(j)._3*20
          }
        }
        team(i) = (success, time)
      }

      val sorted = team.zipWithIndex.sortWith{(x,y) =>
        if(x._1._1>y._1._1) true
        else if(x._1._1==y._1._1 && x._1._2<y._1._2) true
        else if(x._1._1 == y._1._1 && x._1._2 == y._1._2 && x._2 > y._2) true
        else false
      }
      var prevCnt = sorted(0)._1._1
      var prevTime = sorted(0)._1._2
      print(sorted(0)._2+1)
      for(i<-1 until sorted.length) {
        if(prevCnt == sorted(i)._1._1 && prevTime == sorted(i)._1._2) print("=")
        else print(",")
        print(sorted(i)._2+1)
        prevCnt = sorted(i)._1._1
        prevTime = sorted(i)._1._2
      }
      println
    }
  }
}