#include<iostream>

using namespace std;

int main(void) {
	string event;
	bool first, second, third, home;
	int inning, out, points;
	int i;

	cin >> inning;
	for(i = 0; i < inning; i++) {
		points = 0;
		out = 0;
		first = false;
		second = false;
		third = false;
		home = false;
		while(out < 3) {
			cin >> event;
			if(event == "HIT") {
				home = third;
				third = second;
				second = first;
				first = true;
				if(home) {
					points++;
					home = false;
				}
			} else if(event == "HOMERUN") {
				if(first) {
					points++;
					first = false;
				}
				if(second) {
					points++;
					second = false;
				}
				if(third) {
					points++;
					third = false;
				}
				points++;
			} else if(event == "OUT") {
				out++;
			}
		}
		cout << points << endl;
	}

	return 0;
}