#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
using namespace std;

int loop;
int HIT,OUT,point;
string stait;
int main(){
  scanf("%d",&loop);
  for(int i=0;i<loop;i++){

int base1=0,base2=0,base3=0;
    point = 0;
    OUT=0;
      while(OUT<3){
	cin>>stait;

	if(stait.substr(0,3)=="HIT"){
	  if(base3==1){base3=0;point++;}
	  if(base2==1){base2=0;base3=1;}
	  if(base1==1){base1=0;base2=1;}
	  base1=1;
	}
	if(stait.substr(0,3)=="OUT"){OUT++;}
	if(stait.substr(0,3)=="HOM"){
	  if(base3==1){base3=0;point++;}
	  if(base2==1){base2=0;point++;}
	  if(base1==1){base1=0;point++;}
	  point++;
	}
      };
    printf("%d\n",point);
  }
}