/* TU Darmstadt Programming Contest 2001
 * Problem: Ranking
 * Author : Christoph Mueller <cmueller@mathematik.tu-darmstadt.de>
 * Comment:
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

struct teamstruct 
{
  char name[10];
  int solved;
  int time;
  int problems[10][2];
} teaminfo[20];

int compare(const void *p1, const void *p2)
{
  struct teamstruct *t1, *t2;

  t1 = (struct teamstruct *) p1;
  t2 = (struct teamstruct *) p2;

  if(t1->solved > t2->solved) return -1;
  if(t1->solved < t2->solved) return 1;
  if(t1->time < t2->time) return -1;
  if(t1->time > t2->time) return 1;
  return strcmp(t1->name, t2->name);
}

int main(void) 
{
  int scen;
  int n, k, m;
  int i, j, p, t;
  char correct[5], team[10];

  scanf("%d", &scen);

  while(scen--)
    {
      scanf("%d", &n);

      for(i=0; i<n; i++)
	scanf("%s", teaminfo[i].name);

      scanf("%d%d", &k, &m);

      for(j=0; j<n; j++)
	{
	  teaminfo[j].solved = 0;
	  teaminfo[j].time = 0;
	  for(p=0; p<k; p++)
	    {
	      teaminfo[j].problems[p][0] = 0;
	      teaminfo[j].problems[p][1] = 0;
	    }
	}

      for(i=0; i<m; i++)
	{
	  scanf("%d%d%s%s", &p, &t, correct, team);
	  p--;

	  for(j=0; j<n; j++)
	    if(!strcmp(teaminfo[j].name, team))
	      break;

	  if(!strcmp("Yes", correct))
	    {
	      if(!teaminfo[j].problems[p][0])
		{
		  teaminfo[j].problems[p][0] = 1;
		  teaminfo[j].problems[p][1] += t;
		  teaminfo[j].solved++;
		  teaminfo[j].time += teaminfo[j].problems[p][1];
		}
	    }
	  else
	    {
	      if(!teaminfo[j].problems[p][0])
		teaminfo[j].problems[p][1] += 20;
	    }
	}

      qsort(teaminfo, n, sizeof(struct teamstruct), compare);

      for(i=0, j=0; i<n; i++)
	{
	  if(teaminfo[i].solved != teaminfo[j].solved ||
	     teaminfo[i].time != teaminfo[j].time) j = i;

	  printf("%2d. %-8s %d %4d\n", 
	         j+1, teaminfo[i].name, teaminfo[i].solved, teaminfo[i].time);
	}
      printf("\n");

    }
    return 0;
}
