import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
//import std.regex;
import std.container;

void main()
{
	auto n = readln.chomp.to!int;
	int cnt;

	while (cnt < n) {
		int outCnt, score;
		int base;

		while (outCnt < 3) {
			auto str = readln.chomp;
			if (str == "OUT") { 
				outCnt++;
			} else if (str == "HOMERUN") {
				score += base + 1;
				base = 0;
			} else {
				if (base == 3) score++;
				else base++;
			}
		}
		score.writeln;
		cnt++;
	}
}