func main() {
let n = Int(readLine()!)!
let xst = readLine()!
let x: Int = {
    var c = 0
    for s in xst {
        c = c*2 + (s=="1" ? 1 : 0)
    }
    return c
}()

for i in 0..<n {
    let s = xst[xst.index(xst.startIndex, offsetBy: i)]
    let m = s == "0" ? 1 : -1
    let xy = x + tpow(n-1-i) * m
    print(f(xy))
}

}
main()
func tpow(_ m: Int) -> Int{
    var a = 1
    if m >= 1 {
        for _ in 1...m {
            a = a << 1
        }
    }
    return a
}

func pc(_ n: Int) -> Int {
    let b = String(n, radix: 2)
    var c = 0
    for d in b {
        if d == "1" {
            c += 1
        }
    }
    return c
}

func f(_ n: Int) -> Int {
    var c = 0
    var n = n
    while n != 0 {
        n = n % pc(n)
        c += 1
    }
    return c
}
