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

int main(){

  int n;
  string daseki;
  cin >> n;

  for(int i=0;i<n;i++){

    int a[5] = {0},count = 0,out = 0;

    while(1){
      if(out == 3) break;

      cin >> daseki;

      if(daseki == "HIT"){
	if(a[3] == 1){
	  count++;
	  a[3] = 0;
	}
	if(a[2] == 1){
	  a[3] = 1;
	  a[2] = 0;
	}
	if(a[1] == 1){
	  a[2] = 1;
	  a[1] = 0;
	}
	a[1] = 1;
      }

      if(daseki == "HOMERUN"){
	count++;
	for(int j=1;j<=3;j++){
	  if(a[j] == 1){
	    count++;
	    a[j] = 0;
	  }
	}
      }

      if(daseki == "OUT") out++;
    }

    cout << count << endl;

  }
}