import java.util.*;

class Run
{
    public final int time;
    public final String team;
    public final int problem;
    public final boolean correct;

    public Run(int time, String team, String problem, String correct)
    {
        this.time = time;
        this.team = team;
        this.problem = problem.charAt(0) - 'A';
        this.correct = correct.equals("accepted");
    }
}

class Score
{
    public final int time, penalty;

    public Score(int time, int penalty)
    {
        this.time = time;
        this.penalty = penalty;
    }
}

class Team implements Comparable
{
    public final String name;
    private int penalty;
    private Score[] scores;

    public Team(String name)
    {
        this.name = name;
    }

    public int numSolved()
    {
        return scores.length;
    }

    public int timeUsed()
    {
        return penalty;
    }

    public int compareScores(Team other)
    {
        int d;

        // The team with the most problems solved
        if ((d = numSolved() - other.numSolved()) != 0)
            return -d;

        // The team with the lowest penalty wins
        if ((d = timeUsed() - other.timeUsed()) != 0)
             return +d;

        // Compare history
        for (int n = scores.length - 1; n >= 0; --n)
        {
            // Earlier submission of the last run wins
            if ((d = scores[n].time - other.scores[n].time) != 0)
                return +d;

            // Lower penalty at the same point in time wins
            if ((d = scores[n].penalty - other.scores[n].penalty) != 0)
                return +d;
        }

        // No score difference!
        return 0;
    }

    public int compareTo(Object obj)
    {
        Team other = (Team)obj;
        int d = compareScores(other);
        return d != 0 ? d : name.compareTo(other.name);
    }

    public void calculateScores(Run[] runs)
    {
        ArrayList<Score> scoresList = new ArrayList<Score>();
        boolean[] solved = new boolean[10];
        int[] failed = new int[10];
        penalty = 0;
        for (Run run: runs)
        {
            if (run.team.equals(name) && !solved[run.problem])
            {
                if (run.correct)
                {
                    penalty += run.time + 20*failed[run.problem];
                    scoresList.add(new Score(run.time, penalty));
                    solved[run.problem] = true;
                }
                else
                {
                    failed[run.problem] += 1;
                }
            }
        }
        scores = scoresList.toArray(new Score[0]);
    }
}

public class maks
{
    /* Calculates time/score pairs, for each point in time where the
       score changed. This means the length of the scores array is equal to
       the number of problems solved. */

    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int cases = sc.nextInt();
        while (cases-- > 0)
        {
            /* Read input */
            Team[] teams = new Team[sc.nextInt()];
            Run[] runs = new Run[sc.nextInt()];
            for (int t = 0; t < teams.length; ++t)
                teams[t] = new Team(sc.next());
            for (int r = 0; r < runs.length; ++r)
                runs[r] = new Run(sc.nextInt(), sc.next(), sc.next(), sc.next());
            for (int t = 0; t < teams.length; ++t)
                teams[t].calculateScores(runs);

            /* Order teams */
            Arrays.sort(teams);

            /* Display ranking */
            Team lastTeam = null;
            int lastPos = 0, pos = 0;
            for (Team team: teams)
            {
                ++pos;
                if (lastTeam == null || team.compareScores(lastTeam) != 0)
                {
                    lastTeam = team;
                    lastPos  = pos;
                }
                System.out.println(lastPos + " " + team.name + " " + team.numSolved() + " " + team.timeUsed());
            }
        }
    }
}
