#include<iostream>
#include<string>
using namespace std;
int main()
{
	int n;
	cin>>n;
	while(n--) 
	{
		bool one=false,two=false,three=false;
		int out=0,ans=0;
		while(1) 
		{
			string in; cin>>in;
			if(in=="OUT")
			{
				out++;
				if(out==3) break;
			}
			else if(in=="HOMERUN")
			{
				int cnt=1;
				cnt+=one?1:0;
				cnt+=two?1:0;
				cnt+=three?1:0;
				one=two=three=false;
				ans+=cnt;
			}
			else
			{
				if(three) ans+=1;
				three=two; two=one; one=true;
			}
		}
		cout<<ans<<endl;
	}
  return 0;
}