#include <iostream>
using namespace std;

int main(){
	int inning,score;
	int out,runner;
	string str;
	cin>>inning;
	for(int i=0;i<inning;i++){
		score=runner=out=0;
		while(out<3){
			cin>>str;
			if(str=="OUT")out++;
			if(str=="HIT")runner++;
			if(runner==4){
				score++;
				runner--;
			}
			if(str=="HOMERUN"){
				score=score+runner+1;
				runner=0;
			}
		}
		cout<<score<<endl;
	}
}