n=int(eval(input()))

x=eval(input())

t=int(x,2)

c=x.count('1')

a=t%-~c

b=0 if c<2 else t%~-c

for i in range(n):

  if int(x[i]):

    if c<2: print((0)); continue

    else: t=(b-pow(2,n-i-1,c-1))%~-c

  else: t=(a+pow(2,n-i-1,c+1))%-~c

  z=1

  while t:

    d=bin(t).count('1')

    t%=d

    z+=1

  print(z)
n=int(eval(input()))

x=eval(input())

t=int(x,2)

c=x.count('1')

from functools import lru_cache

@lru_cache(None)

def f(x):

  if x==0: return 0

  return f(x%bin(x).count('1'))+1

a=t%-~c

b=0 if c<2 else t%~-c

for i in range(n):

  if int(x[i]):

    d=c-1

    if d<1: print((0))

    else: print((f((b-pow(2,n-i-1,d))%d)+1))

  else:

    d=c+1

    print((f((a+pow(2,n-i-1,d))%d)+1))
n = int(eval(input()))
x = eval(input())
t = int(x, 2)
c = x.count("1")
a = t % -~c
b = 0 if c < 2 else t % ~-c
for i in range(n):
    if int(x[i]):
        if c < 2:
            print((0))
            continue
        else:
            t = (b - pow(2, n - i - 1, c - 1)) % ~-c
    else:
        t = (a + pow(2, n - i - 1, c + 1)) % -~c
    z = 1
    while t:
        d = bin(t).count("1")
        t %= d
        z += 1
    print(z)

n = int(eval(input()))
x = eval(input())
t = int(x, 2)
c = x.count("1")
from functools import lru_cache


@lru_cache(None)
def f(x):
    if x == 0:
        return 0
    return f(x % bin(x).count("1")) + 1


a = t % -~c
b = 0 if c < 2 else t % ~-c
for i in range(n):
    if int(x[i]):
        d = c - 1
        if d < 1:
            print((0))
        else:
            print((f((b - pow(2, n - i - 1, d)) % d) + 1))
    else:
        d = c + 1
        print((f((a + pow(2, n - i - 1, d)) % d) + 1))

+from functools import lru_cache + + +@lru_cache(None) +def f(x): +    if x == 0: +        return 0 +    return f(x % bin(x).count("1")) + 1 + + -        if c < 2: +        d = c - 1 +        if d < 1: -            continue -            t = (b - pow(2, n - i - 1, c - 1)) % ~-c +            print((f((b - pow(2, n - i - 1, d)) % d) + 1)) -        t = (a + pow(2, n - i - 1, c + 1)) % -~c -    z = 1 -    while t: -        d = bin(t).count("1") -        t %= d -        z += 1 -    print(z) +        d = c + 1 +        print((f((a + pow(2, n - i - 1, d)) % d) + 1))