#include <iostream>
#include <string>

using namespace std;

int main()
{
	int i,n,point=0;
	bool run[3];
	string s;
	cin >> n;
	int out=3;
	while(n--){
		for(i=0;i<3;i++) run[i]=0;
		point=0;
		out=3;
		while(out){
			cin >> s;
			if(s == "HIT"){
				if(run[2])point++;
				for(i=2;i>0;i--) run[i]=run[i-1];
				run[0]=1;
				}
				else if(s == "HOMERUN"){
					for(i=0;i<3;i++) if(run[i]){ point++; run[i]=0;}
					point++;
				}
				else out--;
		}
	cout << point << endl;
	}
	return 0;
}