#!/usr/bin/env python3
import sys


def solve(N: int, X: str):
    def pc(n):
        return bin(n).count("1")

    def f(i):
        if i == 0 : return 0
        p = 0
        k = i
        while(k!= 0):
            t = k
            p+=1
            k = t % pc(t)
        return p
    
    ts = [f(i) for i in range(1024)]
    # ts = {}
    # for i in range(2*10**5+1):
        # ts[i] = f(i)
    # for i in range(2*10**5+1):
        # ts[i] = f(i)



    x = int(X, 2)
    px = X.count("1")
    for i, xi in enumerate(X):
        if xi == "0":
            temp = (x + 2**(N-i-1))
            l = px+1
        else:
            temp = (x - 2**(N-i-1))
            l = px-1

        if temp == 0:
            print(0)
        else:
            temp_ = temp % l
            if temp_ == 0:
                print(1)
            else:
                temp = temp_ % bin(temp_).count("1")
                print(ts[temp]+2)  
    
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = next(tokens)  # type: str
    solve(N, X)

if __name__ == '__main__':
    main()
