#include <iostream>
#include <vector>
using namespace std;

int main(){
    int n;
    cin >> n;

    for(int i=1; i<=n; i++){
        vector<bool> base;
        for(int j=1; j<=3; j++){
            base.push_back(false);
        }
        int out = 0;
        int point = 0;
        while(1){
            if(out == 3) break;
            string str;
            cin >> str;
            if(str == "HIT"){
                if(base[2] == true){
                    base[2] = false;
                    point++;
                }
                if(base[1] == true){
                    base[2] = true;
                    base[1] = false;
                }
                if(base[0] == true){
                    base[1] = true;
                }
                base[0] = true;
            }
            if(str == "HOMERUN"){
                int cnt = 0;
                for(int j=0; j<3; j++){
                    if(base[j] == true){
                        base[j] = false;
                        cnt++;
                    }
                }
                point += cnt + 1;
            }
            if(str == "OUT"){
                out++;
            }
        }
        cout << point << endl;
    }
    return 0;
}