class Game
  def initialize
    @out = 0
    @point = 0
    @runner = 0
  end

  def out
    @out += 1
  end

  def hit
    if @runner == 3
      @point += 1
    else
      @runner += 1
    end
  end

  def homerun
    @point += @runner + 1
    @runner = 0
  end

  def continue?
    @out != 3
  end

  def score
    return @point
  end
  
end

def main
  gets.to_i.times do
    game = Game.new
    while game.continue?
      game.send(gets.downcase.chomp)
    end
    puts game.score
  end
end
main