#include<iostream>
#include<string>
#include<new>

using namespace std;
#define ALLAY_SIZE(a)  sizeof((a))/sizeof(*(a))

enum BASE_NO{
  FIRST = 0,
  SECOND,
  THIRD,

  BASE_NUM
};

enum PUT_IN {
  HIT = 0,
  HOMERUN,
  OUT,

  IN_NUM
};
static const string put_in[IN_NUM]{
  "HIT",
  "HOMERUN",
  "OUT"
};

class Base
{
public:
  Base() { Reset(); }
  void BaseIn(int base) { base_exist[base] = true; }
  void BaseOut(int base) { base_exist[base] = false; }
  bool IsBaseIn(int base) { return base_exist[base]; }
  bool Rotate() { 
    bool add_score;

    // ??????????????????????????????
    for (int i = THIRD; i >= 0; i--) {
      int next_base = i + 1;
      
      // ???????????°??????????????´??????TRUE?????????
      if (i == THIRD) add_score = IsBaseIn(i);
      else            base_exist[next_base] = base_exist[i];
    }

    return add_score;
  }
  int Reset() {
    // ?????????????????????reset???????????°?????????
    int runnner_count = 0;
    for (int i = 0; i < ALLAY_SIZE(base_exist); i++) {
      if (IsBaseIn(i)) runnner_count++;
      BaseOut(i);
    }
    
    return runnner_count;
  }
private:
  bool base_exist[BASE_NUM];
};

class BaseballGame
{
public:
  BaseballGame() : score(0), out_count(0), is_game_end(false) {}
  void Hit() {
    //  ???????????????????????¬????????°?????????????????°?????????????¶???????
    if (base.Rotate())
      score++;
    //  ???????????????????????????????????????
    base.BaseIn(FIRST);
  }
  void Homerun() {
    //  ??°?????°??????????????????
    Hit();
    //  ???????????°?????¨????????¬????????????
    int add_score = base.Reset();
    // ?????????????????°????????°??????????????????
    score += add_score;
  }
  void Out() {
    // ??¢???????????????????????????
    out_count++;
    // ??¢?????????????????????3??????????????¨??????????????°??????
    if (out_count >= GAMEEND_OUT_NUM)
      is_game_end = true;
  }

  int   GameScore() {
    return score;
  }
  bool  IsGameEnd() {
    return is_game_end;
  }
private:
  const int GAMEEND_OUT_NUM = 3;

	int   score;
  int   out_count;
  Base  base;
  bool  is_game_end;
};

int main() {
  int game_num;
  cin >> game_num;
  for (int i = 0; i < game_num; i++) {
    BaseballGame game;
    while (!game.IsGameEnd()) {
      string in_data;
      cin >> in_data;

      if (in_data == put_in[HIT])
        game.Hit();
      else if (in_data == put_in[HOMERUN])
        game.Homerun();
      else if (in_data == put_in[OUT])
        game.Out();
    }
    cout << game.GameScore() << endl;
  }
}