#include<iostream>
#include<string>
using namespace std;
int l,r,O,p,i;
string s;
int main(){cin>>l;
for(i=0;i<l;i++){p=0;O=0;r=0;
  while(O<3){cin>>s;
    if(s=="HOMERUN"){p+=r+1;r=0;}
    if(s=="OUT"){O++;}
    if(s=="HIT"){if(r==3){p++;}else{r++;}}
}cout<<p<<"\n";}}