#include <iostream>
#include <string>

using namespace std;

void solve()
{
	int N;
	cin >> N;
	while(N--)
	{
		int count = 3;
		int digit = 0;
		int score = 0;
		while(count)
		{
			string str;
			cin >> str;
			if(str == "HIT")
			{
				digit <<= 1;
				if(digit >= 8)
				{
					++score;
					digit -= 8;
				}
				++digit;
			}
			else if(str == "HOMERUN")
			{
				++score;
				for(int i = 0; i < 3; ++i)
				{
					if(digit & 1)
					{
						++score;
					}
					digit >>= 1;
				}
			}
			else if(str == "OUT")
			{
				--count;
			}
		}
		cout << score << endl;
	}
}

int main()
{
	solve();
	return(0);
}