#include <iostream>
#include <vector>
#include <string>
#include <cstdio>

using namespace std;

int main(){
	string ev[] = {"HIT", "OUT", "HOMERUN"};
	int n;
	cin >> n;
	while(n--){
		string s;
		int out = 0;
		int state = 0;
		int runner = 0;
		int point = 0;
		while(out < 3){
			cin >> s;
			if(s == ev[0]){
				state = state << 1;
				state++;
				if(state&(1<<3)){
					point++;
				}else{
					runner++;
				}
			}else if(s == ev[1]){
				out++;
			}else if(s == ev[2]){
				point += ++runner;
				state = 0;
				runner = 0;
			}
		}
		cout << point << endl;
	}

	return 0;
}