#include<bits/stdc++.h>
using namespace std;
const int N=2e5+7;
int n,n1,s1,s2,a[N],pw1[N],pw2[N];
char ch[N];
int solve(int x)
{
	if(!x)return 0;
	int num=0,tmp=x;
	while(x){if(x&1)num++;x/=2;}
	return 1+solve(tmp%num);
}
int main()
{
	scanf("%d",&n);
	scanf("%s",ch+1);
	for(int i=1;i<=n;i++){a[i]=ch[i]-'0';if(a[i])n1++;}
	if(n1>=2)
	{
		pw1[n]=1;
		for(int i=n-1;i;i--)pw1[i]=2ll*pw1[i+1]%(n1-1);
		for(int i=1;i<=n;i++)if(a[i])s1=(s1+pw1[i])%(n1-1);
	}
	pw2[n]=1;
	for(int i=n-1;i;i--)pw2[i]=2ll*pw2[i+1]%(n1+1);
	for(int i=1;i<=n;i++)if(a[i])s2=(s2+pw2[i])%(n1+1);
	for(int i=1,x;i<=n;i++)
	if(a[i])
	{
		if(n1<=1)puts("0");
		else x=(s1-pw1[i]+n1-1)%(n1-1),printf("%d\n",solve(x)+1);
	}
	else x=(s2+pw2[i])%(n1+1),printf("%d\n",solve(x)+1);
}
