r = /[qwertasdfgzxcvb]/;
loop {
    s = gets.chomp
    break if s == '#'
    count = 0
    right = (r === s[0])
    s.each_char{|c|
        count += 1 if right ^ (right = (r === c))
    }
    p count
}