n = gets.to_i
x = gets.chomp.chars
@h = {0=>0, 1=>1, 2=>1, 3=>2}
def popcount(u)
  return @h[u] if @h[u]
  w = u.to_s(2).count('1')
  m = u % w
#  puts "w=#{w} m=#{m}"
  @h[u] = 1 + popcount(m)
end
n.times do |i|
  y = x.dup
  if y[i] == '0'
    y[i] = '1'
  else
    y[i] = '0'
  end
#  p y.join('').to_i(2)
  puts popcount(y.join('').to_i(2))
end