left = "qwertasdfgzxcvb"
while true
    str = gets.chomp
    break if str == "#"
    hand = left.include?(str[0])
    prev = hand
    count = 0
    str[1..-1].each_char{|c|
        hand = left.include?(c)
        if prev != hand
            count += 1
            prev = hand
        end
    }
    puts count
end
