loop do
    m0, t0, p0, r = gets.split.map &:to_i
    break if m0 == 0
    submission = (0..t0).map {Hash.new(-1)}

    r.times do
        m, t, p, j = gets.split.map &:to_i
        if j == 0
            submission[t][p] = m - submission[t][p] - 1 
        else
            submission[t][p] -= 20
        end
    end 
    
    point = (1..t0).map do |t| 
        tmp = submission[t].select{|p, m| m >= 0}
        [-tmp.size, tmp.values.inject(0, :+), t]
    end 

    point.sort!
    puts point.group_by{|c, m, _| [c, m]}.map{|_, a| a.map(&:last).sort.reverse * '='} * ',' 
end