/* TU Darmstadt Programming Contest 2001
 * Problem: Ranking
 * Author : Philipp Hahn <pmhahn@informatik.tu-darmstadt.de>
 * Comment: 
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#define NDEBUG
#undef NDEBUG
#include <assert.h>

#define MAX_TEAMS 20
#define MAX_NAMELEN 8
#define MAX_PROBLEM 10
#define MAX_SUBMISSION 2000
#define MAX_TIME 300
#define PENALTY 20

/* Team record */
struct team {
	char name[MAX_NAMELEN+1];
	struct {
		int solved;
		int time;
	} problem[MAX_PROBLEM];
	int solved; /* number of problems solved */
	int time;   /* total time */
	int rank;   /* ranking number */
} team[MAX_TEAMS];

/* Sort ranking list */
static int compare(const void *a_, const void *b_) {
	struct team *a = (struct team *)a_;
	struct team *b = (struct team *)b_;
	if(a->solved > b->solved) return -1;
	if(a->solved < b->solved) return  1;
	if(a->time   < b->time  ) return -1;
	if(a->time   > b->time  ) return  1;
	if(a->rank) return 0;
	return strcmp(a->name, b->name);
}

int main(void) {
	int i, n, scenarios;

	/* Read number of scenarios */
	n=scanf("%d", &scenarios); assert(n==1);
	assert(scenarios>0);

	while(scenarios--) {
		int teams;
		int problems, submissions;
		int oldtime = 0;

		memset(team, 0, sizeof(struct team)*MAX_TEAMS);

		/* Read number of teams */
		n=scanf("%d", &teams); assert(n==1);
		assert( (1<=teams) && (teams<=MAX_TEAMS) );

		/* Read name of teams */
		for(i=0; i<teams; i++) {
			n=scanf("%s", team[i].name); assert(n==1);
			assert(strlen(team[i].name)<=MAX_NAMELEN);
			{
				char *c=team[i].name;
				while(*c) assert(isalnum(*c++));
			}
			assert((i==0) || (strcmp(team[i-1].name,team[i].name)<0));
		}

		/* Read number of problems and submissions */
		{
			n=scanf("%d%d", &problems, &submissions); assert(n==2);
			assert( (1<=problems) && (problems<MAX_PROBLEM) );
			assert( (0<=submissions) && (submissions<=MAX_SUBMISSION) );
		}

		/* Read submissions */
		while(submissions--) {
			/* Read problem time vote team */
			int problem, time;
			char vote[4], name[MAX_NAMELEN+1];
			n=scanf("%d%d%s%s", &problem, &time, vote, name); assert(n==4);
			assert( (1<=problem) && (problem<=problems) );
			assert( (0<=time)  && (time<MAX_TIME) );
			assert(oldtime<=time); oldtime = time;
			assert(!strcmp(vote,"Yes") || !strcmp(vote,"No"));
			
			/* Search and update team record */
			for(i=0; i<teams; i++) {
				if(strcmp(team[i].name, name)) continue; /* Name mismatch */

				if(team[i].problem[problem].solved) break;   /* Already solved */
				if(strcmp(vote, "Yes") == 0) {
					team[i].problem[problem].solved = 1;     /* Mark as solved */
					team[i].problem[problem].time += time;   /* Accumulate time */
					team[i].solved++;
					team[i].time += team[i].problem[problem].time;
				} else {
					team[i].problem[problem].time += PENALTY;
				}
				break;
			}
			assert(i<teams);
		}

		/* Sort ranking list */
		qsort(team, teams, sizeof(struct team), compare);

		/* Calculate ranking */
		for(i=0; i<teams; i++) team[i].rank = i+1;
		for(i=1; i<teams; i++)
			if(compare(team+i-1, team+i) == 0)
				team[i].rank = team[i-1].rank;

		/* Print ranking list */
		for(i=0; i<teams; i++) {
			printf("%2d. %-8s %1d %4d\n",
				team[i].rank, team[i].name,
				team[i].solved, team[i].time);
		}
		printf("\n");
	}
	return 0;
}
/* vim: ai si ts=4 sw=4
 */
