n=gets.to_i
for i in 0...n do
  rui = [0,0,0,0]
  outc=0
  while true do
    break if outc==3
    str = gets.chop
    if str=="HIT" then
      rui[3]+=rui[2]
      rui[2]=rui[1]
      rui[1]=rui[0]
      rui[0]=1
    elsif str=="HOMERUN" then
      rui[3]+=rui[2]+rui[1]+rui[0]+1
      for i in 0..2 do
        rui[i]=0
      end
    else
      outc+=1
    end      
 #   print rui[3]," ",outc,"\n"
  end
  print(rui[3],"\n")
end