n = int(eval(input()))

x = int(eval(input()),2)

# b = int(2**(n-1))

pc = 0

d = []

c = x

for i in range(n):

    d.append(c&1)

    if c&1 == 1:

        pc += 1

    c=c>>1



mp =  x%(pc+1)

if pc == 1:

    mm = -1

else:

    mm = x%(pc-1)

# print(x,pc,mp,mm)

for i in range(n):

    if d[-i-1]==0:

        m = 1

        temp = (mp+pow(2,n-i-1,pc+1)) % (pc+1)

        ans = 1

    else:

        if mm == -1:

            temp = 0

            ans = 0

        else:    

            m = -1

            temp = (mm-pow(2,n-i-1,pc-1)) % (pc-1)

            ans = 1

    # temppc = pc+m

    # temp = x^b

    # ans = 1

    # print(temp)

    # print(temp,mm,pc,pow(2,n-i,pc+1),(mm-pow(2,n-i-1,pc+1)) % (pc-1))

    while temp:

        

        c = temp

        temppc = 0

        while c:

            if c&1 == 1:

                temppc += 1

            c=c>>1

        # print(temp)

        # print(i,temp,ans,temppc)

        # print(temp)

        # s = str(bin(temp))

        # print(temp,popcount(temp))

        if temppc == 0:

            break

        temp = temp % temppc

        ans += 1

        # c = temp

        # temppc = 0

        # while c:

        #     if c&1 == 1:

        #         temppc += 1

        #     c=c>>1

        # print(temp,s)

        # break

    # b=b>>1

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

x = int(eval(input()),2)

pc = 0

d = []

c = x

for i in range(n):

    d.append(c&1)

    if c&1 == 1:

        pc += 1

    c=c>>1

mp = x%(pc+1)

if pc == 1:

    mm = -1

else:

    mm = x%(pc-1)

for i in range(n):

    if d[-i-1]==0:

        temp = (mp+pow(2,n-i-1,pc+1)) % (pc+1)

        ans = 1

    else:

        if mm == -1:

            temp = 0

            ans = 0

        else:    

            temp = (mm-pow(2,n-i-1,pc-1)) % (pc-1)

            ans = 1

    while temp:

        c = temp

        temppc = 0

        while c:

            if c&1 == 1:

                temppc += 1

            c=c>>1

        if temppc == 0:

            break

        temp = temp % temppc

        ans += 1

    print(ans)
n = int(eval(input()))
x = int(eval(input()), 2)
# b = int(2**(n-1))
pc = 0
d = []
c = x
for i in range(n):
    d.append(c & 1)
    if c & 1 == 1:
        pc += 1
    c = c >> 1
mp = x % (pc + 1)
if pc == 1:
    mm = -1
else:
    mm = x % (pc - 1)
# print(x,pc,mp,mm)
for i in range(n):
    if d[-i - 1] == 0:
        m = 1
        temp = (mp + pow(2, n - i - 1, pc + 1)) % (pc + 1)
        ans = 1
    else:
        if mm == -1:
            temp = 0
            ans = 0
        else:
            m = -1
            temp = (mm - pow(2, n - i - 1, pc - 1)) % (pc - 1)
            ans = 1
    # temppc = pc+m
    # temp = x^b
    # ans = 1
    # print(temp)
    # print(temp,mm,pc,pow(2,n-i,pc+1),(mm-pow(2,n-i-1,pc+1)) % (pc-1))
    while temp:
        c = temp
        temppc = 0
        while c:
            if c & 1 == 1:
                temppc += 1
            c = c >> 1
        # print(temp)
        # print(i,temp,ans,temppc)
        # print(temp)
        # s = str(bin(temp))
        # print(temp,popcount(temp))
        if temppc == 0:
            break
        temp = temp % temppc
        ans += 1
        # c = temp
        # temppc = 0
        # while c:
        #     if c&1 == 1:
        #         temppc += 1
        #     c=c>>1
        # print(temp,s)
        # break
    # b=b>>1
    print(ans)

n = int(eval(input()))
x = int(eval(input()), 2)
pc = 0
d = []
c = x
for i in range(n):
    d.append(c & 1)
    if c & 1 == 1:
        pc += 1
    c = c >> 1
mp = x % (pc + 1)
if pc == 1:
    mm = -1
else:
    mm = x % (pc - 1)
for i in range(n):
    if d[-i - 1] == 0:
        temp = (mp + pow(2, n - i - 1, pc + 1)) % (pc + 1)
        ans = 1
    else:
        if mm == -1:
            temp = 0
            ans = 0
        else:
            temp = (mm - pow(2, n - i - 1, pc - 1)) % (pc - 1)
            ans = 1
    while temp:
        c = temp
        temppc = 0
        while c:
            if c & 1 == 1:
                temppc += 1
            c = c >> 1
        if temppc == 0:
            break
        temp = temp % temppc
        ans += 1
    print(ans)

-# b = int(2**(n-1)) -# print(x,pc,mp,mm) -        m = 1 -            m = -1 -    # temppc = pc+m -    # temp = x^b -    # ans = 1 -    # print(temp) -    # print(temp,mm,pc,pow(2,n-i,pc+1),(mm-pow(2,n-i-1,pc+1)) % (pc-1)) -        # print(temp) -        # print(i,temp,ans,temppc) -        # print(temp) -        # s = str(bin(temp)) -        # print(temp,popcount(temp)) -        # c = temp -        # temppc = 0 -        # while c: -        #     if c&1 == 1: -        #         temppc += 1 -        #     c=c>>1 -        # print(temp,s) -        # break -    # b=b>>1