N = int(eval(input()))

X = eval(input())



cnt = X.count("1")

res0 = 0

res1 = 0

for i in range(N):

    if X[i] == "1":

        res0 = (res0 + pow(2, N - i - 1, cnt + 1)) % (cnt + 1)



        if cnt - 1 > 0:

            res1 = (res1 + pow(2, N - i - 1, cnt - 1)) % (cnt - 1)



for i in range(N):

    ans = 0

    if X[i] == "0":

        div = cnt + 1

        tmp = (res0 + pow(2, N - i - 1, div)) % div

        ans += 1

    else:

        if cnt - 1 > 0:

            div = cnt - 1

            tmp = (res1 + div - pow(2, N - i - 1, div)) % div

            ans += 1

        else:

            tmp = 0



    while tmp > 0:

        ans += 1

        div = bin(tmp).count("1")

        tmp %= div

        

    print(ans)



N = int(input())

X = input()



mod0 = X.count("1") + 1

mod1 = X.count("1") - 1



full0 = 0

full1 = 0

for i in range(N):

    if X[i] == "1":

        full0 = (full0 + pow(2, N - i - 1, mod0)) % mod0

        if mod1 > 0:

            full1 = (full1 + pow(2, N - i - 1, mod1)) % mod1



ans = [0] * N

for i in range(N):

    if X[i] == "0":

        cur = (full0 + pow(2, N - i - 1, mod0)) % mod0

        res = 1

    else:

        if mod1 > 0:

            cur = (full1 - pow(2, N - i - 1, mod1)) % mod1

            res = 1

        else:

            cur = 0

            res = 0



    while cur > 0:

        cur %= bin(cur).count("1")

        res += 1

    ans[i] = res



print(*ans, sep="\n")

N = int(eval(input()))
X = eval(input())
cnt = X.count("1")
res0 = 0
res1 = 0
for i in range(N):
    if X[i] == "1":
        res0 = (res0 + pow(2, N - i - 1, cnt + 1)) % (cnt + 1)
        if cnt - 1 > 0:
            res1 = (res1 + pow(2, N - i - 1, cnt - 1)) % (cnt - 1)
for i in range(N):
    ans = 0
    if X[i] == "0":
        div = cnt + 1
        tmp = (res0 + pow(2, N - i - 1, div)) % div
        ans += 1
    else:
        if cnt - 1 > 0:
            div = cnt - 1
            tmp = (res1 + div - pow(2, N - i - 1, div)) % div
            ans += 1
        else:
            tmp = 0
    while tmp > 0:
        ans += 1
        div = bin(tmp).count("1")
        tmp %= div
    print(ans)

N = int(input())
X = input()
mod0 = X.count("1") + 1
mod1 = X.count("1") - 1
full0 = 0
full1 = 0
for i in range(N):
    if X[i] == "1":
        full0 = (full0 + pow(2, N - i - 1, mod0)) % mod0
        if mod1 > 0:
            full1 = (full1 + pow(2, N - i - 1, mod1)) % mod1
ans = [0] * N
for i in range(N):
    if X[i] == "0":
        cur = (full0 + pow(2, N - i - 1, mod0)) % mod0
        res = 1
    else:
        if mod1 > 0:
            cur = (full1 - pow(2, N - i - 1, mod1)) % mod1
            res = 1
        else:
            cur = 0
            res = 0
    while cur > 0:
        cur %= bin(cur).count("1")
        res += 1
    ans[i] = res
print(*ans, sep="\n")

-N = int(eval(input())) -X = eval(input()) -cnt = X.count("1") -res0 = 0 -res1 = 0 +N = int(input()) +X = input() +mod0 = X.count("1") + 1 +mod1 = X.count("1") - 1 +full0 = 0 +full1 = 0 -        res0 = (res0 + pow(2, N - i - 1, cnt + 1)) % (cnt + 1) -        if cnt - 1 > 0: -            res1 = (res1 + pow(2, N - i - 1, cnt - 1)) % (cnt - 1) +        full0 = (full0 + pow(2, N - i - 1, mod0)) % mod0 +        if mod1 > 0: +            full1 = (full1 + pow(2, N - i - 1, mod1)) % mod1 +ans = [0] * N -    ans = 0 -        div = cnt + 1 -        tmp = (res0 + pow(2, N - i - 1, div)) % div -        ans += 1 +        cur = (full0 + pow(2, N - i - 1, mod0)) % mod0 +        res = 1 -        if cnt - 1 > 0: -            div = cnt - 1 -            tmp = (res1 + div - pow(2, N - i - 1, div)) % div -            ans += 1 +        if mod1 > 0: +            cur = (full1 - pow(2, N - i - 1, mod1)) % mod1 +            res = 1 -            tmp = 0 -    while tmp > 0: -        ans += 1 -        div = bin(tmp).count("1") -        tmp %= div -    print(ans) +            cur = 0 +            res = 0 +    while cur > 0: +        cur %= bin(cur).count("1") +        res += 1 +    ans[i] = res +print(*ans, sep="\n")