n=gets.to_i
for i in 0.. n-1
  o=0
  r=[0,0,0]
  p=0
  while o<3
    case gets.chomp
    when "HIT"
      r.unshift(1)
      if r.pop==1
        p+=1
      end
    when "OUT"
      o+=1
    when "HOMERUN"
      r.unshift(1)
      for j in 0.. 3
        if r[j]==1
          p+=1
        end
      end
      r=[0,0,0]
    end
  end
  puts p
end