#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef long long int ll;

int main(){
    int n; cin >> n;
    for(int z=0;z<n;z++){
        int out=0;
        int points=0;
        int run=0;
        while(out<3){
            string s; cin >> s;
            if(s=="OUT")out++;
            else if(s=="HIT"){
                run++;
                if(run==4){
                    points++;
                    run--;
                }
            }
            else{
                points+=(run+1);
                run=0;
            }
        }
        cout << points << endl;
    }
}
