local r_shift = bit.rshift
local b_and = bit.band

local N = io.read("*n", "*l")
local X = io.read("*l")
local b_0 = string.byte("0")
local X_s = {}
local popcountX = 0
for i = 1, N do
	local byte = X:byte(i)
	if byte == b_0 then
		X_s[i] = 0
	else
		popcountX = popcountX + 1
		X_s[i] = 1
	end
end

local popcountXPlus1, popcountXMinus1 = popcountX + 1, popcountX - 1

local pow2ModPopcountXPlus1 = {}
pow2ModPopcountXPlus1[1] = 1
for i = 2, N do --ここ謎
	pow2ModPopcountXPlus1[i] = (pow2ModPopcountXPlus1[i-1] * 2) % popcountXPlus1
end
local pow2ModPopcountXMinus1 = {}
pow2ModPopcountXMinus1[1] = 1
if popcountXMinus1 > 0 then
	for i = 2, N do
		pow2ModPopcountXMinus1[i] = (pow2ModPopcountXMinus1[i-1] * 2) % popcountXMinus1
	end
end

local xModPopcountXPlus1 = 0
for digit = 1, N do
	local pos = N + 1 - digit
	if X_s[pos] == 1 then
		xModPopcountXPlus1 = xModPopcountXPlus1 + pow2ModPopcountXPlus1[digit]
		xModPopcountXPlus1 = xModPopcountXPlus1 % popcountXPlus1
	end
end
local xModPopcountXMinus1 = 0
if popcountXMinus1 > 0 then
	for digit = 1, N do
		local pos = N + 1 - digit
		if X_s[pos] == 1 then
			xModPopcountXMinus1 = xModPopcountXMinus1 + pow2ModPopcountXMinus1[digit]
			xModPopcountXMinus1 = xModPopcountXMinus1 + popcountXMinus1
		end
	end
end

local function popcount(num)
	local count = 0
	while num > 0 do
		if b_and(num, 1) == 1 then
			count = count + 1
		end
		num = r_shift(num, 1)
	end
	return count
end

local f = {}
local function getF(num)
	if num == 0 then
		return 0
	end
	if f[num] and f[num] > 0 then
		return f[num]
	end
	local ans = 1 + getF(num % popcount(num))
	f[num] = ans
	return ans
end

for pos = 1, N do
	local digit = N + 1 - pos

	local modXi = 0
	if X_s[pos] == 0 then
		modXi = xModPopcountXPlus1 + pow2ModPopcountXPlus1[digit]
		modXi = modXi % popcountXPlus1
		local ans = 1 + getF(modXi)
		print(ans)
	elseif popcountXMinus1 > 0 then
		modXi = xModPopcountXMinus1 + (popcountXMinus1 - pow2ModPopcountXMinus1[digit])
		modXi = modXi % popcountXMinus1
		local ans = 1 + getF(modXi)
		print(ans)
	else
		print(0)
	end
end
