def popcount(x):

    return bin(x)[2:].count("1")



def f(x):

    cnt=0

    while(x>0):

        x%=popcount(x)

        cnt+=1

    return cnt



n=int(eval(input()))

s=eval(input())

d=s.count("1")

if d==0:

    for i in range(n):

        print((1))

elif d==1:

    if s[-1]=="1":

        for i in range(n-1):

            print((2))

        else:

            print((0))

    else:

        for i in range(n-1):

            if s[i]=="1":

                print((0))

            else:

                print((1))

        print((2))

else:

    s=s[::-1]

    toaddm=1

    toaddM=1

    m=0

    M=0

    for i in range(n):

        if s[i]=="1":

            m+=toaddm

            M+=toaddM

            m%=d-1

            M%=d+1

        toaddm*=2

        toaddm%=d-1

        toaddM*=2

        toaddM%=d+1

    toaddm=-1

    toaddM=1

    res=[None for i in range(n)]

    for i in range(n):

        if s[i]=="1":

            res[i]=f((m+toaddm)%(d-1))+1

        else:

            res[i]=f((M+toaddM)%(d+1))+1

        toaddm*=2

        toaddm%=d-1

        toaddM*=2

        toaddM%=d+1

    for i in res[::-1]:

        print(i)

def popcount(x):

    return bin(x)[2:].count("1")



def f(x):

    cnt=0

    while(x>0):

        x%=popcount(x)

        cnt+=1

    return cnt



n=int(eval(input()))

s=eval(input())

d=s.count("1")

if d==0:

    for i in range(n):

        print((1))

elif d==1:

    if s[-1]=="1":

        for i in range(n-1):

            print((2))

        else:

            print((0))

    else:

        for i in range(n-1):

            if s[i]=="1":

                print((0))

            else:

                print((1))

        print((2))

else:

    ints=int(s,2)

    m=ints%(d-1)

    M=ints%(d+1)

    s=s[::-1]

    toaddm=-1

    toaddM=1

    res=[None for i in range(n)]

    for i in range(n):

        if s[i]=="1":

            res[i]=f((m+toaddm)%(d-1))+1

        else:

            res[i]=f((M+toaddM)%(d+1))+1

        toaddm*=2

        toaddm%=d-1

        toaddM*=2

        toaddM%=d+1

    for i in res[::-1]:

        print(i)

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


def f(x):
    cnt = 0
    while x > 0:
        x %= popcount(x)
        cnt += 1
    return cnt


n = int(eval(input()))
s = eval(input())
d = s.count("1")
if d == 0:
    for i in range(n):
        print((1))
elif d == 1:
    if s[-1] == "1":
        for i in range(n - 1):
            print((2))
        else:
            print((0))
    else:
        for i in range(n - 1):
            if s[i] == "1":
                print((0))
            else:
                print((1))
        print((2))
else:
    s = s[::-1]
    toaddm = 1
    toaddM = 1
    m = 0
    M = 0
    for i in range(n):
        if s[i] == "1":
            m += toaddm
            M += toaddM
            m %= d - 1
            M %= d + 1
        toaddm *= 2
        toaddm %= d - 1
        toaddM *= 2
        toaddM %= d + 1
    toaddm = -1
    toaddM = 1
    res = [None for i in range(n)]
    for i in range(n):
        if s[i] == "1":
            res[i] = f((m + toaddm) % (d - 1)) + 1
        else:
            res[i] = f((M + toaddM) % (d + 1)) + 1
        toaddm *= 2
        toaddm %= d - 1
        toaddM *= 2
        toaddM %= d + 1
    for i in res[::-1]:
        print(i)

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


def f(x):
    cnt = 0
    while x > 0:
        x %= popcount(x)
        cnt += 1
    return cnt


n = int(eval(input()))
s = eval(input())
d = s.count("1")
if d == 0:
    for i in range(n):
        print((1))
elif d == 1:
    if s[-1] == "1":
        for i in range(n - 1):
            print((2))
        else:
            print((0))
    else:
        for i in range(n - 1):
            if s[i] == "1":
                print((0))
            else:
                print((1))
        print((2))
else:
    ints = int(s, 2)
    m = ints % (d - 1)
    M = ints % (d + 1)
    s = s[::-1]
    toaddm = -1
    toaddM = 1
    res = [None for i in range(n)]
    for i in range(n):
        if s[i] == "1":
            res[i] = f((m + toaddm) % (d - 1)) + 1
        else:
            res[i] = f((M + toaddM) % (d + 1)) + 1
        toaddm *= 2
        toaddm %= d - 1
        toaddM *= 2
        toaddM %= d + 1
    for i in res[::-1]:
        print(i)

+    ints = int(s, 2) +    m = ints % (d - 1) +    M = ints % (d + 1) -    toaddm = 1 -    toaddM = 1 -    m = 0 -    M = 0 -    for i in range(n): -        if s[i] == "1": -            m += toaddm -            M += toaddM -            m %= d - 1 -            M %= d + 1 -        toaddm *= 2 -        toaddm %= d - 1 -        toaddM *= 2 -        toaddM %= d + 1