#include <iostream>
#include <array>

class Baseball{
	private:
	int out_count;
	std::array<int, 4> runner;
	
	public:
	
	Baseball(){
		out_count = 0;
		for(int i=0; i<4; ++i)
			runner[i] = 0;
	}
	
	void ining(){
		while(out_count != 3){
			std::string str;
			std::getline(std::cin, str);
		
			if(str == "HIT")
				hit();
			else if(str == "OUT")
				out();
			else homerun();
		}
		
		std::cout << runner[3] << std::endl;
		return;
	}
	
	void hit(){
		int i;
		for(i=0; i<4; ++i){
			if(runner[i] == 0){
				runner[i] = 1;
				return;
			}
		}
		++runner[i];
	}
	
	void out(){
		++out_count;
	}
	
	void homerun(){
		for(int i=0; i<4; ++i){
			if(runner[i] == 1){
				++runner[3];
				runner[i] = 0;
			}
		}
	}
};

int main(){
	int n;
	std::cin >> n;
	
	for(int i=0; i<n; ++i){
		Baseball game;
		game.ining();
	}
	
	return 0;
}