#include <iostream>
#include <string>
using namespace std;
int main()
{
	int n; cin >> n ;
	while(n--)
	{
		int score=0; int out=0; int run=0;
		string str;
		while(cin>>str)
		{
			if(str=="HIT") {run++; if(run>=4) {run--; score++;} }
			else if(str=="HOMERUN") {score+=run+1; run=0;}
			else if(str=="OUT") out++;
			if(out>=3) break;
		}
		cout << score << endl;
	}
}