#include <iostream>

int main(void){
	bool firstRunner = false; //first runnner flag
	bool secondRunner = false; //second runnner flag
	bool thirdRunner = false; //third runnner flag

	int n; //number of data set
	std::cin >> n; //input number of data set

	while(n){
		int score = 0; //inning score
		int outCount = 0; //number of out count 

		while(outCount < 3){
			std::string str;
			std::cin >> str; //input event
		
			if(str == "HIT"){ //judge event
				//advance to the next base
				if(thirdRunner == true){
					++score;
					thirdRunner = false;
				}
				if(secondRunner == true){
					thirdRunner = true;
					secondRunner = false;
				}
				if(firstRunner == true){
					secondRunner = true;
				}
				firstRunner = true;
			}else if(str == "HOMERUN"){
				//add score
				if(thirdRunner == true){
					++score;
					thirdRunner = false;
				}
				if(secondRunner == true){
					++score;
					secondRunner = false;
				}
				if(firstRunner == true){
					++score;
					firstRunner =  false;
				}
				++score;
			}else if(str == "OUT"){
				//add out count
				++outCount;
			}
		}

		std::cout << score << std::endl; //output inning score
		--n;
	}

	return 0;
}