#include<iostream>
#include<string>
using namespace std;
int main(){
	int a,b,c,d;
	int score;
	int out=0;
	int n;
	cin>>n;
	while(n--){
		score=a=b=c=d=0;
		out=0;
		string e;
		while(out!=3){
			cin>>e;
			if(e=="HIT"){
				d=c;c=b;b=a;a=1;
				score+=d;d=0;	
			}else if(e=="HOMERUN"){
				score += a+b+c+1;
				a=b=c=0;
			}else{
				out++;
			}
		}
		cout<<score<<endl;
	}
	return 0;
}