gameCount = gets.chomp!.to_i
gameCount.times do |i|
    score = 0
    hitCnt = 0
    outCnt = 0
    while line = gets .chomp!
        case line
        when "OUT" then
            outCnt += 1
        when "HIT" then
            if hitCnt == 3 
                score += 1
            elsif   
                hitCnt += 1
            end
        when "HOMERUN" then
            score += (hitCnt + 1)
            hitCnt = 0
        end
        if outCnt == 3
            break
        end
    end
    puts score
end