"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function () { return this.index < this.max },
        "next": function () { if (!this.hasNext()) { throw "ArrayIndexOutOfBoundsException"; } else { return this.list[this.index++]; } }
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)

const popCount = (n) => {
    let str = n.toString(2)
    let ans = 0
    for (let i = 0; i < str.length; i++) {
        if (str[i] == '1') ans++
    }
    return ans
}

const Main = () => {
    let n = nextInt()
    let x = next()
    let fn = {}
    let xs = []
    for (let i = 0; i < x.length; i++) {
        let arr = x.split("")
        if (arr[i] == '0') arr[i] = '1'
        else if (arr[i] == '1') arr[i] = '0'
        let xi = parseInt(arr.join(""), 2)
        xs.push(xi)
    }
    let org = [...xs]
    xs.sort((a,b) => a-b)
    for(let i = 0; i<xs.length;i++){
        let tmp = xs[i]
        let cnt = 0
        while (tmp !== 0) {
            let pc = popCount(tmp)
            tmp = tmp % pc
            cnt++
            if (fn[tmp]) {
                fn[xs[i]] = fn[tmp] + cnt
                break
            }
        }
        if(!fn[xs[i]]) fn[xs[i]] = cnt
    }
    for (let i = 0; i < org.length; i++) {
        let key = org[i]
        console.log(fn[key])
    }
}
Main()

