#include<iostream>
#include<cstring>

using namespace std;

int main(){
  int n;
  cin>>n;
  int point[33];
  int out[33];
  for(int i=0;i<33;i++){
    point[i]=0;
    out[i]=0;
  }
  int first=0;
  int second=0;
  int third=0;
  int number=0;
  char input[10];
  for(int i=0;i<n;i++){
    while(out[i]<3){
      cin>>input;
      if(strcmp(input,"HIT")==0){
	if(third==1){
	  point[i]++;
	}
	if(second==1){
	  third=1;
	}
	if(first==1){
	  second=1;
	}
	first=1;
      }
      if(strcmp(input,"HOMERUN")==0){
	int number=0;
	if(first==1){
	  number++;
	}
	if(second==1){
	  number++;
	}
	if(third==1){
	  number++;
	}
	point[i]+=(number+1);
	first=0;second=0;third=0;
      }
      if(strcmp(input,"OUT")==0){
	out[i]++;
      }
      if(out[i]==3){
	first=0;second=0;third=0;
      }
    }
  }
  for(int i=0;i<n;i++){
    cout<<point[i]<<"\n";
  }
  return 0;
}