print=console.log;
ls=require("fs").readFileSync("/dev/stdin","utf-8").split("\n");ls.length--
Object.prototype.trace = function(label){ print(this); return this }
Number.prototype.trace = function(label){ print(this+""); return this }
String.prototype.int = function(c){ return this.split(c||" ").map(int)}
Array.prototype.max = function(){ return Math.max.apply(null, this) }
Array.prototype.min = function(){ return Math.min.apply(null, this) }
Array.prototype.copy = function(){ return this.map(id) }
Array.prototype.rotate = function(n){
  return this.slice(n, this.length).concat(this.slice(0, n)); }
Array.prototype.permutation = function () {
  if (this.length == 0) return [];
  if (this.length == 1) return [this];
  var ret = [], ar = this;
  for (var i=0; i<ar.length; ++i)
    ret = ret.concat(ar.slice(0, i)
             .concat(ar.slice(i+1, ar.length))
             .permutation()
             .map(function(p){ return p.concat(ar[i]) }));
  return ret;
}
Array.prototype.flatten = function() {
  for (var i=0, ret=[]; i<this.length; ++i) ret = ret.concat(this[i]);
  return ret;
}
function iota(n, b, s) {
  b=b||0; s=s||1; for (var ret=[]; n--; b+=s) ret.push(b); return ret;
}
function int(s){return +s}
function add(a,b){return a+b}
function sub(a,b){return a-b}
function bus(a,b){return b-a}
function id(x){return x}

function solve (T, P, ls) {
  var tms = [];
  for (var i=0; i<T; ++i) {
    tms[i] = [];
    for (var j=0; j<P; ++j) tms[i][j] = 0; // wrong count
    tms[i].solved_count = 0;
    tms[i].penalty = 0;
  }
  for (var i=0; i<ls.length; ++i) {
    var b = ls[i].split(" ");
    var tid = b[0] - 1, pid = b[1] - 1, time = +b[2];

    if (b[3] == "WRONG") {
      tms[tid][pid]++;
    } else {
      tms[tid].solved_count++;
      tms[tid].penalty += tms[tid][pid] * 1200 + time;
    }
  }
  tms.map(function(t,i){
            return {id:i+1, solved_count:t.solved_count,
                    penalty:t.penalty}})
     .sort(function(a,b){
        if (b.solved_count != a.solved_count)
          return b.solved_count - a.solved_count;
        else if (b.penalty != a.penalty) return a.penalty - b.penalty;
        else return a.id - b.id;
     })
     .forEach(function(t) {
       print(t.id, t.solved_count, t.penalty);
     });
}

(function main() {
  for (var k = 0;;) {
    var a = ls[k].int(),
        T = a[0],
        P = a[1],
        n = a[2];
    if (T == 0 && P == 0 && n == 0) break;
    solve(T, P, ls.slice(k+1, k+n+1));
    k += n+1;
  }
})();