#include <iostream>
#include <string>

int main()
{
	std::string innings;
	getline(std::cin, innings);
	int bInnings = std::stoi(innings);
	
	int outs = 0;
	int score = 0;
	int base[3] = {0, 0, 0};
	for (int i=0; i<bInnings; ) {
		std::string event;
		getline(std::cin, event);
		if (event == "HIT") {
			if (base[2] == 1) score++;
			base[2] = base[1];
			base[1] = base[0];
			base[0] = 1;
		}
		else if (event == "HOMERUN") {
			score += base[0] + base[1] + base[2] + 1;
			base[0] = base[1] = base[2] = 0;
		}
		else {
			outs++;
			if (outs == 3) {
				std::cout << score << std::endl;
				score = 0;
				base[0] = base[1] = base[2] = 0;
				outs = 0;
				i++;
			}
		}
	}
	
	return 0;
}

