#include<iostream>
#include<string>

int main()
{
	bool base[4];
	int out;
	int n;
	int score;
	std::string event;

	std::cin>>n;
	for(int k=0;k<n;k++)
	{
		for(int i=0;i<4;i++)base[i]=0;
		out=0;
		score=0;
		while(out<3)
		{
			std::cin>>event;
			if(event=="HIT")
			{
				for(int i=2;i>=0;i--)
				{
					base[i+1]=base[i];
				}
				base[0]=true;
				if(base[3]==true)
				{
					score++;
					base[3]=false;
				}
			}
			else if(event=="HOMERUN")
			{
				for(int i=2;i>=0;i--)
				{
					if(base[i])
					{
						score++;
						base[i]=false;
					}
				}
				score++;
			}
			else if(event=="OUT")
			{
				out++;
			}
		}
		std::cout<<score<<std::endl;
	}
	return 0;
}