#include<iostream>
using namespace std;

int main(){
  int n;
  cin >> n;
  while(n--){
    int out = 0, score = 0, runner = 0;
    while(out<3){
      string s;
      cin >> s;
      if(s == "HIT"){
	runner++;
	if(runner == 4){
	  score++; runner--;
	}
      }else if(s == "HOMERUN"){
	score += runner+1;
	runner = 0;
      }else{
	out++;
      }
    }
    cout << score << endl;
  }
}