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

int main(void){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		int score=0,out=0;
		stack <int> base;
		while(out<3){
			string S;
			cin >> S;
			if(S=="HIT"){
				base.push(1);
				if(base.size()>=4)
					base.pop(),score++;
			}else if(S=="HOMERUN"){
				score++;
				while(!base.empty())
					score++,base.pop();
			}else if(S=="OUT")
				out++;
		}
		cout << score << endl;
	}
	return 0;
}