/*
 *      ┌─┐       ┌─┐ + +
 *   ┌──┘ ┴───────┘ ┴──┐++
 *   │                 │
 *   │       ───       │++ + + +
 *   ███████───███████ │+
 *   │                 │+
 *   │       ─┴─       │
 *   │                 │
 *   └───┐         ┌───┘
 *       │         │
 *       │         │   + +
 *       │         │       Code is far away from bug with the animal protecting
 *       │         └──────────────┐
 *       │                        │
 *       │                        ├─┐
 *       │                        ┌─┘
 *       │                        │
 *       └─┐  ┐  ┌───────┬──┐  ┌──┘  + + + +
 *         │ ─┤ ─┤       │ ─┤ ─┤
 *         └──┴──┘       └──┴──┘  + + + +
 *                神兽保佑
 *               代码无BUG!
 */

#include<bits/stdc++.h>
using namespace std;
class IN{
public:
    template<typename T>
    IN& operator >>(T &x){read(x);return *this;}
    IN& operator >>(double &x){scanf("%lf",&x);return *this;}
    IN& operator >>(char *s){scanf("%s",s);return *this;}
    IN& operator >>(char &c){c=getchar();return *this;}
private:
    template<typename T>
    void read(T &x){
        T f=1;int c=getchar();x=0;
        while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
        while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
        x*=f;
    }
}in;
class NL{}nl;
class BK{}bk;
class OUT{
public:
    template<typename T>
    OUT& operator <<(T x){write(x);return *this;}
    OUT& operator <<(const char *s){printf("%s",s);return *this;}
    OUT& operator <<(char c){putchar(c);return *this;}
    OUT& operator <<(BK x){putchar(' ');return *this;}
    OUT& operator <<(NL x){putchar('\n');return *this;}
private:
    template<typename T>
    void write(T x){
        if(x<0)putchar('-'),x=-x;
        if(x>=10)write(x/10);
        putchar(x%10+48);
    }
}out;

#define pb(x) push_back(x)
#define fi first
#define se second
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define mem(a,x) memset(a,x,sizeof(a))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;
/*****************************************************************************************************/
ll Pow(ll a,ll b,ll mod){ll res=1;a%=mod;while(b){if(b&1)(res*=a)%=mod;(a*=a)%=mod;b>>=1;}return res%mod;}
ll inv(ll a,ll p){if(a==1)return 1;return (p-p/a)*inv(p%a,p)%p;}//p为素数,a<p
ll C(ll n,ll m,ll p){ll res=1;for(ll i=1,j=n-m+1;i<=m;++i,++j){res=res*inv(i,p)%p*j%p;}return res;}
/*****************************************************************************************************/
/*ll ask(int x){ll res=0;while(x)res+=c[x],x-=x&-x;return res;}
void add(ll v,int x){while(x<=n)c[x]+=v,x+=x&-x;}*/
const int p=1e9+7;
const int N=2e5+10;

char a[N];
int n;
int b1[N],b2[N];
void f(int *p,int x){
    int y=1;
    rep(i,0,200000){
        p[i]=y%x;
        y*=2;
        y%=x;
    }
}
int ans[N];
int dfs(int x){
    if(ans[x]!=-1)return ans[x];
    int t=x%__builtin_popcount(x);
    return ans[x]=1+dfs(t);
}
int f2(int x){
    int res=a[1]-'0';
    rep(i,2,n){
        res*=2;
        if(a[i]=='1')++res;
        res%=x;
    }
    return res%=x;
}
int main(){
    in>>n;
    in>>(a+1);
    int cnt=0;
    rep(i,1,n)if(a[i]=='1')++cnt;
    f(b1,cnt+1);
    if(cnt-1>0)
        f(b2,cnt-1);//
    memset(ans,-1,sizeof(ans));
    ans[0]=0;
    //rep(i,0,200000)if(a[i]==-1)a[i]=dfs(i);

    int t1=f2(cnt+1);
    int t2;
    if(cnt-1>0)
        t2=f2(cnt-1);

    rep(i,1,n){
        if(a[i]=='0'){
            int tmp=(t1+b1[n-i])%(cnt+1);
            out<<1+dfs(tmp)<<nl;
        }else{
            if(cnt-1==0){
                out<<0<<nl;
            }else{
                int tmp=(t2-b2[n-i]+cnt-1)%(cnt-1);
                out<<1+dfs(tmp)<<nl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 6216