class Baseball
   def initialize
      @base={first: false,second: false ,third: false}
      @point=0
      @outnum=0
   end
   def hit
      if @base[:third]
         @base[:third]=false
         @point += 1
      end
      if @base[:second]
         @base[:third]=true
         @base[:second]=false
      end
      if @base[:first]
         @base[:second]=true
         @base[:first]=false
      end
      @base[:first]=true
   end
   def homerun
      @point += 1
      @base.each do |key,val|
         @point+=1 if val
         @base[key]=false
      end
   end
   def out
      @outnum+=1
      if @outnum == 3
         puts @point
      end
   end
   def gameover?
      return true if @outnum >= 3
      return false
   end
end

n=gets.to_i
n.times do
   obj=Baseball.new
   until obj.gameover? do
      str=gets.chop
      obj.hit if 'HIT'==str
      obj.homerun if 'HOMERUN'==str
      obj.out if 'OUT'==str
   end
end