#include <iostream>
using namespace std;

int main()
{
	int point, base, n, out;
	char ibe[10];

	cin >> n;
	for (int k = 0; k < n; k++){
		base = point = out = 0;
		while (out != 3){
	 	 cin >> ibe;
		 if (ibe == "HIT"){
			 base++;
			 if (base == 4){
				 base--;
				 point++;
			 }
		 }
		 else if (ibe == "HOMERUN"){
			 point += base;
			 base = 0;
		 }
		 else {
			 out++;
		 }
		}
		cout << point << endl;
	}
	return (0);
}	