var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var n=Arr.shift()-0;
for(var j=0;j<n;j++){
   var out=0;
   var runner=0;
   var score=0;
   while(out<3){
      var v=Arr.shift();
      if(v=="HIT"){
         runner++;
         if(runner==4){runner--;score++;}
      }
      if(v=="HOMERUN"){score+=(runner+1);runner=0;}
      if(v=="OUT")out++;
   }
   console.log(score);
}