#include<iostream>
#include<cstdio>

using namespace std;


int main(){
  int n,AUTO,total,home;
  string op;

  scanf("%d",&n);
  for(int i=0;i<n;i++){
    AUTO=0;
    total=0;
    home=0;
    while(true){
      if(AUTO == 3)break;
      cin >> op;
      if(op == "HIT"){
	home = (home<<1)+1;
	if(home>>3){
	  total++;
	  home = home & ~(1<<3);
	}
       
      }
      else if(op == "HOMERUN"){
	for(int i=0;i<3;i++){
	  if(home>>i & 1)total++;
	}
	total++;
	home=0;
      }
      else if(op == "OUT")AUTO++;
    }
    printf("%d\n",total);
  }
  return 0;
}