#include<iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  
  while(n--){
    int runner = 0;
    int out = 0;
    int point = 0;
    
    while(out<3) {
      string s;
      cin >> s;
      
      if(s=="HIT"){
	runner++;
      }

      else if (s=="OUT"){
	out++;
      }

      else if (s=="HOMERUN"){
	point+=runner+1;
	runner = 0;
      }
      
      if(runner == 4) {
	point++;
	runner = 3;
      }
      
    }
    cout << point << endl;
  }
  return 0;
}

