import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;

void main()
{
	while (1) {
		auto x = readln.chomp.split.map!(to!int);
		if (x[0] == 0) break;
		auto teams = new int[][](x[0], 3);
		auto quest = new int[][](x[0], x[1]);
		foreach (i; 0..x[0]) {
			teams[i][0] = i;
		}
		foreach (i; 0..x[2]) {
			auto a = readln.chomp.split;
			auto data = a[0..3].map!(to!int);
			if (a[3] == "WRONG") {
				quest[data[0]-1][data[1]-1]++;
			} else {
				teams[data[0]-1][1]++;
				teams[data[0]-1][2] += quest[data[0]-1][data[1]-1] * 1200 + data[2];
			}
		}

		teams = teams.array.sort!((b, c) => b[1] == c[1] ? b[2] == c[2] ? b[0] < c[0] : b[2] < c[2] : b[1] > c[1]).array;
		foreach (e; teams) {
			writeln(e[0]+1, " ", e[1], " ", e[2]);
		}
	}
}