N=int(eval(input()))

X=eval(input())



def pop(x): #10進数

    ret=0

    while x>0:

        ret+=x%2

        x//=2

    return ret



def solve(x): #10進数

    ret=0

    while x>0:

        pop_c=pop(x)

        x%=pop_c

        ret+=1

    return ret



mod=X.count("1") #>0

original_plus=0

original_minus=0

for i in range(N):

    if X[N-1-i]=="1":

        if mod>1:

            original_minus+=pow(2,i,mod-1)

        original_plus+=pow(2,i,mod+1)

for i in range(N):

    if X[i]=="0":

        tmp=original_plus+pow(2,N-1-i,mod+1)

        tmp%=mod+1

        print((solve(tmp)+1))

    else:

        if mod==1:

            print((0))

            continue

        tmp=original_minus-pow(2,N-1-i,mod-1)

        tmp%=mod-1

        print((solve(tmp)+1))

N=int(eval(input()))

X=eval(input())



def solve(x): #10進数

    ret=0

    while x>0:

        pop=bin(x).count("1")

        x%=pop

        ret+=1

    return ret



mod=X.count("1") #>0

original_plus=0

original_minus=0

for i in range(N):

    if X[N-1-i]=="1":

        if mod>1:

            original_minus+=pow(2,i,mod-1)

        original_plus+=pow(2,i,mod+1)

for i in range(N):

    if X[i]=="0":

        tmp=original_plus+pow(2,N-1-i,mod+1)

        tmp%=mod+1

        print((solve(tmp)+1))

    else:

        if mod==1:

            print((0))

            continue

        tmp=original_minus-pow(2,N-1-i,mod-1)

        tmp%=mod-1

        print((solve(tmp)+1))

N = int(eval(input()))
X = eval(input())


def pop(x):  # 10進数
    ret = 0
    while x > 0:
        ret += x % 2
        x //= 2
    return ret


def solve(x):  # 10進数
    ret = 0
    while x > 0:
        pop_c = pop(x)
        x %= pop_c
        ret += 1
    return ret


mod = X.count("1")  # >0
original_plus = 0
original_minus = 0
for i in range(N):
    if X[N - 1 - i] == "1":
        if mod > 1:
            original_minus += pow(2, i, mod - 1)
        original_plus += pow(2, i, mod + 1)
for i in range(N):
    if X[i] == "0":
        tmp = original_plus + pow(2, N - 1 - i, mod + 1)
        tmp %= mod + 1
        print((solve(tmp) + 1))
    else:
        if mod == 1:
            print((0))
            continue
        tmp = original_minus - pow(2, N - 1 - i, mod - 1)
        tmp %= mod - 1
        print((solve(tmp) + 1))

N = int(eval(input()))
X = eval(input())


def solve(x):  # 10進数
    ret = 0
    while x > 0:
        pop = bin(x).count("1")
        x %= pop
        ret += 1
    return ret


mod = X.count("1")  # >0
original_plus = 0
original_minus = 0
for i in range(N):
    if X[N - 1 - i] == "1":
        if mod > 1:
            original_minus += pow(2, i, mod - 1)
        original_plus += pow(2, i, mod + 1)
for i in range(N):
    if X[i] == "0":
        tmp = original_plus + pow(2, N - 1 - i, mod + 1)
        tmp %= mod + 1
        print((solve(tmp) + 1))
    else:
        if mod == 1:
            print((0))
            continue
        tmp = original_minus - pow(2, N - 1 - i, mod - 1)
        tmp %= mod - 1
        print((solve(tmp) + 1))

- - -def pop(x):  # 10進数 -    ret = 0 -    while x > 0: -        ret += x % 2 -        x //= 2 -    return ret -        pop_c = pop(x) -        x %= pop_c +        pop = bin(x).count("1") +        x %= pop