#include <iostream>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;



int main(void){

int n;
string ss;
	while(cin >> n){
		if(cin.eof()) break;
		rep(i,n){
			int ht=0, tt=0, ot=0;
			while(cin >> ss){
				if(ss=="OUT") ot++;
				if(ot > 2) break;
				if(ss=="HIT") ht++;
				if(ht > 3){ tt++; ht=3; }
				if(ss=="HOMERUN"){ tt += ht+1; ht=0;}
			}
			cout << tt << endl;
		}
	}
	return 0;
	
}