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