#include <iostream>
#include <vector>
using namespace std;

int calc(int k) {
	if (k == 0) return 0;
	int p = 0, kk=k;
	while (kk > 0) {
		p += kk & 1;
		kk /= 2;
	}
	return 1 + calc(k % p);
}

int main() {
	int N;
	string s;
	cin >> N >> s;
	int p = 0;
	for (char c : s) p += (c == '1');
	vector<int> ModsP(N), ModsM(N);
	ModsP[0] = 1 % (p + 1);
	ModsM[0] = (p - 1 <= 0 ? 0 : 1 % (p - 1));
	for (int i = 1; i < N; i++) {
		ModsP[i] = ModsP[i - 1] * 2 % (p + 1);
		ModsM[i] = (p - 1 <= 0 ? 0 : ModsM[i - 1] * 2 % (p - 1));
	}

	int OriginalModP = 0, OriginalModM=0;
	for (int i = 0; i < N; i++) {
		if (s[N - 1 - i] == '1') {
			OriginalModP += ModsP[i];
			OriginalModP %= p + 1;
			OriginalModM += ModsM[i];
			if (p - 1 > 0) OriginalModM %= p - 1;
		}
	}

	for (int i = 0; i < N; i++) {
		int ChangedMod=0;
		if (s[i] == '1') {
			ChangedMod = OriginalModM - ModsM[N - 1 - i];
			if (p - 1 > 0) {
				ChangedMod += p - 1;
				ChangedMod %= p - 1;
			}
		}
		else {
			ChangedMod = OriginalModP + ModsP[N - 1 - i];
			ChangedMod %= p + 1;
		}

		cout << (p==1 && s[i]=='1' ? 0 : 1 + calc(ChangedMod)) << endl;
	}

}