gets.to_i.times do
  s, o, r = 0, 0, [0] * 3
  
  while o < 3
    case gets.chomp
    
    when "HIT"
      s += 1 if r[2] == 1
      r.rotate!(-1)[0] = 1
        
    when "HOMERUN"
      s += r.count(1) + 1
      r = [0] * 3
    
    when "OUT"
      o += 1
    end
  end
  
  puts s
end