#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;

int main() {
  int n;
  cin >> n;
  while (n--) {
    string str;
    vector<int> vec = {0, 0, 0};
    int out = 0;
    while (cin >> str) {
      if (str == "HIT") {
        vec.push_back(1);
      }
      else if (str == "OUT") {
        ++out;
      }
      else if (str == "HOMERUN") {
        vec.push_back(1);
        for (int j = 0; j < 3; ++j)
          vec.push_back(0);
      }
      if (out == 3)
        break;
    }
    cout << accumulate(vec.begin(), vec.end() - 3, 0) << endl;
  }
}
