#include <iostream>
#include <string>
using namespace std;
int main()
{
	int n, p = 0, o, t, i, j;
	string e;
	bool b[3] = {false};
	cin >> n;
	for (i = 0; i < n; i++)
	{
		o = p = 0;
		b[0] = b[1] = b[2] = false;
		while (o < 3)
		{
			cin >> e;
			if (e == "HIT")
			{
				if (b[2] == true)
				{
					p++;
					b[2] = false;
				}
				if (b[1] == true)
				{
					b[1] = false;
					b[2] = true;
				}
				if (b[0] == true)
				{
					b[0] = false;
					b[1] = true;
				}
				b[0] = true;
			}
			if (e == "HOMERUN")
			{
				for (j = t = 0; j < 3; j++)
				{
					if (b[j])
					{
						b[j] = false;
						t++;
					}
				}
				p += t+1;
			}
			if (e == "OUT")
				o++;
		}
		cout << p << endl;
	}
}