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

int main()
{
	string in;
	bool runner[3];
	int point,out,n;
	int i,j;

	scanf("%d",&n);

	for(i = 0; i < n; i++){
		out = 0;
		point = 0;
		for(j = 0; j < 3; j++){
			runner[j] = false;
		}

		while(out < 3){
			cin >> in;
			if(in == "HIT"){
				if(runner[2]){
					point++;
				}
				else if(runner[1]){
					runner[2] = true;
				}
				else if(runner[0]){
					runner[1] = true;
				}
				else{
					runner[0] = true;
				}
			}
			else if(in == "OUT"){
				out++;
			}
			else if(in == "HOMERUN"){
				for(j = 0; j < 3; j++){
					if(runner[j]){
						runner[j] = false;
						point++;
					}
				}
				point++;
			}
		}
		printf("%d\n",point);
	}

	return 0;
}