#include <iostream>
#include<string.h>
using namespace std;
int main (int argc, const char * argv[])
{

    int n=0;
    bool b[3]={0};
    cin>>n;
    int out=0;
    string eve;
    int point=0;
    for(int i=0;i<n;i++){
        point=0;out=0;
        b[0]=false;b[1]=false;b[2]=false;
        while(out<=2){
            cin>>eve;
            if(eve=="OUT"){
                out++;
                if(out==3){
                    break;
                }
            }
            
            if(eve=="HIT"){
                if(b[2]){point++;b[2]=false;}
                if(b[1]){b[2]=true;b[1]=false;}
                if(b[0]){b[1]=true;b[0]=false;}
                b[0]=true;
                
            
            }
            
            
            if(eve=="HOMERUN"){
                point++;
                for(int j=0;j<=2;j++){
                    if(b[j]){point++;b[j]=false;}
                }
            }
            
            
        }
        cout<<point<<endl;
    }
    return 0;
}