#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define ITER( c ) __typeof( c ).begin()
#define REP( i, m, n ) for ( int i = m; i < n; i++ )
#define UREP( i, m, n ) for ( unsigned int i = m; i < n; i++ )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) c.begin(), c.end()
#define PB( n ) push_back( n );
#define MP( a, b ) make_pair( a, b )
#define fst first
#define snd second

int main()
{
	int n;
	cin >> n;
	cin.ignore( 1 );

	REP( ni, 0, n )
	{
		int runner = 0, out = 0, point = 0;

		while ( out < 3 )
		{
			string e;
			cin >> e;

			if ( e == "HIT" )
			{
				runner++;
				if ( 4 <= runner )
				{
					point++;
					runner--;
				}
			}
			else if ( e == "HOMERUN" )
			{
				point += runner + 1;
				runner = 0;
			}
			else
			{
				out++;
			}
		}
		
		cout << point << endl;
	}

	return 0;
}