#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
int main(){
    int time;
    cin >> time;
    rep(t,time){
        int base[3], old[3];
        int out = 0, point = 0;
        rep(i,3) base[i] = 0;
        string s;
        while(cin >> s){
            if(s == "HIT"){
                old[0] = base[0];
                old[1] = base[1];
                old[2] = base[2];
                if(old[0]) base[1] = 1;
                if(old[1]) base[2] = 1;
                if(old[2]) point++;
                base[0] = 1;
            }
            if(s == "HOMERUN"){
                point++;
                if(base[0]) point++;
                if(base[1]) point++;
                if(base[2]) point++;
                base[0] = 0;
                base[1] = 0;
                base[2] = 0;
            }
            if(s == "OUT"){
                out++;
                if(out == 3) break;
            }

        }
        cout << point << endl;
    }
    return 0;
}
