#include<iostream>
#include<string>

using namespace std;

int main(){
  int i, j, n, count, outcount, data[3];
  string event;

  cin >> n;

  for(i=0; i<n; ++i){
    count = 0;
    outcount = 0;
    for(j=0; j<3; ++j)
      data[j] = 0;

    while(1){
      cin >> event;

      if(event == "HOMERUN"){
        ++count;
        for(j=0; j<3; ++j){
          if(data[j] == 1){
            ++count;
            data[j] = 0;
          }
        }
      }else if(event == "HIT"){
        if(data[2] == 1) ++count;
        data[2] = data[1];
        data[1] = data[0];
        data[0] = 1;
      }else if(event == "OUT"){
        ++outcount;
      }

      if(outcount == 3) break;
    }

    cout << count << endl;
  }

  return 0;
}