#include <iostream>
#include <string>

using namespace std;

void solve()
{
	int n;
	cin >> n;
	while(n--)
	{
		int point = 0;
		bool base[3] = {false};
		int remain = 3;
		while(remain)
		{
			string str;
			cin >> str;
			if(str == "HIT")
			{
				if(base[2])
				{
					++point;
					base[2] = false;
				}
				for(int i = 1; i >= 0; --i)
				{
					if(base[i])
					{
						base[i + 1] = true;
					}
				}
				base[0] = true;
			}
			else if(str == "HOMERUN")
			{
				for(int i = 0; i < 3; ++i)
				{
					if(base[i])
					{
						++point;
					}
					base[i] = false;
				}
				++point;
			}
			else if(str == "OUT")
			{
				--remain;
			}
		}
		cout << point << endl;
	}
}

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