#include<iostream>
#include<string>
using namespace std;

int main(){
	string str;
	int n;
	getline( cin, str );
	sscanf( str.c_str(), "%d", &n );

	for( int i=0; i<n; i++ ){
		int out = 0;
		int score = 0;
		bool first=false, second=false, third=false;

		while( out < 3 ){
			getline( cin, str );
			if( str == "HIT" ){
				if(third){ score++; third=false; }
				if(second){ third=true; second=false; }
				if(first){ second=true; first=false; }
				first = true;
			}
			else if( str == "HOMERUN" ){
				if(third){ score++; third=false; }
				if(second){ score++; second=false; }
				if(first){ score++; first=false; }
				score++;
			}
			else if( str == "OUT" ){
				out++;
			}
		}
		cout << score << endl;
	}
}