#include <iostream>
#include <string>
using namespace std;

int main()
{
	int n;
	string ivent;

	cin >> n ;
	while (n--)
	{
		int r=0, p=0, o=3;
		while (o)
		{
			cin >> ivent;

			if (ivent == "HIT")
			{
				r++;
				if (r >= 4)
				{
					p++;
				}
			}

			else if (ivent=="HORMRUN")
			{
				if (r >= 4)
				{
					p += 4;
				}
				else
				{
					p += r + 1;
				}
				r = 0;
			}
			else
			{
				o--;
			}
		}

		cout << p << endl;

	}


	return 0;
}