#include <iostream>
using namespace std;

int main() {
  int n,first,second,third,point,out;
  string str;
  cin >> n;
  for(int i=0;i<n;i++) {
    point = 0;
    out = 0;
    first = 0;
    second = 0;
    third = 0;
    while(cin >> str) {
      //     cout << str << endl;                                                    
      if(str == "HIT") {
        if(third == 1) {
          third = 0;
          point++;
        }
        if(second == 1) {
          second = 0;
          third = 1;
        }
        if(first == 1) {
          second = 1;
        }
        first = 1;
      }
      else if(str == "OUT") {
        out++;
        if(out == 3) break;
      }
      else if(str == "HOMERUN") {
        point += 1 + first + second + third;
        first = 0;
        second = 0;
        third = 0;
      }
    }
    cout << point << endl;
  }

}