gets.to_i.times do
  score, count, base = 0, 0, [false] * 3
  
  while count < 3
    case gets.chomp
    
    when "HIT"
      if base[2]
        base[2] = false
        score += 1
      end
      base[1], base[2] = false, true if base[1]
      base[0], base[1] = false, true if base[0]
      base[0] = true
    
    when "HOMERUN"
      score += base.count(true) + 1
      base = [false] * 3
    
    when "OUT"
      count += 1
    end
  end
  
  puts score
end