#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
// 293206GT
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <unordered_set>
#include <stack>
#include <string>
#include<algorithm>
#include <random>
#include <bitset>
#include <chrono>

typedef long long ll;
#define int ll
using namespace std;
#define put(a) cout << (a) << '\n'
#define sqr(x) (x) * (x)
typedef pair<int, int> pii;
typedef long double ld;
typedef pair<ld, ld> pld;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<pii> vpii;
#define rep(x, y, a) for (int x = (y); x < (int)(a); ++x)
#define all(a) a.begin(), a.end()
#define chkmax(a, b) a = max(a, (b))
#define chkmin(a, b) a = min(a, (b))
#define prev asasdasd
#define next aasdasda
#define left asdasdasdasd
#define right asnabsdkasdl
#define rank asdasdknlasd
#define move asdasdas

namespace IO {
    template<class A, class B>
    ostream &operator<<(ostream &out, pair<A, B> a) {
        out << a.first << " " << a.second;
        return out;
    }

    template<class A, class B>
    ostream &operator<<(ostream &out, vector<pair<A, B>> a) {
        for (pair<A, B> x: a)
            out << x.first << " " << x.second << '\n';
        return out;
    }

    template<class A>
    ostream &operator<<(ostream &out, vector<A> a) {
        for (A x: a) out << x << ' ';
        return out;
    }

    template<class A, class B>
    istream &operator>>(istream &in, pair<A, B> &a) {
        in >> a.first >> a.second;
        return in;
    }

    template<class A>
    istream &operator>>(istream &in, vector<A> &a) {
        for (A &x: a) in >> x;
        return in;
    }
}
using namespace IO;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int bp(int a, int b, int m) {
    if (b == 0) return 1;
    int x = bp(a, b / 2, m);
    x = x * x % m;
    x *= max(1ll, (b % 2) * a);
    return x % m;
}
int divi(string s, int x) {
    int cur = 0;
    int p = 0;
    int n = s.size();
    while (p < n) {
        while (p < n && cur < x) {
            cur *= 2;
            cur += (s[p] == '1');
            ++p;
        }
        cur %= x;
    }
    return cur;
}
void solve() {
    int n;
    cin >> n;
    string x;
    cin >> x;
    vi prec(n + 3, 0);
    rep(i,1,n + 3) prec[i] = prec[i%__builtin_popcount(i)] + 1;
    int cnt = count(all(x), '1');
    int mod_1 = (cnt < 2?-1:divi(x, cnt - 1));
    if (cnt == 1) mod_1 = 0;
    int mod_2 = (cnt == n?-1:divi(x, cnt + 1));
    rep(i, 0, n) {
        if (x[i] == '1') {
            if (cnt == 1) {
                put(0);
                continue;
            }
            int cur = (mod_1 - bp(2, (n - i - 1), cnt - 1)) % (cnt - 1);
            if (cur < 0) cur += cnt - 1;
            put(prec[cur] + 1);
        } else {
            int cur = (mod_2 + bp(2, (n - i - 1), cnt + 1)) % (cnt + 1);
            put(prec[cur] + 1);
        }
    }
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(30);
//    freopen("input.txt", "r", stdin);
    int q = 1;
//    cin >> q;

    while (q--) solve();
}


Measured memory_bytes: 4848