def bitcount(N):  # 立ってるbitの数

    bitcnt = [0]

    for _ in range(N):

        bitcnt += [i + 1 for i in bitcnt]

    return bitcnt





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



num, cnt = int(x, 2), x.count('1')

lbit = bitcount(18)

for i in range(n):

    ans = 1

    if x[i] == '0':

        ctmp = cnt + 1

        tmp = num % ctmp + pow(2, n - (i + 1), ctmp)

    elif x[i] == '1':

        if cnt == 1:

            print((0))

            continue

        ctmp = cnt - 1

        tmp = num % ctmp - pow(2, n - (i + 1), ctmp)

    tmp %= ctmp

    ctmp = lbit[tmp]

    while tmp > 0:

        ans += 1

        tmp %= ctmp

        ctmp = lbit[tmp]

    print(ans)

def bitcount(N):  # 立ってるbitの数

    bitcnt = [0]

    for _ in range(N):

        bitcnt += [i + 1 for i in bitcnt]

    return bitcnt





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



num, cnt = int(x, 2), x.count('1')

num0, num1 = num % (cnt + 1), num % max(cnt - 1, 1)

lbit = bitcount(18)

for i in range(n):

    ans = 1

    if x[i] == '0':

        ctmp = cnt + 1

        tmp = num0 + pow(2, n - (i + 1), cnt + 1)

    elif x[i] == '1':

        if cnt == 1:

            print((0))

            continue

        ctmp = cnt - 1

        tmp = num1 - pow(2, n - (i + 1), cnt - 1)

    tmp %= ctmp

    ctmp = lbit[tmp]

    while tmp > 0:

        ans += 1

        tmp %= ctmp

        ctmp = lbit[tmp]

    print(ans)

def bitcount(N):  # 立ってるbitの数
    bitcnt = [0]
    for _ in range(N):
        bitcnt += [i + 1 for i in bitcnt]
    return bitcnt


n, x = int(eval(input())), eval(input())
num, cnt = int(x, 2), x.count("1")
lbit = bitcount(18)
for i in range(n):
    ans = 1
    if x[i] == "0":
        ctmp = cnt + 1
        tmp = num % ctmp + pow(2, n - (i + 1), ctmp)
    elif x[i] == "1":
        if cnt == 1:
            print((0))
            continue
        ctmp = cnt - 1
        tmp = num % ctmp - pow(2, n - (i + 1), ctmp)
    tmp %= ctmp
    ctmp = lbit[tmp]
    while tmp > 0:
        ans += 1
        tmp %= ctmp
        ctmp = lbit[tmp]
    print(ans)

def bitcount(N):  # 立ってるbitの数
    bitcnt = [0]
    for _ in range(N):
        bitcnt += [i + 1 for i in bitcnt]
    return bitcnt


n, x = int(eval(input())), eval(input())
num, cnt = int(x, 2), x.count("1")
num0, num1 = num % (cnt + 1), num % max(cnt - 1, 1)
lbit = bitcount(18)
for i in range(n):
    ans = 1
    if x[i] == "0":
        ctmp = cnt + 1
        tmp = num0 + pow(2, n - (i + 1), cnt + 1)
    elif x[i] == "1":
        if cnt == 1:
            print((0))
            continue
        ctmp = cnt - 1
        tmp = num1 - pow(2, n - (i + 1), cnt - 1)
    tmp %= ctmp
    ctmp = lbit[tmp]
    while tmp > 0:
        ans += 1
        tmp %= ctmp
        ctmp = lbit[tmp]
    print(ans)

+num0, num1 = num % (cnt + 1), num % max(cnt - 1, 1) -        tmp = num % ctmp + pow(2, n - (i + 1), ctmp) +        tmp = num0 + pow(2, n - (i + 1), cnt + 1) -        tmp = num % ctmp - pow(2, n - (i + 1), ctmp) +        tmp = num1 - pow(2, n - (i + 1), cnt - 1)