n = gets.to_i
n.times{
    score = 0 
    out_count = 0
    runners = [0, 0, 0]

    until out_count == 3
        event = gets.chomp
        case event
        when "HIT"
            score += 1 if runners[2] == 1
            runners[2] = runners[1]
            runners[1] = runners[0]
            runners[0] = 1
        when "HOMERUN"
            score += runners.count(1) + 1
            runners = [0, 0, 0]
        when "OUT"
            out_count += 1
        end
    end
    puts score
}