N = gets.to_i
X = gets.chomp

@m = {0 => 0, 1 => 1}
f = ->(n){@m[n] ||= f[n % n.to_s(2).count('1')] + 1}
c = X.count('1')
c0, c1 = c + 1, c - 1
cf = c1 > 0
xd = X.to_i(2)
x0, x1 = xd % c0, cf ? xd % c1 : nil
(N - 1).downto(0).each do |i|
  if xd[i] == 0
    puts f[(x0 + 2.pow(i, c0))%c0] + 1
  else
    puts cf ? f[(x1 - 2.pow(i, c1))%c1] + 1 : 0
  end
end