class Inning
  attr_accessor :score, :base, :out

  def initialize()
    @score, @out = 0, 0
    @base = [0, 0, 0]
  end

  def solve(str)
    case str
    when 'HIT'
      if i = @base.index(0)
        @base[i] = 1
      else
        @score += 1
      end
    when 'OUT'
      @out += 1
    when 'HOMERUN'
      @score += @base.inject(0) {|s, x| s + x} + 1
      @base.fill(0)
    end
  end
end

times = 0
num = gets.to_i

while times < num
  t = Inning.new()
  while t.out < 3
    str = gets.chomp!
    t.solve(str)
  end
  puts t.score
  times += 1
end