n = gets.to_i
x = gets.chomp
M = Hash.new
M[0] = 0
def f(n)
  if M.has_key?(n)
    M[n]
  else
    M[n] = f(n % n.to_s(2).count('1')) + 1
  end
end
n.times do |i|
  x[i] = x[i] == '1' ? '0' : '1'
  puts f(x.to_i(2))
  x[i] = x[i] == '1' ? '0' : '1'
end
