using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

			//出力の都度更新をやめる
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);


			Ans();

			//更新する
			Console.Out.Flush();
	
		}
	
      public static void Ans() {

			var inputArray = retreiveLongArray();
			var inputCount = 1;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			long N = inputArray[0];
			var X = Console.ReadLine();

			//扱いやすいように1の桁から並べる
			var Xrev = X.Reverse().ToArray();

			var popCount = Xrev.Where(x => x == '1').Count();
			
			//popCount の+-1を格納
			var popS = new long[2];
			popS[0] = popCount + 1;
			popS[1] = popCount - 1 <=0 ? 1 : popCount - 1;

			//N...2のN乗  2...pop+-　それぞれの余り
			var TwoMods = new long[N, 2];
			TwoMods[0,0] = 1 % popS[0];
			TwoMods[0,1] = 1 % popS[1];

			for (int p = 0; p < 2; p++) {
				for (int i = 1; i < N; i++) {
					TwoMods[i, p] = (TwoMods[i - 1, p] * 2) % popS[p];
				}
			}

			//Xをpop+-1で割ったあまり
			var Fx = new long[2];

			
			for (int i = 0; i < N; i++) {
				var c = Xrev[i];
				for (int p = 0; p < 2; p++) {
					if (c == '1') {
						Fx[p] += TwoMods[i, p];
						Fx[p] %= popS[p];
					}

				}
			}

			//i番目をひっくり返す　降順になる
			for (var i = N-1; i >= 0; i--) {
				var c = Xrev[i];
				var first = 0L;
				if (c=='1') {

					//1つしかない1を反転させると、操作0回になる
					if (popCount==1) {
						Console.WriteLine(0);
						continue;
					}

					var p = 1;
					first = Fx[p] - TwoMods[i, p];
					if (first < 0) {
						first += popS[p];
					}
				}
				else {
					var p = 0;
					first = Fx[p] + TwoMods[i, p];
					first %= popS[p];
				}

				var ans = 1 + function(first);
				Console.WriteLine(ans);
			}

		}


		/// <summary>
		/// 問題文のfunctionを実装した関数
		/// </summary>
		/// <param name="n"></param>
		/// <returns></returns>
		private static long function(long n) {

			var count = 0;

			while (n >0) {
				//1が何個あるか求める
				var OneCount = 0L;
				for (int i = 0; i < 32; i++) {
					if ((n >> i & 1) == 1) {
						OneCount++;
					}
				}

				//nを割ってあまりを求める
				n %= OneCount;
				count++;
			}
			return count;


		}



		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}


		/// <summary>
		/// 2組みずつの入力データ(数値)からTuppleListを作成する
		/// </summary>
		/// <param name="N"></param>
		/// <returns></returns>
		private static List<Tuple<long, long>> createLongTuppleList(long N) {
			var inpList = new List<Tuple<long, long>>();

			for (int i = 0; i < N; i++) {
				var inp = retreiveLongArray();
				var item1 = inp[0];
				var item2 = inp[1];
				inpList.Add(new Tuple<long, long>(item1, item2));
			}
			return inpList;
		}
	}
}

 

Measured memory_bytes: 33228