#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL n,pwm1[200020],pw[200020],pwp1[200020],num=0,resm1=0,res=0,resp1=0;
string s;

int get(LL x)
{
	int ret=0,y;
	while(x>0)
	{
		y=__builtin_popcount(x);
		x%=y;
		ret++;
	}
	return ret;
}

int main()
{
	cin>>n>>s;
	rep(i,n) num+=s[i]-'0';
	pwm1[0]=pw[0]=pwp1[0]=1;
	repn(i,200010)
	{
		if(num-1>0) pwm1[i]=pwm1[i-1]*2%(num-1);
		if(num>0) pw[i]=pw[i-1]*2%num;
		pwp1[i]=pwp1[i-1]*2%(num+1);
	}
	rep(i,n)
	{
		if(num-1>0) resm1=(resm1+(s[i]=='1')*pwm1[n-i-1])%(num-1);
		if(num>0) res=(res+(s[i]=='1')*pw[n-i-1])%num;
		resp1=(resp1+(s[i]=='1')*pwp1[n-i-1])%(num+1);
	}
	rep(i,n)
	{
		if(s[i]=='0')
		{
			LL tmp=(resp1+pwp1[n-i-1])%(num+1);
			printf("%d\n",get(tmp)+1);
		}
		else
		{
			if(num==1)
			{
				puts("0");
				continue;
			}
			LL tmp=(resm1-pwm1[n-i-1]+num-1+num-1)%(num-1);
			printf("%d\n",get(tmp)+1);
		}
	}
	return 0;
}