#include<iostream>
#include<string>
using namespace std;
int main(){
  int n;
  cin >>n;
  while(n--){
    int point = 0,out = 3;
    bool base[3] = {0};
    string order;
    while(cin>>order){
      if(order == "HIT"){
	if(base[2]){point++;}
	for(int i=2; i>0; i--){
	  base[i] = base[i-1];
	}
	base[0] = true;
      }
      if(order == "HOMERUN"){
	point++;
	for(int i=0; i<3; i++){
	  if(base[i]){point++;}
	  base[i] = false;
	}
      }
      if(order == "OUT"){
	out--;
      }
      if(!out){break;}
    }
    cout <<point<<endl;
  }
  return 0;
}