#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
   int n,i,l,count,point;
   string hantei;
   queue<int> runner;
   
   cin>>n;
   for(i=0;i<n;i++){
      
      while(!runner.empty()) runner.pop();
      for(l=0;l<3;l++) runner.push(0);
      count=0;point=0;
      
      while(count!=3){
         cin>>hantei;
         
         if(hantei=="HIT"){
            runner.push(1);
            if(runner.front()==1) point++;
            runner.pop();
         }
         else if(hantei=="HOMERUN"){
            runner.push(1);
            for(l=0;l<3;l++) runner.push(0);
            
            for(l=0;l<4;l++){
               if(runner.front()==1) point++;
               runner.pop();
            }
         }
         else if(hantei=="OUT")
            count++;
      }
      cout<<point<<endl;
   }
   return 0;
}