while true
    limit, n_t, n_p, n_r = gets.chomp.split.map(&:to_i)
    break if [limit, n_t, n_p, n_r] == [0, 0, 0, 0]
    result = Array.new(n_t){[0, 0, nil, Hash.new(0)]}
    1.upto(n_t){|team| result[team - 1][2] = team}
    n_r.times{
        time, team, problem, judge = gets.chomp.split.map(&:to_i)
        if judge == 0
            result[team - 1][0] += 1
            result[team - 1][1] += (time + 20 * result[team - 1][3][problem])
        else
            result[team - 1][3][problem] += 1
        end
    }
    result.sort_by!{|n_solved, total, team, n_mis| [-n_solved, total, -team]}
    prev = nil
    result.each{|team|
        if prev
            if prev[0] == team[0] && prev[1] == team[1]
                print "="
            else
                print ","
            end
        end
        print team[2]
        prev = team
    }
    puts
end
