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

int main() {
  int n, s, r, o;
  string e;

  cin >> n;
  for (int i=0; i<n; i++) {
    s = r = o = 0;
    while (1) {
      cin >> e;
      if (e == "HIT") {
        if (++r >= 4) {
          ++s;
          --r;
        }
      } else if (e == "HOMERUN") {
        s += r+1;
        r = 0;
      } else if (e == "OUT") {
        o++;
        if (o >= 3) break;
      }
    }
    cout << s << endl;
  }

  return 0;
}