#include <iostream>
#include <string>

int main() {
	
	int n;
	
	std::cin >> n;
	
	while(n-->0) {
		int a[3] = { 0, 0, 0};
		int point = 0;
		int out = 0;
		std::string commands = "";
		while(1) {
			std::cin >> commands;

			// HIT
			if( commands == "HIT") {
				if( a[2] == 1) point ++;
				a[2] = a[1];
				a[1] = a[0];
				a[0] = 1;
			}

			// OUT
			if( commands == "OUT") out ++;

			// HOMERUN
			if( commands == "HOMERUN") {
			for( int j=0; j<3; j++)
				if( a[j] == 1) {
					point ++;
					a[j] = 0;
				}
				point ++;
			}

			if(out==3) break;
		}
		
		std::cout << point << std::endl;
	}
	return 0;
}