/* TU Darmstadt Programming Contest 2001
 * Problem: Ranking
 * Author : Philipp Hahn <pmhahn@informatik.tu-darmstadt.de>
 * Comment: Formatierung von "%4d" schwierig
 *	Gross-/Kleinschreibung
 *  Sortierung bei Gleichstand
 */
import java.io.FileReader;
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.EOFException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Arrays;
import java.text.MessageFormat;
import java.text.ParseException;

/** Team record. **/
class Team implements Comparable {
	/** Problem subrecord. **/
	class Problem {
		boolean solved = false;
		int time = 0;
	}

	String name;
	Problem[] problem;
	int solved = 0;
	int time = 0;
	int rank = 0;

	/** Constructor. **/
	public Team(String name) {
		this.name = name;
		problem = new Problem[ranking.MAX_PROBLEM];
		for(int i=0; i<ranking.MAX_PROBLEM; i++)
			problem[i] = new Problem();
	}

	/** Submission. **/
	public void solve(int problem, int time, boolean vote) {
		Problem p = this.problem[problem];
		if(p.solved) return; // Already solved
		if(vote) {
			p.solved = true; // Mark as solved
		    p.time += time;  // Accumulate time
			this.time += p.time;
			this.solved++;
		} else {
			p.time += ranking.PENALTY;
		}
	}

	/** Compare this to other. **/
	public int compareTo(Object o) {
		Team other = (Team)o;
		if(this.solved > other.solved) return -1;
		if(this.solved < other.solved) return  1;
		if(this.time   < other.time  ) return -1;
		if(this.time   > other.time  ) return  1;
		if(rank>0) return 0;
		return this.name.compareTo(other.name);
	}

	/** Display team record. **/
	public String toString() {
		//                                  01  45678901 3 5678
		StringBuffer sb = new StringBuffer(" 0.          0    0\n");
		String r = Integer.toString(rank);   sb.replace( 2-r.length(), 2,r);
		String n = name;                     sb.replace( 4, 4+n.length(),n);
		String s = Integer.toString(solved); sb.replace(14-s.length(),14,s);
		String t = Integer.toString(time);   sb.replace(19-t.length(),19,t);
		return sb.toString();
	}
}

/** Main class. **/
public class ranking {
	static BufferedReader br = new BufferedReader(new java.io.InputStreamReader(System.in));
	static BufferedWriter bw = new BufferedWriter(new java.io.OutputStreamWriter(System.out));

	static MessageFormat mfScenarios = new MessageFormat("{0,number}");
	static MessageFormat mfTeams = new MessageFormat("{0,number}");
	static MessageFormat mfTeam = new MessageFormat("{0}");
	static MessageFormat mfProblemsSubmissions = new MessageFormat("{0,number} {1,number}");
	//static MessageFormat mfSubmission = new MessageFormat("{0,number} {1,number} {2,choice,0#No|1#Yes} {3}");
	static MessageFormat mfSubmission = new MessageFormat("{0,number} {1,number} {2} {3}");

	public static final int MAX_TEAMS = 20;
	public static final int MAX_NAMELEN = 8;
	public static final int MAX_PROBLEM = 10;
	public static final int MAX_SUBMISSION = 2000;
	public static final int MAX_TIME = 300;
	public static final int PENALTY = 20;

	/** Read and parse line. **/
	static Object[] read(MessageFormat mf) {
		try {
			String line = br.readLine();
			Object[] o = mf.parse(line);
			//dump(o);
			return o;
		} catch(IOException ioe) {
			System.err.println(ioe);
		} catch(ParseException pe) {
			System.err.println(pe);
		}
		System.exit(1);
		return null;
	}

	/** Dump debug data. **/
	private static void dump(Object[] o) {
		for(int i=0; i<4; i++)System.err.print(o[i]);
		System.err.println();
	}

	/** Main method. **/
	public static void main(String[] args) {
		// Read number of scenarios
		Object[] o1 = read(mfScenarios);
		int scenarios = ((Long)o1[0]).intValue();
		while(scenarios-- > 0) {
			// Read number of teams
			Object[] o2 = read(mfTeams);
			int teams = ((Long)o2[0]).intValue();
			HashMap team = new HashMap(teams);

			// Read name of teams
			for(int i=0; i<teams; i++) {
				Object[] o3 = read(mfTeam);
				String name = ((String)o3[0]).trim();
				team.put(name, new Team(name));
			}

			// Read number of problems and submissions
			Object[] o4 = read(mfProblemsSubmissions);
			int problems = ((Long)o4[0]).intValue();

			int submissions = ((Long)o4[1]).intValue();

			// Read submissions
			int oldtime = 0;
			while(submissions-- > 0) {
				Object[] o5 = read(mfSubmission);
				int problem = ((Long)o5[0]).intValue();
				int time = ((Long)o5[1]).intValue();
				String vote = ((String)o5[2]);
				String name = ((String)o5[3]).trim();
				Team t = (Team)team.get(name);

				t.solve(problem, time, vote.equals("Yes"));
			}

			// Sort ranking list
			Team[] ranking = new Team[teams];
			ranking = (Team[])team.values().toArray(ranking);
			Arrays.sort(ranking);

			// Calculate ranking
			for(int i=0; i<teams; i++) ranking[i].rank = i+1;
			for(int i=1; i<teams; i++)
				if(ranking[i-1].compareTo(ranking[i]) == 0)
					ranking[i].rank = ranking[i-1].rank;

			// Print ranking list
			try {
				for(int i=0; i<teams; i++)
					bw.write(ranking[i].toString());
				bw.write("\n");
			} catch(IOException ioe) {
				System.err.println(ioe);
			}
		}
		try{bw.flush();bw.close();}catch(IOException ioe){}
	}
}
// vim: autoindent smartindent tabstop=4 shiftwidth=4
