//55
#include<iostream>
#include<string>

using namespace std;

int main(){
  int n;
  cin>>n;
  while(n--){
    int b=0,ans=0,out=0;
    for(string s;cin>>s;){
      if(s=="HIT"){
	b++;
	if(b==4){
	  ans++;
	  b=3;
	}
      }else if(s=="OUT"){
	out++;
	if(out==3)break;
      }else{
	ans+=b+1;
	b=0;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}