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

int main() {
  int n;
  cin >> n;
  while(n--) {
    int runner = 0;
    int score = 0;
    int mask = (1<<3)-1;
    int n_out = 0;
    while(1) {
      string s;
      cin >> s;
      if(s == "HIT") {
        runner = ( (runner<<1) | 1 ) ;
        score += __builtin_popcount(runner & ~mask);
        runner &= mask;
      } else if(s == "HOMERUN") {
        score += __builtin_popcount(runner) + 1;
        runner = 0;
      } else if(s == "OUT") {
        if(++n_out == 3) {
          cout << score << endl;
          break;
        }
      }
    }
  }
  return 0;
}