#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
        vector<int> point,runner;
        int d;
        string s;
        cin>>d;
        point.reserve(d);
        runner.reserve(d);
        for(int j = 0 ; j < d ; j++){
        fill(point.begin(),point.end(),0);
        fill(runner.begin(),runner.end(),0);
        for(int i=0; i < 3;){
                
                cin>>s;
                
                        if(s=="HIT"){
                        runner[j]++;
                                if(runner[j]>3){
                                        runner[j]--;
                                        point[j]++;
                                }
                        }
                        else if(s=="HOMERUN"){
                        point[j] += (1 + runner[j]);
                        runner[j] =0;
                        }
                        else if(s=="OUT"){
                        i++;
                        }
                
                }
        
        }
        
        for(int i = 0;i < d; i++) cout<<point[i]<<endl; 
}