gets.to_i.times {
	out = 0
	run = 0
	base = 0
	loop {
		case gets.chomp
		when 'HIT'
			base |= ((base ^ (base+1)) & base << 1) | 1
			run += base >> 3
			base &= 7
		when 'OUT'
			out += 1
			break if out == 3
		when 'HOMERUN'
			run += 1
			(0..2).each{|i| run += base[i]}
			base = 0
		end
	}
	puts run
}