num = gets.chomp.to_i
out_time = 0
array = []
score = 0
while true
    str = gets.chomp
    break if str.nil?
    case str
    when "HIT"
    array << 1
    if array.length >= 4
        array.delete_at(array.length - 1)
        score += 1
    end
    when "HOMERUN"
    score += array.length + 1
    array = []
    when "OUT"
    out_time += 1
    else
    end
    if out_time == 3
        puts score.to_s
        out_time = 0
        num -= 1
        if num == 0
            break
        end
    end
end