#include <iostream>

using namespace std;

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int out = 0;
    int point = 0;
    int r1 = 0, r2 = 0, r3 = 0;
    while (out <= 2) {
      string str;
      cin >> str;
      if (str == "HIT") {
        if (r3) point++;
        r3 = r2; r2 = r1; r1 = 1;
      } else if (str == "OUT") {
        out++;
      } else if (str == "HOMERUN") {
        point += r1 + r2 + r3 + 1;
        r1 = r2 = r3 = 0;
      }
    }
    cout << point << endl;
  }

  return 0;
}