#include <iostream>
#include <string>

using namespace std;

int main()
{
	int n,p,c,o;
	string event;
	
	cin>>n;
	while(n>0){
		p=o=c=0;
		while(1){
			cin>>event;
			if(event=="HOMERUN"){
				p+=c+1;
				c=0;
			}
			else if(event=="OUT"){
				o+=1;
			}
			else{
				c+=1;
				if(c==4){
					c--;
					p++;
				}
			}
			if(o==3)break;
		}
		cout<<p<<endl;
		n--;
	}
	return 0;
}