y = {
  'r' => %w[q w e r t a s d f g z x c v b],
  'l' => %w[y u i o p h j k l n m]
}
while (n = gets.chomp) != '#'
  f, *s = n.split('')
  h = y['r'].include?(f) ? 'r' : 'l'
  c = 0
  s.each do |k|
    unless y[h].include?(k)
      h = h == 'r' ? 'l' : 'r'
      c += 1
    end
  end
  p c
end