#include <iostream>
#include <string>

class Score {
public:
	Score() :out(0), runner(0), score(0), change(false) {};
	void batter(const int &event) {
		if (event == 0) {
			++runner;
		}
		else if (event == 1) {
			score += runner + 1;
			runner = 0;
		}
		else {
			if (++out == 3) {
				if (runner > 3) {
					score += runner - 3;
				}
				std::cout << score << std::endl;
				change = true;
			}
		}
	}
	const bool in_turn() const { return !change; }
private:
	int out, runner, score;
	bool change;
};

int main() {
	int n;
	std::cin >> n;
	for (auto i = 0; i < n; ++i) {
		Score score;
		while (score.in_turn()) {
			std::string event;
			std::cin >> event;
			if (event == "HIT") {
				score.batter(0);
			}
			else if (event == "HOMERUN") {
				score.batter(1);
			}
			else {
				score.batter(2);
			}
		}
	}
}