def hit(runner)
	@runner=runner
	@runner[3] += @runner[2]
	@runner[2] = @runner[1]
	@runner[1] = @runner[0]
	@runner[0] = 1
end

def homerun(runner)
	@runner[3]+=@runner[2]+@runner[1]+@runner[0]+1
	@runner[2] = 0
	@runner[1] = 0
	@runner[0] = 0
end

n=gets.to_i
for i in 0..n-1
	runner=Array.new(4,0)
	outcount=0
	while outcount < 3
		event=gets.chomp
			case event
			when "HIT"
				hit(runner)
			when "HOMERUN"
				homerun(runner)
			when "OUT"
				outcount+=1
			end
	end
	puts runner[3]
end