#include<iostream>
using namespace std;
int main(){
  int n,poi[100],hit,hom,out;
  string exam;
  cin>>n;
  for(int j=0;j<100;j++){
    poi[j]=0;
  }
  for(int i=0;i<n;i++){
    hit=0,hom=0,out=0;
    while(1){
      cin>>exam;
      if(exam=="HIT"){
	hit++;
      }
      if(hit==4){
	hit--;
	poi[i]++;
      }if(exam=="OUT"){
	out++;
      }
      if(out==3){
	break;
      }if(exam=="HOMERUN"){
	poi[i]+=hit;
	poi[i]++;
	hit=0;
      }
    }
  }
  for(int i=0;i<n;i++){
    cout<<poi[i]<<endl;
  }
  return 0;
}
  