# coding : UTF-8

n = gets.to_i

n.times do
   score = 0
   runner = 0
   out = 0
   loop do
      event = gets
      case event
         when /HIT/
            runner += 1
            if runner == 4
              runner = 3
              score += 1
            end
         when /HOMERUN/
            score += runner + 1
            runner = 0
         when /OUT/
            out += 1
      end
      break if out == 3
   end
   puts score
end