#include <iostream>
using namespace std;
int main()
{
  int n;
  cin >> n;
  while(n--){
    string str;
    int o = 0, p = 0, r=0;
    while(o < 3){
      cin >> str;
      if(str == "HIT"){
	if(r<3) r++;
	else p++;
      }else if(str == "HOMERUN"){
	p += r+1;
	r = 0;
      }else if(str == "OUT"){
	o++;
      }
    }
    cout << p << endl;
  }
  return 0;
}