#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    int ans = 0, out = 0;
    int p[3] = {};
    while (out < 3) {
      cin >> s;
      if (s == "HIT") {
        ans += p[2];
        p[2] = p[1];
        p[1] = p[0];
        p[0] = 1;
      } else if (s == "HOMERUN") {
        ans += p[0] + p[1] + p[2] + 1;
        p[0] = p[1] = p[2] = 0;
      } else {
        out++;
      }
    }
    cout << ans << endl;
  }

  return 0;
}
