#include <iostream>
#include <string>
using namespace std;
int main(void){
    int n; //データセット数
    cin >> n;
        
    for(int i = 1; i <= n; i++){
        int countout = 0; //OUTの発生回数
        int counthit = 0; //HITの発生回数
        int score = 0; //イニングの得点

        while(countout != 3){
            string state;
            cin >> state;
            if(state == "OUT") countout++;
            else if(state == "HIT"){
                counthit++;
                if(counthit == 4){
                    score++;
                    counthit--;
                }
            }    
            else if(state == "HOMERUN"){
                score += counthit + 1;
                counthit = 0;
            }
        } 
        cout << score << endl;     
    }
}

