#include <iostream>
#include <string>
using namespace std;

int main(void)
{
  int point;
  int single_hit;
  int out;
  int inning;
  string event;

  cin >> inning;

  for(int i = 0 ; i < inning ; i++)
    {
      point = 0;
      out = 0;
      single_hit = 0;

      while(1)
	{
	  if(out == 3) break;
	  
	  cin >> event;
	  if(event == "HIT") single_hit++;	  
	  if(event == "OUT") out++;
	  if(event == "HOMERUN") 
	    {
	      point += (single_hit + 1);
	      single_hit = 0;
	    }
	  if(single_hit == 4)
	    {
	      point++;
	      single_hit--;
	    }
	}
      cout << point << endl;
    }
  return 0;
}