#include<stdio.h>
#include<cstring>

int OutCount,PointCount,HitCount;

int Check(const char* str){
  if( strcmp(str,"HIT") == 0 )
		return 0;
	
	else if( strcmp(str,"HOMERUN") == 0 )
		return 1;
	
	else if( strcmp(str,"OUT") == 0 )
		return 2;
}
int main(){
  int n;
	char Input[10];
	scanf("%d",&n);
	while( n-- ){
		OutCount=PointCount=HitCount=0;
		
		while(OutCount < 3){
			scanf("%s",Input);
			switch(Check(Input)){
				case 0:
					HitCount++;
					if(HitCount==4)++PointCount, --HitCount;
					break;
				case 1:
					PointCount+=HitCount+1;
					HitCount=0;
					break;
				case 2:
					OutCount++;
					break;
			}
		}
		printf("%d\n",PointCount);
	}
	return 0;
}