#include<iostream>
#include<cstring>
using namespace std;
int main(){
  int n;
  cin>>n;
  int out=0;
  int score;
  string a;
  bool rui[3]={0};
  for(int i=0;i<n;i++){
    out=0; score=0;
    for(int j=0;j<3;j++){
      rui[j]=false;
    }
    while(out<3){
      cin>>a;
      if(a=="OUT")out++;
      if(a=="HIT"){
	if(rui[2]){rui[2]=false;score++;}
	if(rui[1]){rui[1]=false;rui[2]=true;}
	if(rui[0]){rui[0]=false;rui[1]=true;}
	rui[0]=true;
      }
      if(a=="HOMERUN"){
	score++;
	for(int j=0;j<3;j++){
	  if(rui[j]){rui[j]=false;score++;}
	}
      }
    }
    cout<<score<<endl;
  }
}