#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<int, int, int> T;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
string x;

int bitcount(int bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int dp[200100];

int calc(int v) {
    if (v == 0) return 0;
    if (dp[v] < 0) {
        const int p = bitcount(v);
        dp[v] = calc(v%p) + 1;
    }
    return dp[v];
}

void solve() {
    memset(dp, -1, sizeof(dp));
    int sum = 0;
    for (char c : x) {
        if (c == '1')
            sum++;
    }
    if (sum == 0) {
        for (int i = 0; i < n; i++) {
            cout << 1 << endl;
        }
    } else if (sum == 1 && x[n-1] == '0') {
        for (int i = 0; i < n; i++) {
            if (x[i] == '1') {
                cout << 0 << endl;
            } else if (i < n-1) {
                cout << 1 << endl;
            } else {
                cout << 2 << endl;
            }
        }
    } else if (sum == 1) {
        for (int i = 0; i < n; i++) {
            if (i == n-1) {
                cout << 0 << endl;
            } else {
                cout << 2 << endl;
            }
        }
    } else {
        int mod_sum[2] = {0, 0};
        for (int i = 0; i < n; i++) {
            mod_sum[0] = (mod_sum[0]*2 + (int)(x[i]-'0')) % (sum+1);
            mod_sum[1] = (mod_sum[1]*2 + (int)(x[i]-'0')) % (sum-1);
        }
        int mod_pow2[2][n];
        memset(mod_pow2, 0, sizeof(mod_pow2));
        mod_pow2[0][0] = 1 % (sum+1);
        mod_pow2[1][0] = 1 % (sum-1);
        for (int i = 1; i < n; i++) {
            mod_pow2[0][i] = mod_pow2[0][i-1] * 2 % (sum+1);
            mod_pow2[1][i] = mod_pow2[1][i-1] * 2 % (sum-1);
        }

        for (int i = 0; i < n; i++) {
            if (x[i] == '0') {
                cout << calc((mod_sum[0] + mod_pow2[0][n-i-1]) % (sum+1)) + 1 << endl;
            } else {
                int t = mod_sum[1] - mod_pow2[1][n-i-1];
                t = (t + sum-1) % (sum-1);
                cout << calc(t) + 1 << endl;
            }
        }
    }
}

void input() {
    cin >> n >> x;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    solve();
}


Measured memory_bytes: 5600