// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on

import core.bitop;

void main()
{
    long N = lread();
    auto X = sread();
    ulong m = X.map!"a == '1'"().sum();
    ulong plain0 = () {
        if (m == 1)
            return -1;
        long ret;
        foreach (i, c; X)
        {
            if (c == '1')
            {
                ret += powmod(2, X.length - i - 1, m - 1);
                ret %= m - 1;
            }
        }
        return ret;
    }();
    ulong plain1 = () {
        long ret;
        foreach (i, c; X)
        {
            if (c == '1')
            {
                ret += powmod(2, X.length - i - 1, m + 1);
                ret %= m + 1;
            }
        }
        return ret;
    }();
    foreach (i; 0 .. X.length)
    {
        if (X[i] == '1' && m == 1)
        {
            writeln(0);
            continue;
        }
        ulong y = () {
            if (X[i] == '1')
            {
                return ((m - 1) + plain0 - powmod(2, X.length - i - 1, m - 1)) % (m - 1);
            }
            return (plain1 + powmod(2, X.length - i - 1, m + 1)) % (m + 1);
        }();
        // dprint(i, X[i] == '1', y, plain0, plain1);
        long ans = 1;
        while (y != 0)
        {
            y = g(y);
            ans++;
        }
        writeln(ans);
    }
}

ulong g(ulong x)
{
    return x % popcnt(x);
}

/// x^^n % m
T powmod(T = long)(T x, T n, T m = 10 ^^ 9 + 7)
{
    if (n < 1)
        return 1;
    if (n & 1)
    {
        return x * powmod(x, n - 1, m) % m;
    }
    T tmp = powmod(x, n / 2, m);
    return tmp * tmp % m;
}
