#include <iostream>
#include <string>
#include <cstring>

int main(void){
    using namespace std;
    
    int i,j,k,l;
    int data_set;
    string data;
    int out;
    int field[4];
    int point;
    
    cin>>data_set;
    for(i=0;i<data_set;i++){
        out=0;
        memset(field,0,sizeof(field));
        
        while(out<3){
            cin>>data;
            if(data=="HIT"){
                field[3]+=field[2];
                field[2]=field[1];
                field[1]=field[0];
                field[0]=1;
            }
            else if(data=="HOMERUN"){
                for(j=0;j<3;j++){
                    field[3]+=field[j];
                    field[j]=0;
                }
                field[3]++;
            }
            else if(data=="OUT"){
                out++;
            }
        }
        point=field[3];
        cout<<point<<endl;
    }
    return(0);
}