nstr = gets
n = nstr.to_i

out = 0
base = 0b00
point = 0
inning = 0

while inning < n do
	event = gets

	case event
	when /OUT.*/
		out += 1
	when /HOMERUN.*/
		point += 1
		point += 1 if base[0] == 1
		point += 1 if base[1] == 1
		point += 1 if base[2] == 1
		base = 0b00
	when /HIT.*/
		base = base << 1
		if base[3] == 1 then
			point += 1
			base -= 0b1000
		end
		base += 0b01
	else
		print("undefined event: ", event, "\n")
	end

	if out == 3 then
		print(point, "\n")
		out = 0
		point = 0
		base = 0
		inning += 1
	end
end