inning = $stdin.gets.to_i
Base = [0,1,3,7]

while inning > 0
  base = 0
  score = 0
  out = 0
  while out < 3
    event = $stdin.gets.chomp
    case event
    when "HIT"
      score += 1 if base == Base[3]
      base = (base << 1) + 1
      base = Base[3] if base > Base[3]
    when "HOMERUN"
      score += (Base.index(base) + 1)
      base = 0
    when "OUT"
      out += 1
    end
  end
  inning -= 1
  printf "%d\n", score
end