/*
  [BAPC'07] RANKING
  by: Jan Kuipers
*/

using namespace std;

#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>

map<string,set<string> > solved;
map<string,map<string,int> > cntwrong;
map<string,int> total;
map<string,vector<int> > times,wrong;

bool comp (string a, string b) {
  if (solved[a].size() != solved[b].size()) return solved[a].size() > solved[b].size();

  if (total[a] != total[b]) return total[a] < total[b];

  for (int i=times[a].size()-1; i>=0; i--) { 
    if (times[a][i] != times[b][i]) return times[a][i] < times[b][i];
    if (wrong[a][i] != wrong[b][i]) return wrong[a][i] > wrong[b][i];
  }
  
  return false;
}

int main () {

  int runs;
  cin>>runs;
  while (runs--) {

    int T,N;
    cin>>T>>N;

    vector<string> name(T);
    for (int i=0; i<T; i++) cin>>name[i];

    solved.clear();
    cntwrong.clear();
    total.clear();
    times.clear();
    wrong.clear();
    
    for (int i=0; i<N; i++) {
      int time;
      string team, prob, result; 
      cin>>time>>team>>prob>>result;
      
      if (solved[team].count(prob)) continue;

      if (result=="accepted") {
	solved[team].insert(prob);
	times[team].push_back(time);
	wrong[team].push_back(cntwrong[team][prob]);
	total[team]+=time+20*cntwrong[team][prob];
      }
      else
	cntwrong[team][prob]++;      
    }

    sort(name.begin(), name.end());
    stable_sort(name.begin(), name.end(), comp);

    int rank=1; 
    for (int i=0; i<T; i++) {
      if (i>0 && comp(name[i-1],name[i])) rank=i+1;
      cout << rank << " " << name[i] << " " << solved[name[i]].size() << " " << total[name[i]] << endl;
    }
  }

  return 0;
}
