loop do
    m, t, p, r = gets.split.map(&:to_i)
    break if m == 0 && t == 0 && p == 0 && r == 0
    rec = r.times.map{gets.split.map(&:to_i)}
    wa = Array.new(t).map{Array.new(p+1,0)}
    grade = Array.new(t).map{Array.new(2,0)}
    rec.each do |rr|
        case rr[3]
        when 0
            grade[rr[1]-1][0] += 1
            grade[rr[1]-1][1] += rr[0] + 20 * wa[rr[1]-1][rr[2]]
        else
            wa[rr[1]-1][rr[2]] += 1
        end
    end
    gr = grade.map.with_index(1){|g,i| [i] + g}.sort{
        |a,b| (b[1] <=> a[1]).nonzero? || (a[2] <=> b[2]).nonzero? || b[0]<=>a[0]
    }
    pb = pc = -1
    ret = ""
    gr.each_with_index {|a,i|
        if a[1] == pb && a[2] == pc
            ret += "=#{a[0]}"
        else
            ret += "#{a[0]}" if i == 0
            ret += ",#{a[0]}" if i != 0
        end
        pb = a[1]
        pc = a[2]
    }
    puts ret
end