#include <cstdio>
#include <algorithm>
using namespace std;
long long mp(long long b, long long e, long long m) {
	if (e == 0) return 1;
	long long a = mp(b, e / 2, m);
	a = a * a % m;
	if (e & 1) a = a * b % m;
	return a;
}
int get_ans(int X) {
	if (X == 0) return 0;
	return get_ans(X % __builtin_popcount(X)) + 1;
}
int main() {
	int N, pc = 0;
	scanf("%d", &N);
	char X[N];
	for (int i = 0; i < N; ++i) scanf(" %c", &X[i]);
	for (int i = 0; i < N; ++i) {
		if (X[i] == '1') ++pc;
	}
	int tz = 0, to = 0;
	for (int i = 0; i < N; ++i) {
		if (pc > 1) tz = ((tz << 1) + (X[i] == '1')) % (pc - 1);
		to = ((to << 1) + (X[i] == '1')) % (pc + 1);
	}
	for (int i = 0; i < N; ++i) {
		if (X[i] == '0') printf("%d\n", get_ans((to + mp(2, N - 1 - i, pc + 1)) % (pc + 1)) + 1);
		else if (pc == 1) printf("0\n");
		else printf("%d\n", get_ans((tz - mp(2, N - 1 - i, pc - 1) + pc - 1) % (pc - 1)) + 1);
	}
	return 0;
}