package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	sc := NewScanner()

	n := sc.ReadInt()
	x := sc.ReadString()

	popcountX := 0
	for _, c := range x {
		if c == '1' {
			popcountX++
		}
	}
	popcountXPlus1 := popcountX + 1
	popcountXMinus1 := popcountX - 1

	pow2ModPopcountXPlus1 := make([]int, n)
	pow2ModPopcountXPlus1[0] = 1
	for i := 1; i < n; i++ {
		pow2ModPopcountXPlus1[i] = pow2ModPopcountXPlus1[i-1] * 2 % popcountXPlus1
	}
	pow2ModPopcountXMinus1 := make([]int, n)
	pow2ModPopcountXMinus1[0] = 1
	if popcountXMinus1 > 0 {
		for i := 1; i < n; i++ {
			pow2ModPopcountXMinus1[i] = pow2ModPopcountXMinus1[i-1] * 2 % popcountXMinus1
		}
	}

	xModPopcountXPlus1 := 0
	for digit := 0; digit < n; digit++ {
		pos := n - 1 - digit
		if x[pos] == '1' {
			xModPopcountXPlus1 += pow2ModPopcountXPlus1[digit]
			xModPopcountXPlus1 %= popcountXPlus1
		}
	}
	xModPopcountXMinus1 := 0
	if popcountXMinus1 > 0 {
		for digit := 0; digit < n; digit++ {
			pos := n - 1 - digit
			if x[pos] == '1' {
				xModPopcountXMinus1 += pow2ModPopcountXMinus1[digit]
				xModPopcountXMinus1 %= popcountXMinus1
			}
		}
	}

	f := make([]int, 200_000)
	var getF func(n int) int
	getF = func(n int) int {
		if n == 0 {
			return 0
		}
		if f[n] > 0 {
			return f[n]
		}
		ans := 1 + getF(n%popcount(n))
		f[n] = ans
		return ans
	}

	for pos := 0; pos < n; pos++ {
		digit := n - 1 - pos

		modXi := 0
		if x[pos] == '0' {
			modXi = xModPopcountXPlus1 + pow2ModPopcountXPlus1[digit]
			modXi %= popcountXPlus1
			ans := 1 + getF(modXi)
			fmt.Println(ans)
		} else if popcountXMinus1 > 0 {
			modXi = xModPopcountXMinus1 + (popcountXMinus1 - pow2ModPopcountXMinus1[digit])
			modXi %= popcountXMinus1
			ans := 1 + getF(modXi)
			fmt.Println(ans)
		} else {
			fmt.Println(0)
		}
	}
}

func popcount(n int) int {
	cnt := 0
	for ; n > 0; n >>= 1 {
		if n&1 == 1 {
			cnt++
		}
	}
	return cnt
}

// from [my library](https://github.com/ikngtty/go-contestlib)
// -   math/simple

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}

	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}

	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base, exponent int) int {
	if exponent < 0 {
		panic(fmt.Sprintf("exponent (%d) should not be a minus", exponent))
	}

	answer := 1
	for i := 0; i < exponent; i++ {
		answer *= base
	}
	return answer
}

func Ceil(divident, dividor int) int {
	if dividor == 0 {
		panic("dividor should not be 0")
	}

	quo := divident / dividor
	rem := divident % dividor

	if rem != 0 {
		if (divident > 0 && dividor > 0) ||
			(divident < 0 && dividor < 0) {
			return quo + 1
		}
	}
	return quo
}

// -   sortutil

func ReverseInts(a []int) {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
}

func ReverseStrings(a []string) {
	sort.Sort(sort.Reverse(sort.StringSlice(a)))
}

// -   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}


Measured memory_bytes: 7752