#include <iostream>
using namespace std;
void HIT(void);
void HOMERUN(void);
void OUT(void);

int main(void){
    int data, score, out, first, second, third;
    string event;
    
    cin >> data;
    for(int i=0; i<data; i++){
        out=0;
        score=0;
        first=0;
        second=0;
        third=0;
        
        while(out<3){
            cin >> event;
            if(event=="HIT"){
                if(third==1){
                    third=0;
                    score++;
                }
                if(second==1){
                    third=1;
                    second=0;
                }
                if(first==1){
                    second=1;
                    first=0;
                }
                first=1;
            }
            else if(event=="HOMERUN"){
                int count=0;
                if(first==1) count++;
                if(second==1) count++;
                if(third==1) count++;
                score += count+1;
                first=0;
                second=0;
                third=0;
            }
            else if(event=="OUT"){
                out++;
            }
        }
        cout << score << endl;
    }
    return 0;
}

