#include<cstdio>
#include<iostream>
#include<string>

using namespace std;

int main(void){

	int n;
	int run[3+1]={0};
	int out,score;;
	string inp;

	cin>>n;

	for(int i=0;i<n;i++){
		for(int j=0;j<=3;j++) run[j]=0;
		out=0;
		score=0;
		while(1){
			cin>>inp;
			if(inp=="HIT"){
				if(run[3]==1) score++,run[3]=0;
				if(run[2]==1) run[2]=0,run[3]=1;
				if(run[1]==1) run[1]=0,run[2]=1;
				run[1]=1;
			}
			if(inp=="HOMERUN"){
				score++;
				for(int i=1;i<=3;i++){
					if(run[i]==1) score++;
					run[i]=0;
				}
			}
			if(inp=="OUT"){
				out++;
			}
			if(out==3) break;
		}
		cout<<score<<endl;
	}

	return 0;
}