#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(int argc, char *argv[]) {
  int n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    string s;
    bool runner[4] = {0};
    int score = 0, out = 0;
    while (true) {
      cin >> s;
      if (s == "HIT") {
        for (int j = 0; j <= 4; j++)
          runner[3-j] = (3-j == 0 ? true : runner[2-j]);
        if (runner[3]) {
          runner[3] = false;
          score++;
        }
      } else if (s == "HOMERUN") {
        score++;
        for (int j = 0; j < 3; j++)
          if (runner[j]) {
            runner[j] = false;
            score++;
          }
      } else {
        out++;
      }
      if (out >= 3) {
        cout << score << endl;
        break;
      }
    }
  }
  return 0;
}