// By Mohit Gupta
#include <bits/stdc++.h>
using namespace std;
//DEBUG 
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define printint(v) copy(begin(v), end(v), ostream_iterator<int>(cout," "))
#define printintv(s,e) copy(s,e, ostream_iterator<int>(cout," "))
#define forstl(i,v) for(auto &i: v)
#define all(v) (v).begin(), (v).end()
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (for ints only diff for ll)
//https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for other in built
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define pb push_back
#define fi first
#define se second
#define int long long
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
#pragma GCC optimize ("-O2")
int LIM = 5e5+5, MOD = 998244353;
int t,n,m,k,x,y;

inline void add(int& x, int y)
{
	x += y;
	if (x >= MOD) x -= MOD;
}

inline void sub(int& x, int y)
{
	x -= y;
	if (x < 0) x += MOD;
}

inline int mult(int x, int y)
{
	return x * (long long) y % MOD;
}


ll modpow(int n,int p){
    if(p==0) return 1;
    if(p%2) return (modpow(n,p-1)*1LL*n)%MOD;
    else{
        ll half=modpow(n,p/2);
        return (half*1LL*half)%MOD;
    }
}

ll modinv(int d){
    return modpow(d,MOD-2);
} 


int solve(int val){
    if(val==0) return 0;
    
    int cnt=popc(val);
    return 1 + solve(val%cnt);
}

int32_t main()
{
    IOS;
    cin>>n;
    string str;
    cin>>str;

    int cnt[3];
    cnt[1]=0;
    forn(i,n) cnt[1]+=(str[i]=='1');

    cnt[0]=max(ll(0),cnt[1]-1);
    cnt[2]=cnt[1]+1;

    int pre[n][3],suff[n][3];
    forn(i,n){
        forn(j,3){
            if(cnt[j]==0) continue;
            MOD=cnt[j];
            if(i==0){
                pre[i][j]=0;
                if(str[i]=='1') pre[i][j]=modpow(2,n-i-1);
            }
            else{
                pre[i][j]=pre[i-1][j];
                if(str[i]=='1') pre[i][j]+=modpow(2,n-i-1);
                pre[i][j]%=MOD;
            }
        }
    }
    for(int i=n-1;i>=0;i--){
        forn(j,3){
            if(cnt[j]==0) continue;
            MOD=cnt[j];
            if(i==n-1){
                suff[i][j]=0;
                if(str[i]=='1') suff[i][j]=modpow(2,n-i-1);
            }
            else{
                suff[i][j]=suff[i+1][j];
                if(str[i]=='1') suff[i][j]+=modpow(2,n-i-1);
                suff[i][j]%=MOD;
            }
        }        
    }
    forn(i,n){
        if(str[i]=='1'){
            MOD=cnt[0];
            if(cnt[0]==0) cout<<0<<ln;
            else{
                int val=0;
                if(i>0) add(val,pre[i-1][0]);
                if(i<n-1) add(val,suff[i+1][0]);
                // val%=MOD;
                cout<<1+solve(val)<<ln;
            }
        }
        else{
            MOD=cnt[2];
            int val=0;
            if(i>0) add(val,pre[i-1][2]);
            if(i<n-1) add(val,suff[i+1][2]);
            add(val,modpow(2,n-i-1));
            // debug_out(val,cnt[2]);
            cout<<1+solve(val)<<ln;
        }
    }
}


Measured memory_bytes: 13112