#include<iostream>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<numeric>
#include<vector>
#include<cstdio>
#include<climits>
#include<cfloat>
#include<cstring>
#define foreach(t,p) for(t::iterator it=p.begin();it!=p.end();++it)
#define rforeach(t,p) for(t::reverse_iterator it=p.rbegin();it!=p.rend();++it)
#define all(p) p.begin(),p.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define FOREACH(t,p,tit) for(t::iterator tit=p.begin();tit!=p.end();++tit)
using namespace std;
int main()
{
    int n;
    cin>>n;
    while(n--)
    {
        int lunner[3]={};
        int points = 0;
        int outs = 0;
        string ss;
        while(cin>>ss)
        {
            if(ss=="HOMERUN")
            {
                points++;
                rep(i,3){ if(lunner[i]==1){lunner[i]=0;points++;}}
                continue;
            }
            if(ss=="HIT")
            {
                if(lunner[2]==1){points++;continue;}
                if(lunner[1]==1){lunner[2]=1;continue;}
                if(lunner[0]==1){lunner[1]=1;continue;}
                if(lunner[0]==0){lunner[0]=1;continue;}
            }
            if(ss=="OUT"){outs++;}



            if(outs == 3)break;
        }
        cout << points << endl;
    }

    return 0;
}