N = gets.chomp.to_i
x = gets.chomp.split('')

max_n = ('1'*N).to_i(2)

# counts = Array.new(max_n+5, nil)

# 1.upto(max_n) do |n|
#   t = n
#   tmp = 0
#   while t != 0
#     if counts[t]
#       counts[n] = counts[t] + tmp
#       break
#     end
#     ni = t.to_s(2)
#     co = ni.count('1')
#     t = t%co
#     tmp += 1
#     if t == 0
#       counts[n] = tmp
#       break
#     end
#   end
# end

# p counts
N.times do |n|
  xx=x.dup
  xx[n] = xx[n]=='0' ? '1' : '0'
  se = xx.join('').to_i(2)

  t = se
  tmp = 0
  while t != 0
    # if counts[t]
    #   counts[se] = counts[t] + tmp
    #   break
    # end
    ni = t.to_s(2)
    co = ni.count('1')
    t = t%co
    tmp += 1
    if t == 0
      # counts[se] = tmp
      p tmp
      break
    end
  end

end
