#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
using namespace std;

int loop;
int runner,OUT,point;
string stait;

int main(){
  scanf("%d",&loop);
  for(int i=0;i<loop;i++){
    point = 0;
    OUT=0;
    runner=0;
      while(OUT<3){
	cin>>stait;
	if(stait=="HOMERUN"){
	  point += runner + 1;
	  runner = 0;
	}
	if(stait=="OUT"){
	  OUT++;
	}
	if(stait=="HIT"){
	  if(runner==3){
	    point++;
	  }else{
	    runner++;
   	  }
	}
      }
      printf("%d\n",point);
  }
}