#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>
#include <bitset>
#include <sstream>
#include <cassert>
#include <time.h>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}
void printvec (vec &v) {
    Rep (i, (ll)v.size()) {
        cout << v[i] << " \n"[i+1 == (ll)v.size()];
    }
}

vec memo(2e5+10, -1);
ll f (ll n) {
    if (memo[n] != -1) return memo[n];
    if (n == 0) return memo[0] = 0;
    ll m = n;
    ll popcount = 0;
    while (m) {
        if (m%2 == 1) popcount++;
        m /= 2;
    }
    return memo[n] = 1 + f(n%popcount);
}

const int MOD = 1e9+7;
class mint {
    ll x;
public:
    mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
    
    mint operator -() const {
        return mint(-x);
    }
    
    mint &operator +=(const mint &a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }

    mint &operator -=(const mint &a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }

    mint &operator *=(const mint &a) {
        (x *= a.x) %= MOD;
        return *this;
    }

    mint operator +(const mint &a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint &a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator *(const mint &a) const {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(MOD - 2);
    }

    mint &operator /=(const mint &a) {
        return (*this) *= a.inv();
    }

    mint operator /(const mint &a) const {
        mint res(*this);
        return res /= a;
    }

    friend ostream &operator<<(ostream& os, const mint &m) {
        os << m.x;
        return os;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    string X;
    cin >> N >> X;

    ll pop = 0;
    ll num = 0;
    Rep (i, N) {
        if (X[i] == '1') pop++;
    }

    if (pop == 0) {
        Rep (i, N) {
            cout << 1 << "\n";
        }
        return 0;
    } else if (pop == 1) {
        Rep (i, N) {
            if (X[i] == '1') {
                cout << 0 << "\n";
            } else {
                if (X[N-1] == '1' or (X[N-1] == '0' and i == N-1)) {
                    cout << 2 << "\n";
                } else {
                    cout << 1 << "\n";
                }
            }
        }
        return 0;
    }

    ll numdec = 0, numinc = 0, tmpdec = 1, tmpinc = 1, popdec = pop-1, popinc = pop+1;
    vec ddec(N, 1), dinc(N, 1);

    Rep (i, N-1) {
        ddec[i] %= popdec;
        dinc[i] %= popinc;
        ddec[i+1] = (ddec[i] * 2) % popdec;
        dinc[i+1] = (dinc[i] * 2) % popinc;
    }
    
    Rep (i, N) {
        if (X[N-1-i] == '1') {
            numdec += ddec[i];
            numdec %= popdec;
            numinc += dinc[i];
            numinc %= popinc;
        }
    }

    Rep (i, N) {
        ll n;
        if (X[i] == '0') {
            n = numinc;
            n += dinc[N-1-i];
            n %= popinc;
            cout << 1+f(n%popinc) << "\n";
        } else {
            n = numdec;
            n -= ddec[N-1-i];
            n %= popdec;
            n += popdec;
            n %= popdec;
            cout << 1+f(n%popdec) << "\n";
        }
    }
}

Measured memory_bytes: 8336