#include <iostream>
using namespace std;

int main(){
  int n;
  cin >> n;

  while(n--){
    int score = 0;
    int out = 0;
    int first = 0, second = 0, third = 0;

    while(out != 3){
      string s;
      cin >> s;

      if(s == "HIT"){
        score += third;
        third = second;
        second = first;
        first = 1;
      }
      else if(s == "OUT"){
        out++;
      }
      else{
        score += first + second + third + 1;
        first = second = third = 0;
      }
    }

    cout << score << endl;
  }
}