#include <stdio.h>
#include <string.h>
int main(void){
	int dataset,ining;
	int i;
	int runner[3],point,out;
	char str[8];

	scanf("%d",&dataset);
	for(ining=0;ining<dataset;ining++){

		//init state variable
		for(i=0;i<3;i++){
			runner[i]=0;
		}
		point=0;
		out=0;

		//start	ining
		while(out<3){
			scanf("%s",&str[0]);

			if(strcmp(str,"HOMERUN")==0){
		                for(i=0;i<3;i++){
					point+=runner[i];
		                        runner[i]=0;
		                }
				point++;
			}

			else if(strcmp(str,"HIT")==0){
				if(runner[2]==1){
					runner[2]=0;
					point++;
				}
				if(runner[1]==1){
					runner[1]=0;
					runner[2]=1;
				}
				if(runner[0]==1){
					runner[0]=0;
					runner[1]=1;
				}
				runner[0]=1;
			}

			else if(strcmp(str,"OUT")==0){
				out++;
			}
		}

		//finish ining
		printf("%d\n",point);
	}
}