import Foundation

let N = Int(readLine()!)!
let n = N
let s = readLine()!
let x = Array(s).map { String($0) }.compactMap { Int($0) }
let pc = x.reduce(0, +)

var ans: [Int] = .init(repeating: 0, count: N)

func popcount(_ x: Int) -> Int {
  var x = x
  var count = 0
  while x > 0 {
    x = x & (x - 1)
    count += 1
  }
  return count
}

func f(_ x: Int) -> Int {
  if x == 0 {
    return 0
  }
  return f(x % popcount(x)) + 1
}

for b in 0..<2 {
  let npc = b == 0 ? pc + 1 : pc - 1
  if npc <= 0 {
    continue
  }
  var r0 = 0
  for i in 0..<x.count {
    r0 = (r0 * 2) % npc
    r0 += x[i]
  }
  var k = 1
  for i in (0..<x.count).reversed() {
    if x[i] == b {
      var r = r0
      r = b == 0 ? (r + k) % npc : (r - k + npc) % npc
      ans[i] = f(r) + 1
    }
    k = (k * 2) % npc
  }
}
ans.forEach { print($0) }
