from numba import njit



@njit('i8(i8)', cache=True)

def popcount(n):

    a = 0

    while n != 0:

        a += n & 1

        n >>= 1

    return a



@njit('i8(i8)', cache=True)

def fun(n):

    ops = 0

    while n:

        pc = popcount(n)

        n %= pc

        ops += 1

    return ops



n = int(eval(input()))

xs = list(map(int, eval(input())))



from functools import reduce

sm = reduce(lambda x,y: x*2+y, xs)

pc = xs.count(1)



# pcの差分を出した後の剰余計算を速くするため、事前にmod pc+1, mod pc-1を計算しておく

mp = sm % (pc + 1)

mm = sm % (pc - 1) if pc > 1 else 0



for i in range(n):

    df = 1 if xs[i] == 0 else -1

    pci = pc + df

    if pci == 0:

        print((0))

        continue



    rest = pow(2, n - i - 1, pci)



    if xs[i] == 0:

        smi = (mp + rest) % pci

        print((1 + fun(smi)))

    else:

        smi = (mm - rest) % pci

        print((1 + fun(smi)))



def fun(n):

    ops = 0

    while n:

        pc = format(n, 'b').count('1')

        n %= pc

        ops += 1

    return ops



n = int(eval(input()))

xs = eval(input())



sm = int(xs, 2)

pc = xs.count('1')



mp = sm % (pc + 1)

mm = sm % (pc - 1) if pc > 1 else 0



for i, x in enumerate(xs, 1):

    df = 1 if x == '0' else -1

    pci = pc + df

    if pci == 0:

        print((0))

        continue



    rest = pow(2, n - i, pci)



    if x == '0':

        smi = (mp + rest) % pci

        print((1 + fun(smi)))

    else:

        smi = (mm - rest) % pci

        print((1 + fun(smi)))

from numba import njit


@njit("i8(i8)", cache=True)
def popcount(n):
    a = 0
    while n != 0:
        a += n & 1
        n >>= 1
    return a


@njit("i8(i8)", cache=True)
def fun(n):
    ops = 0
    while n:
        pc = popcount(n)
        n %= pc
        ops += 1
    return ops


n = int(eval(input()))
xs = list(map(int, eval(input())))
from functools import reduce

sm = reduce(lambda x, y: x * 2 + y, xs)
pc = xs.count(1)
# pcの差分を出した後の剰余計算を速くするため、事前にmod pc+1, mod pc-1を計算しておく
mp = sm % (pc + 1)
mm = sm % (pc - 1) if pc > 1 else 0
for i in range(n):
    df = 1 if xs[i] == 0 else -1
    pci = pc + df
    if pci == 0:
        print((0))
        continue
    rest = pow(2, n - i - 1, pci)
    if xs[i] == 0:
        smi = (mp + rest) % pci
        print((1 + fun(smi)))
    else:
        smi = (mm - rest) % pci
        print((1 + fun(smi)))

def fun(n):
    ops = 0
    while n:
        pc = format(n, "b").count("1")
        n %= pc
        ops += 1
    return ops


n = int(eval(input()))
xs = eval(input())
sm = int(xs, 2)
pc = xs.count("1")
mp = sm % (pc + 1)
mm = sm % (pc - 1) if pc > 1 else 0
for i, x in enumerate(xs, 1):
    df = 1 if x == "0" else -1
    pci = pc + df
    if pci == 0:
        print((0))
        continue
    rest = pow(2, n - i, pci)
    if x == "0":
        smi = (mp + rest) % pci
        print((1 + fun(smi)))
    else:
        smi = (mm - rest) % pci
        print((1 + fun(smi)))

-from numba import njit - - -@njit("i8(i8)", cache=True) -def popcount(n): -    a = 0 -    while n != 0: -        a += n & 1 -        n >>= 1 -    return a - - -@njit("i8(i8)", cache=True) -        pc = popcount(n) +        pc = format(n, "b").count("1") -xs = list(map(int, eval(input()))) -from functools import reduce - -sm = reduce(lambda x, y: x * 2 + y, xs) -pc = xs.count(1) -# pcの差分を出した後の剰余計算を速くするため、事前にmod pc+1, mod pc-1を計算しておく +xs = eval(input()) +sm = int(xs, 2) +pc = xs.count("1") -for i in range(n): -    df = 1 if xs[i] == 0 else -1 +for i, x in enumerate(xs, 1): +    df = 1 if x == "0" else -1 -    rest = pow(2, n - i - 1, pci) -    if xs[i] == 0: +    rest = pow(2, n - i, pci) +    if x == "0":