#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cmath>
#define pb(in,tmp) in.push_back(tmp)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) loop(i,0,b)
using namespace std;
int main(){
int n;
cin>>n;
rep(i,n){
int out=0;
int r1=0,r2=0,r3=0;
int tm=0;
while(out!=3){
char in[10];
cin>>in;
if(strcmp(in,"OUT")==0)out++;
if(strcmp(in,"HIT")==0){
if(r3==1){tm++;r3=0;}
if(r2==1){r3=1;r2=0;}
if(r1==1){r2=1;r1=0;}
r1++;
}
if(strcmp(in,"HOMERUN")==0){
if(r1==1){tm++;r1=0;}
if(r2==1){tm++;r2=0;}
if(r3==1){tm++;r3=0;}
tm++;
}
}
cout<<tm<<endl;
}
}