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

memo = {}

arr = []
0.upto(100) do |i|
  break if 2**i > 2*10**5
  arr.push(2**i)
end

def cou(n,arr)
  value = 0
  arr.reverse_each do |a|
    if n >= a
      n %= a
      value += 1
    end
  end
  value
end

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 memo[t]
      memo[se] = memo[t] + tmp
      break
    end
    co = cou(t,arr)
    t = t%co
    tmp += 1
    if t == 0
      memo[se] = tmp
      break
    end
  end
  p memo[se]
end
