import std.stdio, std.conv, std.string, std.algorithm;

void main() {
	uint n = readln.chomp.to!uint;
	uint[] result;
	foreach (i; 0..n) {
		uint outNum = 0;
		bool[3] fieldPlayer;
		uint point = 0;
		while (outNum < 3) {
			auto str = readln.chomp;
			if (str == "HIT") {
					if (fieldPlayer[2]) point++;
					fieldPlayer[2] = fieldPlayer[1];
					fieldPlayer[1] = fieldPlayer[0];
					fieldPlayer[0] = true;
			} else if (str == "OUT") {
					outNum++;
			} else if (str == "HOMERUN"){
					foreach (j; 0..3) {
						if (fieldPlayer[j]) point++;
						fieldPlayer[j] = false;
					}
					point++;
			}
		}
		result ~= point;
	}
	foreach (r; result) r.writeln;
}