map = ["qwertasdfgzxcvb".chars.to_a, "yuiophjklnm".chars.to_a]

loop do
  s = gets.chomp
  break if s=='#'

  k = s.chars.map{|x| map[0].include?(x) ? 1 : 2}.join
  puts k.scan(/12/).size + k.scan(/21/).size
end