class BaseBall
  def initialize
    @first=false
    @second=false
    @third=false
    @out=0
  end

  def hit
    if @third then
      point=1
    else
      point=0
    end
    @third = false
    @third  = true if @second
    @second = true if @first
    @first = true
    return point
  end

  def homerun
    point= [@first,@second,@third].select{|x| x}.length + 1
    @first,@second,@third =false
    return point
  end

  def out
    @out += 1
    if @out>= 3 then
      @out=0
      return true
    else
      return false
    end
  end
end
if false then
  fh=STDIN
else
  fh=open("in0103.txt")
end
n= fh.gets.chomp.to_i
0.upto(n-1) { |i|
  point=0
  bb = BaseBall.new
  while fh.gets do
    s = $_.chomp
    if s=="HIT" then
      point += bb.hit
    elsif s=="HOMERUN" then
      point += bb.homerun
    elsif s=="OUT" then
      if bb.out then
        puts point
        break
      end
    end
  end
}