class Baseball
  attr_accessor :point, :first, :second, :third, :out_count
  def initialize
    @point = 0
    @out_count = 0
    @first = false
    @second = false
    @third = false
  end

  def hit
    @first, @second, @third, @point = [true, @first, @second, @third ? @point+1 : @point]
  end

  def homerun
    @point += 1
    @point += 1 if @first
    @point += 1 if @second
    @point += 1 if @third
    @first, @second, @third = [false, false, false]
  end

  def out
    @out_count += 1
  end

  def exit?
    @out_count >= 3
  end
end

def main
  round = Integer(gets)
  round.times do
    game = Baseball.new
    while true
      if game.exit?
        puts game.point
        break
      end

      case gets.chomp
      when "HIT"
        game.hit
      when "OUT"
        game.out
      when "HOMERUN"
        game.homerun
      end
    end
  end
end

main