#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <sstream>
 
#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
	int n;
	std::string buf;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif

#if INPUT_FROM_FILE
	ifs >> n;
#else
	std::cin >> n;
#endif

	for(int i = 0; i < n; i++){
		int out = 0;
		int num_runner = 0;
		int points = 0;

		while(true){
#if INPUT_FROM_FILE
			ifs >> buf;
#else
			std::cin >> buf;
#endif
			if(buf == "HIT"){
				if(num_runner == 3){
					points++;
				}
				else{
					num_runner++;
				}
			}
			else if(buf == "HOMERUN"){
				points += num_runner + 1;
				num_runner = 0;
			}
			else{
				out++;
				if(out == 3){
					std::cout << points << std::endl;
					break;
				}
			}
		}
	}

#if INPUT_FROM_FILE
		//fclose(fp);
#endif
	return 0;
}

