#include <bits/stdc++.h>

using namespace std;

int main(){
        int N;
        int out=0;
        cin>>N;
        N*=3;
        string str;
        int ans=0;
        int run=0;
        while(out<N){
                cin>>str;
                if(str=="HIT"){
                        run++;
                        if(run>=4){
                                ans++;
                                run--;
                        }
                }
                else if(str=="OUT"){
                        out++;
                        if(out%3==0){
                                cout<<ans<<endl;
                                ans=0;
                                run=0;
                        }
                }
                else if(str=="HOMERUN"){
                        run++;
                        ans+=run;
                        run=0;
                }
        }

return 0;
}
#include <iostream>
#include <cstring>
using namespace std;

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int score = 0, out = 0;
        int bases[3] = {};
        while (true) {
            char event[8];
            cin >> event;
            if (strcmp(event, "OUT") == 0) {
                out++;
                if (out == 3) {
                    break;
                }
            } else if (strcmp(event, "HIT") == 0) {
                score += bases[2];
                bases[2] = bases[1];
                bases[1] = bases[0];
                bases[0] = 1;
            } else if (strcmp(event, "HOMERUN") == 0) {
                score += bases[0] + bases[1] + bases[2] + 1;
                bases[0] = bases[1] = bases[2] = 0;
            }
        }
        cout << score << endl;
    }
}