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.container;

void main()
{
	while (1) {
		auto x = readln.chomp.split.map!(to!int);
		if (!x[0])break;
		auto score = new int[][](x[1], 3);
		auto wa = new int[][](x[1], x[2]);
		foreach (i; 0..x[3]) {
			auto y = readln.chomp.split.map!(to!int);
			if (y[3] == 0) {
				score[y[1]-1][0]++;
				score[y[1]-1][1] += y[0] + 20 * wa[y[1]-1][y[2]-1];
			} else {
				wa[y[1]-1][y[2]-1]++;
			}
		}
		foreach (i; 0..x[1]) {
			score[i][2] = i + 1;
		}
		score = score.sort!((a,b) => a[0] == b[0] ? a[1] == b[1] ? a[2] > b[2] : a[1] < b[1] : a[0] > b[0]).array;

		auto pre = score[0][0..2];
		write(score[0][2]);
		foreach (i; 1..x[1]) {
			if (pre == score[i][0..2]) {
				write("=");
			} else {
				write(",");
			}
			write(score[i][2]);
			pre = score[i][0..2];
		}
		writeln("");
	}
}