$<.gets.to_i.times do
  bases = [0, 0, 0]
  out_count = 0
  points = 0
  while out_count < 3
    case $<.gets.chomp
    when "OUT"
      out_count += 1
      puts points if out_count >= 3
    when "HIT"
      bases << 1
      points += bases.shift
    when "HOMERUN"
      points += bases.sum + 1
      bases = [0, 0, 0]
    else
      raise "error"
    end
  end
end
