io = DATA.eof? ? STDIN : DATA
n=io.gets.to_i
xs=io.gets.chomp
x=xs.to_i(2)
def popcount(x)
  b = 0
  while x > 0
    x &= x - 1
    b += 1
  end
  b
end
def f(n)
  cnt=1
  while (n>0)
    n=n%popcount(n)
    cnt+=1
  end
  cnt
end
pcx=popcount(x)
pc0,pc1= pcx+1,pcx-1
xmod0=x%pc0
xmod1=x%pc1 if pc1>0
n.times do |i|
  if (xs[i])=="0"
    pci,xmodi,powi = [pc0,xmod0,(2.pow(n-1-i,pc0))]
  elsif pc1>0
    pci,xmodi,powi = [pc1,xmod1,-(2.pow(n-1-i,pc1))]
  else
    pci=pc1
  end
  if pci==0
    puts 0
  else
    pc=(xmodi+powi)%pci
    puts f(pc)
  end
end
__END__
