#include<iostream>
#include<string>

using namespace std;

void baseball(){
    bool first=false, second=false, third=false;
    int runner=0;
    int outCount=0;
    int score=0;
    string event;
    string hit = "HIT";
    string homerun = "HOMERUN";
    string out = "OUT";
    
    while(outCount !=3){
        cin >> event;
        if(event == hit){
            if(third==true) runner--,score++;
            if(second==true) third=true;
            if(first==true) second=true;
            first=true;
            runner++;
        }
        else if(event == homerun){
            score += runner+1;
            first=false, second=false, third=false;
            runner=0;
        }
        else if(event == out){
            outCount++;
        }
        
    }
    cout << score<<endl;
}


int main(){
    
    int c;
    cin >> c;
    
    for(int i=0;i<c;i++){
        
        baseball();
        
    }
    return 0;
}