n.times do
  out = 0 
  score = 0 
  runner = [false,false,false]

  loop do
    case gets.chomp
    when 'HIT'
      if runner[2]
        score += 1
      end 
      runner[2] = runner[1]
      runner[1] = runner[0]
      runner[0] = true
    when 'OUT'
      out += 1
      if out == 3
        break
      end 
    when 'HOMERUN'
      score += runner.select{|x|x}.count + 1 
      runner = [false,false,false]
    end 
  end 

  puts score
end