from copy import copy



def popcount(x):

    return bin(x).count("1")



def f(x):

    if x == 0:

        return 0

    return f(x%popcount(x))+1



n = int(eval(input()))

x = eval(input())

xx = int(x,2)

p = x.count("1")

stand1 = xx%(p+1)

if p != 1:

    stand2 = xx%(p-1)

for i in range(n):

    if x[i] == "1":

        if p != 1:

            k = copy(stand2)

            k -= pow(2,n-i-1,p-1) 

            k %= p-1

        else:

            print((0))

            continue

    else:

        k = copy(stand1)

        k += pow(2,n-i-1,p+1)

        k %= p+1

    print((1+f(k)))
def popcount(x):

    return bin(x).count("1")



def f(x):

    if x == 0:

        return 0

    return f(x%popcount(x))+1



n = int(eval(input()))

x = eval(input())

xx = int(x,2)

p = x.count("1")

stand1 = xx%(p+1)

if p != 1:

    stand2 = xx%(p-1)

for i in range(n):

    if x[i] == "1":

        if p != 1:

            k = stand2

            k -= pow(2,n-i-1,p-1) 

            k %= p-1

        else:

            print((0))

            continue

    else:

        k = stand1

        k += pow(2,n-i-1,p+1)

        k %= p+1

    print((1+f(k)))
from copy import copy


def popcount(x):
    return bin(x).count("1")


def f(x):
    if x == 0:
        return 0
    return f(x % popcount(x)) + 1


n = int(eval(input()))
x = eval(input())
xx = int(x, 2)
p = x.count("1")
stand1 = xx % (p + 1)
if p != 1:
    stand2 = xx % (p - 1)
for i in range(n):
    if x[i] == "1":
        if p != 1:
            k = copy(stand2)
            k -= pow(2, n - i - 1, p - 1)
            k %= p - 1
        else:
            print((0))
            continue
    else:
        k = copy(stand1)
        k += pow(2, n - i - 1, p + 1)
        k %= p + 1
    print((1 + f(k)))

def popcount(x):
    return bin(x).count("1")


def f(x):
    if x == 0:
        return 0
    return f(x % popcount(x)) + 1


n = int(eval(input()))
x = eval(input())
xx = int(x, 2)
p = x.count("1")
stand1 = xx % (p + 1)
if p != 1:
    stand2 = xx % (p - 1)
for i in range(n):
    if x[i] == "1":
        if p != 1:
            k = stand2
            k -= pow(2, n - i - 1, p - 1)
            k %= p - 1
        else:
            print((0))
            continue
    else:
        k = stand1
        k += pow(2, n - i - 1, p + 1)
        k %= p + 1
    print((1 + f(k)))

-from copy import copy - - -            k = copy(stand2) +            k = stand2 -        k = copy(stand1) +        k = stand1