aryL = %w|q w e r t a s d f g z x c v b|
aryR = %w|y u i o p h j k l n m|

loop do
  str = gets.chomp.chars
  if str == ["#"]
    exit
  else
    if aryL.include?(str[0])
      now = :left
    else
      now = :right
    end
    
    cnt = 0
    str.each do |c|
      if now == :left && aryR.include?(c)
        cnt += 1
        now = :right
      elsif now == :right && aryL.include?(c)
        cnt += 1
        now = :left
      end
    end

    puts cnt
  end
end

