#include <set>
#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <complex>
#include <iostream>
#include <algorithm>
#include <ctime>
#include <deque>
#include <bitset>
#include <cctype>
#include <utility>
#include <cassert>
using namespace std;
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)
#define REP(i,a) for(int i=0,_a=(a); i<_a; i++)
#define EACH(it,a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define DEBUG(x) { cout << #x << " = " << x << endl; }
#define PR(a,n) { cout << #a << " = "; FOR(_,1,n) cout << a[_] << ' '; cout << endl; }
#define PR0(a,n) { cout << #a << " = "; REP(_,n) cout << a[_] << ' '; cout << endl; }
struct Team {
string name;
int nWrong[ 22 ] ;
bool accepted[ 22 ] ;
int penalty, nAc;
vector< pair< int ,int > > scores;
Team( string name = "" ) : name( name) {
memset ( nWrong, 0 , sizeof nWrong) ;
memset ( accepted, false , sizeof accepted) ;
penalty = nAc = 0 ;
scores.clear ( ) ;
}
void submit( int t, int prob, string status) {
if ( accepted[ prob] ) return ;
if ( status[ 0 ] == 'a' ) {
penalty + = nWrong[ prob] * 20 + t;
accepted[ prob] = true ;
++ nAc;
scores.push_back ( make_pair( t, penalty) ) ;
}
else {
++ nWrong[ prob] ;
}
}
} teams[ 55 ] ;
bool lower( const Team & a, const Team & b) {
if ( a.nAc ! = b.nAc ) return a.nAc > b.nAc ;
if ( a.penalty ! = b.penalty ) return a.penalty < b.penalty ;
FORD( i,a.scores .size ( ) - 1 ,0 )
if ( a.scores [ i] .first < b.scores [ i] .first ) return true ;
else if ( a.scores [ i] .first > b.scores [ i] .first ) return false ;
else if ( a.scores [ i] .second ! = b.scores [ i] .second )
return a.scores [ i] .second < b.scores [ i] .second ;
return false ;
}
bool operator < ( const Team & a, const Team & b) {
if ( a.nAc ! = b.nAc ) return a.nAc > b.nAc ;
if ( a.penalty ! = b.penalty ) return a.penalty < b.penalty ;
FORD( i,a.scores .size ( ) - 1 ,0 )
if ( a.scores [ i] .first < b.scores [ i] .first ) return true ;
else if ( a.scores [ i] .first > b.scores [ i] .first ) return false ;
else if ( a.scores [ i] .second ! = b.scores [ i] .second )
return a.scores [ i] .second < b.scores [ i] .second ;
return a.name < b.name ;
}
int nTeam, nSub;
#define rank rank_
int rank[ 55 ] ;
int getId( string name) {
FOR( i,1 ,nTeam)
if ( teams[ i] .name == name) return i;
return - 1 ;
}
int main( ) {
ios :: sync_with_stdio ( false ) ; cin .tie ( NULL ) ;
cout << ( fixed) << setprecision( 6 ) ;
int ntest; cin >> ntest;
while ( ntest-- ) {
cin >> nTeam >> nSub;
FOR( i,1 ,nTeam) {
string s; cin >> s;
teams[ i] = Team( s) ;
}
FOR( i,1 ,nSub) {
int t; string name, prob, status;
cin >> t >> name >> prob >> status;
int id = getId( name) ;
teams[ id] .submit ( t, prob[ 0 ] - 'A' , status) ;
}
sort( teams+ 1 , teams+ nTeam+ 1 ) ;
FOR( i,1 ,nTeam) {
if ( i == 1 ) rank[ i] = 1 ;
else if ( lower( teams[ i- 1 ] , teams[ i] ) ) rank[ i] = i;
else rank[ i] = rank[ i- 1 ] ;
cout << rank[ i] << ' ' << teams[ i] .name << ' ' << teams[ i] .nAc << ' ' << teams[ i] .penalty << endl;
}
}
return 0 ;
}
I2luY2x1ZGUgPHNldD4KI2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPGxpc3Q+CiNpbmNsdWRlIDxjbWF0aD4KI2luY2x1ZGUgPHF1ZXVlPgojaW5jbHVkZSA8c3RhY2s+CiNpbmNsdWRlIDxjc3RkaW8+CiNpbmNsdWRlIDxzdHJpbmc+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxjc3RkbGliPgojaW5jbHVkZSA8Y3N0cmluZz4KI2luY2x1ZGUgPHNzdHJlYW0+CiNpbmNsd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