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

int count8bit( unsigned char v ){
	unsigned int count = ( v & 0x55 ) + ( ( v >> 1 ) & 0x55 );
	count = ( count & 0x33 ) + ( ( count >> 2 ) & 0x33 );
	return ( count & 0x0f ) + ( ( count >> 4 ) & 0x0f );
}

int main()
{
	int n;

	cin >> n;

	for( int inning_cnt = 0; inning_cnt < n; ++inning_cnt ){
		int point = 0;
		int out_cnt = 0;
		unsigned char base = 0;
		while( out_cnt < 3 ){
			base |= 1;
			string s;
			cin >> s;
			if( s == "HIT" ){
				base <<= 1;
				if( base & 1 << 4 ){
					base -= ( 1 << 4 );
					++point;
				}
			}else if( s == "HOMERUN" ){
				point += count8bit( base );
				base = 0;
			}else if( s == "OUT" ){
				++out_cnt;
			}
		}
		cout << point << endl;
	}
}