#include<iostream>
using namespace std;
int main(void){
    int n;
    cin>>n;
    while(n){
        int OUTPOINT=0,count=0,HITPOINT=0;
        while(OUTPOINT != 3){
            string s;
            cin >> s;
            if(s=="HIT"){
                if(HITPOINT == 3)     count++;
                else                HITPOINT++;
            }
            else if(s=="OUT")       OUTPOINT++;
            else{
                count+=++HITPOINT;
                HITPOINT=0;
            }
        }
        cout << count << endl;
        n--;
    }
}
