using System;
using System.IO;
using System.Text;
using CompLib.Algorithm;
using CompLib.Util;

public class Program
{
    private int N;
    private char[] X;

    private int[] Dp;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        X = sc.NextCharArray();

        // XのpopCount
        int all = 0;
        foreach (char c in X)
        {
            if (c == '1') all++;
        }

        int p1 = 0;
        int m1 = 0;
        for (int i = 0; i < N; i++)
        {
            p1 *= 2;
            p1 += X[i] - '0';
            p1 %= all + 1;

            if (all - 1 > 0)
            {
                m1 *= 2;
                m1 += X[i] - '0';
                m1 %= all - 1;
            }
        }

        // 2^iを+1 ,-1で割った余り

        int[] d1 = new int[N];
        int[] d2 = new int[N];
        d1[0] = 1 % (all + 1);
        if (all - 1 > 0) d2[0] = 1 % (all - 1);
        for (int i = 1; i < N; i++)
        {
            d1[i] = (d1[i - 1] * 2) % (all + 1);
            if (all - 1 > 0) d2[i] = (d2[i - 1] * 2) % (all - 1);
        }

        Dp = new int[400000];
        Dp[0] = 0;
        for (int i = 1; i < 400000; i++)
        {
            Dp[i] = Dp[i % (Algorithm.BitCount(i))] + 1;
        }


        var sb = new StringBuilder();

        for (int i = 0; i < N; i++)
        {
            int d = N - i - 1;
            if (X[i] == '0')
            {
                // 1になる
                int m = (p1 + d1[d]) % (all + 1);
                sb.AppendLine((Dp[m] + 1).ToString());
            }
            else
            {
                // 0
                if (all == 1)
                {
                    sb.AppendLine("0");
                }
                else
                {
                    int m = (m1 - d2[d]) % (all - 1);
                    if (m < 0) m += (all - 1);
                    sb.AppendLine((Dp[m] + 1).ToString());
                }
            }
        }

        Console.Write(sb);

        // all+1で割ったあまり、all-1で割った余り、全体を
    }


    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Algorithm
{
    static class Algorithm
    {
        /// <summary>
        /// nの立っているbitの数
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
        public static int BitCount(long n)
        {
            n = (n & 0x5555555555555555) + (n >> 1 & 0x5555555555555555);
            n = (n & 0x3333333333333333) + (n >> 2 & 0x3333333333333333);
            n = (n & 0x0f0f0f0f0f0f0f0f) + (n >> 4 & 0x0f0f0f0f0f0f0f0f);
            n = (n & 0x00ff00ff00ff00ff) + (n >> 8 & 0x00ff00ff00ff00ff);
            n = (n & 0x0000ffff0000ffff) + (n >> 16 & 0x0000ffff0000ffff);
            return (int) ((n & 0x00000000ffffffff) + (n >> 32 & 0x00000000ffffffff));
        }
    }
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 33008