#include<iostream>
#include<string>

using namespace std;

int main()
{
	int n;
	cin >> n;
	for(int i = 0;i < n;i++)
	{
		int out = 0;
		int score = 0;
		unsigned char data = 0;
		while(1)
		{
			string event;
			cin >> event;
			if(event == "HIT")
			{
				data <<= 1;
				data |= 0x01;
				if(data & 0x08)
				{
					data &= ~0x08;
					score++;
				}
			}
			else if(event == "HOMERUN")
			{
				for(int i = 0;i < 3;i++)
				{
					if(data & (0x01 << i)) score++;
				}
				score++;
				data = 0;
			}
			else if(event == "OUT")
			{
				out++;
				if(out >= 3) break;
			}
		}
		cout << score << endl;
	}
	return 0;
}