fun main() = Thread(null, ::aising2020d, "(^o^)", 128 * 1024 * 1024).apply { start() }.join()

@OptIn(ExperimentalStdlibApi::class)
fun aising2020d() {
    val n = readLine()!!.toInt()
    val x = readLine()!!

    var bitCount = 0
    for (c in x) if (c == '1') bitCount++

    val bitCountToModded = mutableMapOf<Int, Long>()

    for (i in bitCount - 1..bitCount + 1) {
        var modByN = 0L
        for ((index, c) in x.reversed().withIndex()) {
            if (c == '1') {
                modByN += (2L).modPow(index.toLong(), i.toLong())
                modByN %= i
            }
        }
        bitCountToModded[i] = modByN
    }

    val answer = StringBuilder()

    for (i in 0 until n) {
        if (x[i] == '0') bitCount++ else bitCount--

        val modPow = (2L).modPow(n - i - 1L, bitCount.toLong())
        var x1 = bitCountToModded[bitCount]!! + if (x[i] == '0') modPow else -modPow
        x1 += bitCount
        x1 %= bitCount

        var currX = x1.toInt()
        var count = 1

        while (currX > 0) {
            currX %= Integer.bitCount(currX)
            count++
        }

        answer.appendln(count)
        if (x[i] == '0') bitCount-- else bitCount++
    }

    print(answer)
}

private fun Long.modPow(p: Long, m: Long): Long {
    var x = this % m
    var y = p
    var result = 1L
    while (y > 0) {
        if (y % 2 == 1L) result = (result * x) % m
        y = y shr 1
        x = (x * x) % m
    }
    return result
}
