out = 0
num = gets.chomp!.to_i
num.times do
  cnt = 0
  base1 = base2 = base3 = 0
  out = 0
  while out < 3
    act = gets.chomp!
    if act == "HIT"
      if base3 == 1
        cnt = cnt + 1
      end
      base3 = base2
      base2 = base1
      base1 = 1
    end
    if act == "OUT"
      out = out + 1
    end
    if act == "HOMERUN"
      cnt = cnt + base1 + base2 + base3 + 1
      base1 = base2 = base3 = 0
    end
  end
  printf("%d\n",cnt)
end