$<.gets.to_i.times do
	point = 0
	out = 0
	runner = 0

	$<.each_line do |line|
		case line.chomp
		when 'HIT'
			runner = (runner << 1) + 1
			if runner[3] == 1
				runner &= 7
				point += 1
			end
		when 'OUT'
			out += 1
			break if out == 3
		when 'HOMERUN'
			point += 3.times.map{|i| runner[i]}.inject(&:+) + 1
			runner = 0
		end
	end

	p point
end