require 'scanf'

n = STDIN.gets.to_i

for i in 0..n-1 do
    out,score = 0,0
    f=[0,0,0]
    while out < 3 
        str = STDIN.gets
        if str == "HOMERUN\n" then
            score = score+f[0]+f[1]+f[2]+1
            f=[0,0,0]
        elsif str == "HIT\n" then
            score = score+f[2]
            f[2] = f[1]
            f[1] = f[0]
            f[0] = 1
        elsif str == "OUT\n" then
            out = out+1
        end
    end
    print score, "\n"
end