#include<iostream>
#include<string>
using namespace std;
int main(){
long n,r,p,o,i;
string s;
cin>>n;
for(i=0;i<n;i++){
o=p=r=0;
while(cin>>s){
if(s=="HIT"){
r*=2;r++;if(r>=8){p++;r-=8;}
}else if(s=="HOMERUN"){
if(r==0)p++;
else if(r==1||r==2||r==4)p+=2;
else if(r==3||r==5||r==6)p+=3;
else if(r==7)p+=4;
r=0;
}else if(s=="OUT"){
o++;
if(o>=3)break;
}
}
cout<<p<<endl;
}
return 0;
}