#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#define PI 3.141592653589793
using namespace std;
int main(){
	int n;
	string str;
	cin>>n;
	for(int i=0;i<n;i++){
		int cnt=0,num=0;
		int rui[5]={0};
		while(cin>>str){
			if(str=="HIT"){
				rui[4]=rui[3];
				rui[3]=rui[2];
				rui[2]=rui[1];
				rui[1]=1;
				if(rui[4]==1){
					rui[4]=0;
					cnt++;
				}
			}else if(str=="HOMERUN"){
				for(int j=1;j<=3;j++){
					if(rui[j]==1){
						rui[j]=0;
						cnt++;
					}
				}
				cnt++;
			}else{
				num++;
				if(num==3)break;
			}
		}
		cout<<cnt<<endl;
	}
	return 0;
}
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n;
  cin>>n;
  string event;
  getline(cin,event,'\n');
  int i=0,out,b,score;
  while(n>0){
    out = 0;
    b = 0;
    score=0;
    while(out<3){
      getline(cin,event,'\n');
      if(event=="HIT"){
	b*=2;
	b+=1;
	if(b>8){
	  b-=8;
	  score++;
	}
      }
      if(event=="HOMERUN"){
	while(b>0){
	  score+=b%2;
	  b/=2;
	}
	score++;
      }
      if(event=="OUT"){
	out++;
      }
    }
    cout<<score<<endl;
    n--;
  }
  return 0;
}