#include<iostream>
#include<string>
using namespace std;
int main(){
  int n;
  int hit,out;
  int score;
  string c;
  cin >> n;
  for(int i=0;i<n;i++){
    hit = 0; 
    out = 0;
    score = 0;
    while(out!=3){
      cin >> c;
      if(c=="HIT"){
	hit++;
	if(hit==4){
	  score += 1;
	  hit = 3;
	}
      }
      else if(c=="HOMERUN"){
	score += (hit+1);
	hit =  0;
      }
      else out++;
    }
    cout << score << endl;
  }
  return 0;
}