def modpow2(n, m)
  if n == 0
    1
  else
    if n % 2 == 1
      ((modpow2(n / 2, m) ** 2) * 2) % m
    else
      (modpow2(n / 2, m) ** 2) % m
    end
  end
end

n = gets.chomp.to_i
x = gets.chomp

count = x.count('1')

modpos = x.chars.map(&:to_i).inject(0) { |acc, i| (acc * 2 + i) % (count + 1) }
modneg = x.chars.map(&:to_i).inject(0) { |acc, i| (acc * 2 + i) % (count - 1) } if count > 1

(1..n).each do |i|
  if x[i - 1] == '1' && count == 1
    puts 0
  else    
    t = if x[i - 1] == '1'
        (modneg - modpow2(n - i, count - 1)) % (count - 1)
      else
        (modpos + modpow2(n - i, count + 1)) % (count + 1)
      end

    answer = 1
    while t > 0
      t = t % (t.to_s(2).count('1'))
      answer += 1
    end
    puts answer
  end
end

