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

int main(void)
{
	string instr;
	int N;

	cin >> N;

	while(N--, N >= 0){
		int out = 0;
		int pos[4] = {};

		while(out < 3){
			cin >> instr;

			if(instr == "HIT"){
				if(pos[2]){
					pos[3] += pos[2];
					pos[2] = 0;
				}
				swap(pos[2],pos[1]);
				swap(pos[1],pos[0]);
				pos[0] = 1;
			}
			else if(instr == "HOMERUN"){
				pos[3] += pos[0] + pos[1] + pos[2] + 1;
				pos[0] = pos[1] = pos[2] = 0;
			}
			else if(instr == "OUT")
				out++;
	//		cout << pos[0] << ' ' << pos[1] << ' ' << pos[2] << ' ' << pos[3] << endl;
		}
		cout << pos[3] << endl;
	}
			

	return 0;
}