#include <iostream>
#include <string>
int main(void){
int datasets,i,hit=0,out,remain=0;
std::string input;
std::cin >> datasets;
for(i=0;i<datasets;++i){
	out=0;
	while(out<3){
		std::cin >> input;
		if(input=="HIT"){
			++hit;
			++remain;
		}
		if(input=="HOMERUN"){
			++hit;
			remain=0;
		}
		if(input=="OUT") ++out;
	}
	if(remain>3) remain=3;
	std::cout << hit-remain;
	hit=0;
	remain=0;
}
return 0;
}