#include "bits/stdc++.h"
using namespace std;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	string s; cin >> s;
	int bits = 0;
	for (auto i : s)
		bits += i == '1';
	int mod0 = bits+1, mod1 = max(1, bits-1);
	int pw0 = 1, pw1 = 1;
	int rem0 = 0, rem1 = 0;
	for (int i = n-1; i >= 0; --i) {
		if (s[i] == '1') {
			rem0 += pw0; rem0 %= mod0;
			rem1 += pw1; rem1 %= mod1;
		}
		pw0 = (pw0*2)%mod0;
		pw1 = (pw1*2)%mod1;
	}
	pw0 = pw1 = 1;
	vector<int> out;
	for (int i = n-1; i >= 0; --i) {
		if (s[i] == '0') {
			int rem = rem0 + pw0; rem %= mod0;
			int ans = 1;
			while (rem) {
				int m = __builtin_popcount(rem); 
				rem %= m;
				++ans;
			}
			out.push_back(ans);
			// cout << ans << '\n';
		}
		else {
			if (bits == 1) out.push_back(0);
			else {
				int rem = rem1 + mod1 - pw1; rem %= mod1;
				int ans = 1;
				while (rem) {
					int m = __builtin_popcount(rem); 
					rem %= m;
					++ans;
				}
				out.push_back(ans);
			}
		}
		pw0 = (pw0*2)%mod0;
		pw1 = (pw1*2)%mod1;
	}
	reverse(begin(out), end(out));
	for (auto x : out)
		cout << x << '\n';
}