#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
  int n;
  cin >> n;
  for(int i =0; i < n; i++){
    int base = 0;
    int p = 0;
    for(int out = 0; out < 3;){
      string str;
      cin >> str;
      if(str == "HIT"){
	base++;
      }else if(str == "OUT"){
	out++;
      }else{
	p += base + 1;
	base = 0;
      }
    }
    p += max(0,base - 3);
    cout << p << endl;
  }
}