import Foundation

extension String {
    func toIntList() -> [Int] {
        return self.split(separator: " ").map{Int($0)!}
    }
    
    func toList() -> [String] {
        return self.map{String($0)}
    }
    
    func count(c:Character) -> Int{
        var result = 0

        for e in self{
            if e == c{
                result += 1
            }
        }
        return result
    }
}

extension Int {
    func toBin() -> String {
        return String(self, radix: 2)
    }
    
    func toD() -> Double {
        return Double(self)
    }
}

extension Double {
    func toI() -> Int {
        return Int(self)
    }
}

extension Array where Element: Equatable{
    func count(n:Self.Element) -> Int{
        var result = 0
        for e in self{
            if e == n{
                result += 1
            }
        }
        return result
    }
}



func D() {
    let N = Int(readLine()!)!
    let X = readLine()!.toList()
    let R:[String] = X.reversed()
    var dp = Array(repeating: 0, count: N+1)
    func popcount(n:Int) -> Int{
        var result = n
        var cnt = 0
        while result != 0 {
            let bin = result.toBin()
            let count = bin.toList().count(n: "1")
            result %= count
            cnt += 1
        }
        return cnt
    }
    
    var total = 0.0
    for i in 0..<N{
        total += Double(R[i])! * pow(2, i.toD())
    }
    
    var baseCnt = X.count(n: "1")
    
    for i in 0..<N{
        dp[i] = popcount(n: i)
    }
    for i in 0..<N{
        if X[i] == "1" {
            let a = total - pow(2.0, (N-1-i).toD())
            let b = baseCnt - 1
            if b == 0 {
                print(0)
                continue
            }
            let c = a.toI() % b
            print(dp[c] + 1)
            continue
        }
        
        let x = total + pow(2, (N-1-i).toD())
        let y = x.toI() % (baseCnt+1)
        print(dp[y] + 1)
    }
}


D()
