#include <iostream>
#include <array>

class Baseball{
private:
	int point;
	int out;
	int base;   //0:no runner 1:runner
				//home,third,second,first

public:

	Baseball(){
		point = 0;
		out = 0;
		base = 0;
	}

	int point(){
		return point;
	}

	int out(){
		return out;
	}

	int hit(){
		base = (base * 10) + 1;
		
		if(base >= 1000){
			base -= 1000;
			point += 1;
		}
	}

	int home_run(){
		point += 1;
		for(int i = base; i > 0; i /= 10){
			point += i%10;
		}
		base = 0;
	}

	int get_out(){
		out += 1;
	}
	

int main(){

	int N;
	std::cin >> N;

	for(int i = 0; i < N; ++i){
		Baseball baseball();

		while(baseball.out() != 3){
			std::string str;
			cin >> str;

			if(str == "HIT")
				baseball.hit();
			
			else if(str == "HOMERUN")
				baseball.home_run();

			else if(str == "OUT")
				baseball.get_out();

		}

		std::cout >> baseball.point() >> endl;
	}

	return 0;
{
	