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

int main(void)
{
	int n;
	string _event;

	cin >> n;
	for(int i=0; i<n; i++)
	{
		int outN=0;
		int score=0;
		int runnerState=0;

		while(1)
		{
			cin >> _event;
			if(_event == "HIT")
			{
				runnerState <<= 1;
				runnerState |=  1;

				if(runnerState & 0x08)
				{
					runnerState &= ~(0x08);
					score ++;
				}
			}

			if(_event == "HOMERUN")
			{
				score++;
				while(runnerState != 0)
				{
					runnerState >>= 1;
					score++;
				}
			}

			if(_event == "OUT")
			{
				outN++;
				if(outN == 3)break;
			}
		}
		cout << score << endl;
	}
	return 0;
}