#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

void solve()
{
	int n;
	char c;
	scanf("%d%c", &n, &c);
	while(n--)
	{
		int score = 0;
		int runner[3] = {0};
		int outCount = 0;
		while(outCount < 3)
		{
			string str;
			cin >> str;
			if(str == "HIT")
			{
				if(runner[2] == 1)
				{
					++score;
				}
				runner[2] = runner[1];
				runner[1] = runner[0];
				runner[0] = 1;
			}
			else if(str == "HOMERUN")
			{
				for(int i = 0; i < 3; ++i)
				{
					if(runner[i] == 1)
					{
						++score;
					}
					runner[i] = 0;
				}
				++score;
			}
			else if(str == "OUT")
			{
				++outCount;
			}
		}
		cout << score << endl;
	}
}

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