loop do
    t, p, r = gets.split.map(&:to_i)
    break if t == 0 && p == 0 && r == 0
    rec = r.times.map{gets.gsub(/WRONG|CORRECT/, "WRONG" => "0", "CORRECT" => "1").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
            wa[rr[0]-1][rr[1]] += 1
        when 1
            grade[rr[0]-1][0] += 1
            grade[rr[0]-1][1] += rr[2] + 1200 * wa[rr[0]-1][rr[1]]
        end
    end
    puts grade.map.with_index(1){|g,i| [i] + g}.sort{
        |a,b| (b[1] <=> a[1]).nonzero? || (a[2] <=> b[2]).nonzero? || (a[0] <=> b[0])
     }.map{|a,b,c| "#{a} #{b} #{c}"}
end