#include<bits/stdc++.h>
#define ll                 long long int
#define mod                1000000007
#define pi                 3.14159265358979323846264338327950288419716939937510
#define setbit(x)          __builtin_popcountll(x)
#define db                 double
#define pp(x)              pair<x,x>
#define ff                 first
#define ss                 second
#define FIO                ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc                 ll tc; cin>>tc; for(ll number = 1 ; number <= tc ; number ++ )
#define vv(x)              vector<x>
#define pb                 push_back
#define pob                pop_back
#define pf                 push_front
#define pof                pop_front
#define endl               "\n"
#define pq                 priority_queue
#define dbg(x)             { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y)          { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define bp                 ll kkk; cin >>kkk;
#define dbgArr(a,n)        cout<<"Array "<<#a<<endl; for(ll i=0 ; i<n ; i++) cout<<a[i]<<" "; cout<<endl;
#define maxE(a,n)          *max_element(a,a+n);
#define minE(a,n)          *min_element(a,a+n);
#define forn(i,s,n)        for(ll i=s ; i<n ; i++)
#define fornr(i,e,s)       for(ll i=e-1 ; i>=s ; i--)
#define arr(a,n)           for(ll i=0;i<n;i++){ cin>>a[i]; }
#define arr1(a,n)          for(ll i=1;i<=n;i++){ cin>>a[i]; }
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define print cout<<"Case #"<<number<<": "
#define all(x) x.begin(), x.end()
ll power(ll x, ll b, ll m) {ll p = 1;while (b > 0) {if(b&1) {p = p * x; p %= m;} b >>= 1; x *= x; x %= m;} return p % m;}
using namespace std;
# define INF 1e15
struct lex_compare {
    bool operator() (const pair<db,ll>  p1, const pair<db,ll> p2){
        return (p1.first ==  p2.first) ? p1.ss < p2.ss : p1.first > p2.first;
    }
};
#define MAXN 1005


int main(){
    FIO;
    ll n; cin >> n;
    string s; cin >> s;
    ll bits = 0;
    forn(i,0,n){
        if(s[i] == '1') bits++;
    }

    reverse(s.begin(), s.end());
    ll rem[n][3];
    forn(i,0,n){
        if(bits > 0) rem[i][0] = (power(2,i,bits));
        else rem[i][0] = 0;
        rem[i][1] = (power(2,i,bits+1));
        if(bits > 1){
            rem[i][2] = power(2,i,bits-1);
        }else{
            rem[i][2] = 0;
        }
    }
    ll sum[3] = {0};;
    forn(i,0,n){
        if(s[i] == '0') continue;
        sum[0] += rem[i][0];
        sum[1] += rem[i][1];
        sum[2] += rem[i][2];
    }
    //dbgArr(sum,3);
    ll ans[n] = {0};
    for(ll i = 0;i<n;i++){
        ll currbits = bits;
        ll currsum = 0;
        if(s[i] == '0'){
            //dbg("YES");
            currbits++;
            currsum = sum[1];
            currsum += rem[i][1];
            currsum %= currbits;
        }else{
            //dbg("NO");
            currbits--;
            currsum = sum[2];
            currsum -= (rem[i][2]);
            currsum %= currbits;
        }
        if(currbits == 0){
            ans[i] = 0;
            continue;
        }
        //dbg2(currbits,currsum);
        ll anst = 1;
        while(currsum > 0){
            currbits = __builtin_popcountll(currsum);
            currsum %= currbits;
            anst++;
        }
        ans[i] = anst;

    }
    forn(i,0,n){
        cout << ans[n-i-1] << endl;
    }
    return 0;
}


Measured memory_bytes: 9960