object Main {
  def main(args: Array[String]): Unit = {
    val n_length = scala.io.StdIn.readInt
    val n        = scala.io.StdIn.readLine

    ( 0 until n_length ).foreach{ i =>
      val change_value = if( n( i ) == '0' ) '1' else '0'

      var check_n = n.updated( i, change_value )
      var count = 0

      while( check_n != "0" ) {
        count += 1
        check_n = calcBinaryDiv( check_n, popCount( check_n ).toBinaryString )

      }

      println( count )
    }
  }

  def calcBinaryDiv( n: String, divided_n: String ): String = {
    val check = n.split( "" )
    var x = ""
    var answer = ""

    check.foreach{ i =>
      x += i
      val calc_x = java.lang.Integer.parseInt( x, 2 ) - java.lang.Integer.parseInt( divided_n, 2 )
      if( calc_x >= 0 ) {
        x = calc_x.toBinaryString
        answer += "1"
      }
      else if( answer != "" ) {
        answer += "0"
      }
    }
    
    return java.lang.Integer.parseInt( x, 2 ).toBinaryString
  }

  def popCount( n: String ): Int = {
    val check = n.split( "" ).map{ _.toInt }
    var count = 0
    check.foreach{ i =>
      if( i == 1 ) count += 1
    }
    return count
  }
}