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

int main()
{
	int n,inning=0;
	int p[40] = {0};
	string ivent;

	cin >> n ;
	while (1)
	{
		int r=0, o=3;                        //r = ???????????????o = ??¢???????????°
		while (o)
		{
			cin >> ivent;

			if (ivent == "HIT")
			{
				r++;
				if (r >= 4)                       //??????
				{
					p[inning]++;
                                        r=3;
				}
			}

			else if (ivent=="HORMRUN")
			{
				p[inning] += r + 1;
				r = 0;                            //??????????????????????????????
			}
			else if (ivent=="OUT")
			{
				o--;
			}
		}
		cout << p[inning] << endl;
		inning++;
		if (n == inning) break;

	}

	return 0;
}