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

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

    val baseBitCount = x.count { it == '1' }.toLong()
    val bitCountToModded = mutableMapOf<Long, Long>()

    for (bitCount in baseBitCount - 1..baseBitCount + 1) {
        if (bitCount == 0L) {
            bitCountToModded[bitCount] = 0
            continue
        }

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

    val answer = StringBuilder()

    for (i in 0 until n) {
        val currBitCount = baseBitCount + if (x[i] == '0') 1 else -1

        if (currBitCount == 0L) {
            answer.appendln(0)
            continue
        }

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

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

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

        answer.appendln(count)
    }

    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
}
