Buggy python submission (verdict: Time Limit Exceeded):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	if len(x) == 0:
		return []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
	ll = 0
	rr = r
	while True:
		mid = (ll+rr)//2

	if rr == mid:
		return ll
	if (ここに評価入れる):
		rr = mid
	else:
		ll = mid+1
"""

n = onem()

po = input()[:-1]
num = int("0B" + po,0)
co = po.count("1")
for i in range(n):
	if po[i] == "0":
		ima = num + 2**(n-1-i)
		coco = co + 1
		count = 0
		while True:
			if ima == 0:
				break
			else:
				ima %= coco
				count += 1
				coco = format(ima,"b").count("1")
	else:
		ima = num - 2**(n-1-i)
		coco = co - 1
		count = 0
		while True:
			if ima == 0:
				break
			else:
				ima %= coco
				count += 1
				coco = format(ima,"b").count("1")
	print(count)







Fixed submission:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	if len(x) == 0:
		return []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
	ll = 0
	rr = r
	while True:
		mid = (ll+rr)//2

	if rr == mid:
		return ll
	if (ここに評価入れる):
		rr = mid
	else:
		ll = mid+1
"""





n = onem()

po = input()
#num = int("0B" + po,0)
co = po.count("1")

num = [0,0]

for i in range(n):
	num[0] *= 2
	num[1] *= 2
	if po[i] == "1":
		num[0] += 1
		num[1] += 1
	if co > 1:
			num[0] %= co-1
	num[1] %= co+1
	

for i in range(n):
	if po[i] == "0":
		coco = co + 1

		ima = num[1] + pow(2,(n-1-i),coco)
		ima %= coco
		coco = format(ima,"b").count("1")
		count = 1
		while True:
			if ima == 0:
				break
			else:
				ima %= coco
				count += 1
				"""
				if ima >= 10**5 + 1:
					coco = dp[ima-(10**5 + 1)]
				else:
				"""
				coco = format(ima,"b").count("1")

	else:
		coco = co - 1
		if coco == 0:
			count = 0
			print(count)
			continue
		ima = num[0] - pow(2,(n-1-i),coco)
		ima %= coco
		count = 1
		coco = format(ima,"b").count("1")
		while True:
			if ima == 0:
				break
			else:
				ima %= coco
				count += 1
				"""
				if ima >= 10**5 + 1:
					coco = dp[ima-(10**5 + 1)]
				else:
				"""
				coco = format(ima,"b").count("1")
	print(count)