#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct team
{
int id;
int ac;
int time;
int vis;
int acid[11];
int penalty[11];
} Team;
int cmp(const void *a,const void *b)
{
Team *x = (Team *)a;
Team *y = (Team *)b;
if(x->vis == y->vis)
{
if(x->ac == y->ac)
return x->time - y->time;
return y->ac - x->ac;
}
return y->vis - x->vis;
}
int main()
{
int cases;
Team teams[101];
int id, pid, time;
char status;
char strtemp[30];
int i,j,n;
scanf("%d\n\n", &cases);
while (cases--)
{
for(i=1; i<=100; i++)
{
teams[i].id=i;
teams[i].ac=0;
teams[i].time=0;
teams[i].vis=0;
for(j=0; j<=10; j++)
{
teams[i].acid[j]=0;
teams[i].penalty[j]=0;
}
}
n = 0;
while(gets(strtemp)!=NULL)
{
if(strlen(strtemp)<2) break;
sscanf(strtemp,"%d %d %d %c", &id, &pid, &time, &status);
teams[id].vis = 1;
if(!teams[id].acid[pid] && status=='C')
{
teams[id].acid[pid] = 1;
teams[id].penalty[pid] += time;
}
if(!teams[id].acid[pid] && status=='I')
teams[id].penalty[pid] += 20;
n++;
}
for(i=1; i<=100; i++)
{
for(j=1; j<10; j++)
{
if(teams[i].acid[j])
{
teams[i].ac++;
teams[i].time += teams[i].penalty[j];
}
}
}
qsort(teams+1, 100, sizeof(teams[0]), cmp);
for(i=1; i<=100; i++)
{
if(!teams[i].vis) continue;
printf("%d %d %d\n",teams[i].id, teams[i].ac, teams[i].time);
}
if(cases > 0) printf("\n");
}
return 0;
}