actions = []
while line = gets
  line.chomp!
  actions << line
end

inig = actions.shift.to_i

# puts inig
scores = []

score = 0
outs = 0
rui = 0
while inig > 0
  action = actions.first
  actions.shift
  if action == "HIT"
    rui += 1
  end
  if action == "HOMERUN"
    score += rui
    rui = 0
  end
  if rui > 3
    score += (rui -= 3)
  end

  if action == "OUT"
    outs += 1
  end
  if outs >= 3
    inig -= 1
    outs = 0
    scores << score
    score = 0
  end
  if actions.count <= 0
    scores << score
    break
  end

  # puts inig
end

scores.each {|s| puts "#{s}\n"}