#include <stdio.h>
const int N = 2e5+5;
int pow2[N][3];
int f[N][3];
char s[N];
int getans(int x) {
	int ans = 0;
	while (x) {
		int tmp = x;
		int cnt = 0;
		while (tmp) {
			if (tmp & 1)
				cnt++;
			tmp>>=1;
		}
		ans++;
		x = x%cnt;
	}
	return ans;
}
int main()
{
	int n;
	scanf("%d%s",&n,s);
	int mod[3] = {0,0,0};
	for (int i = 0;i < n;i++)
		if (s[i] == '1')
			mod[0]++;
	mod[1] = mod[0]+1;
	mod[2] = mod[0]-1;
	for (int j = 0;j < 3;j++) if (mod[j]!=0)
	{
		pow2[0][j] = 1%mod[j];
	}
	for (int i = 1;i<=n+1;i++)
		for (int j = 0;j< 3;j++) if (mod[j]!=0)
		{
			pow2[i][j] = pow2[i-1][j]*2%mod[j];
			if (i!=n+1)
			{
				f[i][j] = f[i-1][j]*2%mod[j];
				f[i][j] = (f[i][j] + (s[i-1]=='1'))%mod[j];
			}
		}
	for (int i = 0;i< n;i++)
	{
		int tmp = 0;
		int ans = 0;
		if (s[i]=='1') {
			if (mod[2]==0) {ans = 0;}
			else {
				tmp = ((f[n][2]-pow2[n-i-1][2])%mod[2]+mod[2])%mod[2];
				ans = 1 + getans(tmp);
			}
		}
		else {
			tmp = (f[n][1]+pow2[n-i-1][1])%mod[1];
			ans = 1 + getans(tmp);
		}
		printf("%d\n",ans);
	}
	return 0;
}

/*
10110111001011011001110
6002382
 */