#include<iostream>
#include<string>
using namespace std;
int casenum;
int runner,strike,out,point;
string str;


int main(){
  cin >> casenum;
  for(int i = 0;i < casenum;i++){
    runner = strike = out = point = 0;
    while(1){
      cin >> str;
      if(str == "HIT"){
	strike = 0;
	if(runner == 3)point += 1;
	else runner++;
      }else if(str == "OUT"){
	out++;
	strike = 0;
	if(out == 3)break;
      }else if(str == "HOMERUN"){
	point += (runner+1);
	runner = strike = 0;
      }
    }
    cout << point << endl;
  } 
  return 0;
}