n=gets.to_i
n.times{
	runner=Array.new(4,0)
	outcount=0
	while outcount < 3
		event=gets.chomp
			case event
			when "HIT"
				runner[3] += runner[2]
				runner[2] = runner[1]
				runner[1] = runner[0]
				runner[0] = 1
			when "HOMERUN"
				runner[3]+=runner[2]+runner[1]+runner[0]+1
				runner[2] = 0
				runner[1] = 0
				runner[0] = 0
			when "OUT"
				outcount+=1
			end
	end
	puts runner[3]
}