n = gets.to_i
n.times do
    out = 0
    hit = 0
    score = 0
    until out == 3
        input = gets.chomp

        if input == "HIT"
            hit += 1
            if hit == 4
                hit = 3
                score += 1
            end 
        elsif input == "HOMERUN"
            score += hit + 1
            hit = 0
        elsif input == "OUT"
            out += 1
        end

    end
    puts score
end
